I'm trying to avoid concepts on the master branch of my projects, so I need some kind of alternative with type_trait
:
I need a class whom some few functions will change depending on the bool
value.
Someone already suggest me to split my class, but this case won't make sense here. For some context it's a pool where remove function and some others will change if the object type of the pool can be shared or not.
So I tried to use std::enable_if
, but there are still some errors (I want the declaration and the implementation to be separate).
#include <type_traits>
template < typename Object, bool Shared = false >
class Foo {
template < bool S = Shared, typename std::enable_if<S>::type* = nullptr >
void bar();
template < bool S = Shared, typename std::enable_if<!S>::type* = nullptr >
void bar();
};
template < typename Object,
bool Shared >
template < bool S, typename std::enable_if<S>::type* = nullptr >
void Foo<Object, Shared>::bar() {
//do something
}
template < typename Object,
bool Shared >
template < bool S, typename std::enable_if<!S>::type* = nullptr >
void Foo<Object, Shared>::bar() {
//do nothing
}
int main() {
Foo<int> test;
return 0;
}
Test3.cpp:16:33: error: default argument for template parameter for class enclosing ‘void Foo<Object, Shared>::bar()’
void Foo<Object, Shared>::bar() {
^
Test3.cpp:24:33: error: default argument for template parameter for class enclosing ‘void Foo<Object, Shared>::bar()’
void Foo<Object, Shared>::bar() {
EDIT: Removed copy/paste error