minifying boilerplate code on C++ template code

Viewed 1341

suppose I have code like this:

template <class T>
class Something{
public:
    int func1();
    int func2();

    T   t;
    int n = 0;
};

template <class T>
int Something<T>::func1(){
   return t.value() * n;
}

template <class T>
int Something<T>::func2(){
   return n;
}

In this case Something::func2() does not really depends of template parameter T, so it can be compiled into the object file, instead of recompiled every time (this is compiler dependent and can or can not be true).

Second, you still need to type template <class T> int Something<T>::func2().

is there a way to simplify the boilerplate code?

2 Answers
Related