V
vlad.k.sm
Specialization of member of template class is impossible according to C
++ standard. The following code:
template<typename T> struct enbl_if {};
template<> struct enbl_if<int> { typedef int type; };
template<typename T> struct disble_if {typedef T type; };
template<> struct disble_if<int> {};
template<typename T>
struct test
{
template<typename T2>
typename enbl_if<T2>::type get() const
{
std::cout << "enbl_if" << std::endl;
return T2();
}
template<typename T2>
typename disble_if<T2>::type get() const
{
std::cout << "disble_if" << std::endl;
return T2();
}
};
int main()
{
int i = test<int>().get<int>();
long l = test<int>().get<long>();
std::string s = test<int>().get<std::string>();
return 0;
}
prints:
enbl_if
disble_if
disble_if
and so, it works as full specialization for "int". I was able to
compile it under gcc 4.2, VC2003-2005, comeua online. Is it correct
code?
p.s.: instead enbl_if, disble_if need to use appropriate boost utility
in complete code.
++ standard. The following code:
template<typename T> struct enbl_if {};
template<> struct enbl_if<int> { typedef int type; };
template<typename T> struct disble_if {typedef T type; };
template<> struct disble_if<int> {};
template<typename T>
struct test
{
template<typename T2>
typename enbl_if<T2>::type get() const
{
std::cout << "enbl_if" << std::endl;
return T2();
}
template<typename T2>
typename disble_if<T2>::type get() const
{
std::cout << "disble_if" << std::endl;
return T2();
}
};
int main()
{
int i = test<int>().get<int>();
long l = test<int>().get<long>();
std::string s = test<int>().get<std::string>();
return 0;
}
prints:
enbl_if
disble_if
disble_if
and so, it works as full specialization for "int". I was able to
compile it under gcc 4.2, VC2003-2005, comeua online. Is it correct
code?
p.s.: instead enbl_if, disble_if need to use appropriate boost utility
in complete code.