There was a question somewhat related to my problem earlier, which dealt with template class, that used std::enable_if
on a method, which is declared in class prototype, but the actual implementation is done outside.
Source: function implementation with enable_if outside of class definition
I want to do something similar, but with the class constructor, which I want to define outside template class with std::enable_if
metafunction.
template <typename T>
using EnableIfArithmetic = typename std::enable_if<std::is_arithmetic<T>::value, void>::type;
template <typename NumericType>
class SomeClass {
public:
// constructor definition
template <typename = EnableIfArithmetic<NumericType>>
SomeClass() {
// do some stuff
}
};
Desired form:
template <typename NumericType>
class SomeClass {
public:
// constructor declaration
template <typename = EnableIfArithmetic<NumericType>>
SomeClass();
};
// constructor definition
template <typename NumericType>
template <typename = EnableIfArithmetic<NumericType>>
SomeClass<NumericType>::SomeClass() {
// constructor implementation
}
But I cannot get it right, without compiling error. What am I doing wrong?