G
greek_bill
With regards to using Boost enable_if and similar SFINAE constructs,
is it right that you can only put an enable_if on the return type or
as an additional parameter? Why is that?
The following doesn't compile (VC8 and gcc 3.4.4) :
namespace Test
{
template<typename T, typename U>
struct IsSameType
{
enum { value = false };
};
template<typename T>
struct IsSameType<T,T>
{
enum { value = true };
};
//------------------------------------------------------------------
struct Foo
{
// Doesn't compile
template<class T>
void Func(typename enable_if_c<!IsSameType<T, int>::value, T>::type
t)
{}
// But this does...
template<class T>
typename enable_if_c<!IsSameType<T, int>::value, void>::type Func(T
t)
{}
void Func(int i)
{}
};
void FooFunc()
{
Foo f;
// Should go to non-template version
f.Func(5);
// Should go to template version
char* p;
f.Func(p);
}
}
Thanks,
Vassilis
is it right that you can only put an enable_if on the return type or
as an additional parameter? Why is that?
The following doesn't compile (VC8 and gcc 3.4.4) :
namespace Test
{
template<typename T, typename U>
struct IsSameType
{
enum { value = false };
};
template<typename T>
struct IsSameType<T,T>
{
enum { value = true };
};
//------------------------------------------------------------------
struct Foo
{
// Doesn't compile
template<class T>
void Func(typename enable_if_c<!IsSameType<T, int>::value, T>::type
t)
{}
// But this does...
template<class T>
typename enable_if_c<!IsSameType<T, int>::value, void>::type Func(T
t)
{}
void Func(int i)
{}
};
void FooFunc()
{
Foo f;
// Should go to non-template version
f.Func(5);
// Should go to template version
char* p;
f.Func(p);
}
}
Thanks,
Vassilis