if I have the following function
struct Struct { template<T> void Foo(); }
How can I use enable_if in the function definition without repeating the declaration above?
template<T> typename enable_if<is_class<T>,void>::type Struct::Foo() { ... } // error: Struct has no member `Foo<T>`
template<T> typename enable_if<!is_class<T>,void>::type Struct::Foo() { ... } // error: Struct has no member `Foo<T>`
enable_if<is_class<T>,void> is just an example but is there a way to not repeat the declaration with multiple enable_if definitions?
it seems I'm forced to do this
struct Struct
{
template<T> typename enable_if<is_class<T>,void>::type Foo();
template<T> typename enable_if<!is_class<T>,void>::type Foo();
}
The easiest way to not have to repeat yourself too much is to define them inline:
or with constexpr-if:
which makes separating the declaration and definition slightly less verbose: