I am trying to get a simple example to work to understand how to use std::enable_if
. After I read this answer, I thought it shouldn\'t be too hard to come up wi
One way to solve this problem, specialization of member functions is to put the specialization into another class, then inherit from that class. You may have to change the order of inheritence to get access to all of the other underlying data but this technique does work.
template< class T, bool condition> struct FooImpl;
template struct FooImpl {
T foo() { return 10; }
};
template struct FoolImpl {
T foo() { return 5; }
};
template< class T >
class Y : public FooImpl > // whatever your test is goes here.
{
public:
typedef FooImpl > inherited;
// you will need to use "inherited::" if you want to name any of the
// members of those inherited classes.
};
The disadvantage of this technique is that if you need to test a lot of different things for different member functions you'll have to make a class for each one, and chain it in the inheritence tree. This is true for accessing common data members.
Ex:
template class Goo;
// repeat pattern above.
template
class Foo : public Goo > {
public:
typedef Goo > inherited:
// etc. etc.
};