I can't understand why the following code is not working. compiler (gcc) seems to instanciate both methods and obviously integer is either signed or unsigned, so one always fails. I though enable_if was here to avoid that.
Q: why the compile error, and how to avoid it ?
using namespace boost; // or std as you want
template<typename T>
struct test {
// if signed
template< typename enable_if
< is_signed<T>
, int
>:: type = 0
>
test &operator<<=(int value)
{}
// if unsigned
template< typename enable_if
< is_unsigned<T>
, int
>:: type = 0
>
test &operator<<=(int value)
{}
};
void foo()
{
test<int> x;
x << 1; // COMPILE ERROR no type named 'type' in struct enable_if<unsigned> etc.
test<unsigned> y;
y << 1; // COMPILE ERROR no type named 'type' in struct enable_if<int> etc.
}