template<typename T> struct foo<typename bar<T>::Type> {
static void func() { ... }
};
T , T, bar<T>::Type.
, ,
foo<double> foodouble;
, , , bar, double, foo? , , bar, double , - :
template<> struct bar<int> { typedef double Type; };
bar<double>::Type bar<int>::Type double. , : bar, double , bar.
SFINAE :
#include <iostream>
template<typename T> struct bar { typedef void type; };
template<> struct bar<float> { typedef bar<float> type; };
template<> struct bar<double> { typedef bar<double> type; };
template<typename T>
struct foo : bar<T>::type
{
static void func()
{
std::cout << "primary template for float and double" << std::endl;
}
};
template<>
struct foo<bool>
{
static void func()
{
std::cout << "specialization for for bool" << std::endl;
}
};
int main()
{
foo<float>::func();
foo<double>::func();
foo<bool>::func();
}
(-):
primary template for float and double
primary template for float and double
specialization for for bool
, struct foo : bar<T>::type . . , , , , float, double bool; , foo<int>. , undefined, , .