??C++????????????????????????????
???????????? ???????[ 2013/4/24 10:02:45 ] ????????
????????7??
namespace
{
template <bool??typename T??typename> struct conditional { typedef T type; };
template <typename T??typename U> struct conditional<false??T??U> {typedef U type; };
}
template<class T?? unsigned B>
struct Base
{
//other function
//....
void Func ()
{
typedef typename ::conditional<B!=16??primary_t??spec_t>::type type;
Func_impl(type());
}
private:
struct primary_t { };
struct spec_t { };
void Func_impl (primary_t) { std::cout << "primary function" << std::endl; }
void Func_impl (spec_t ) { std::cout << "specialization function" << std::endl; }
};
???????????????6???????????????????
????????8??
????namespace
{
template <bool??typename T = void> struct enable_if { typedef T type; };
template <typename T> struct enable_if<true??T> {};
}
template<class T?? unsigned B>
struct Base
{
//other function
//....
template <unsigned N>
typename ::enable_if<16!=N>::type
FuncImpl () { std::cout << "primary function" << std::endl; }
template <unsigned N>
typename ::enable_if<16==N>::type
FuncImpl () { std::cout << "specialization function" << std::endl; }
void Func() {
FuncImpl<B>();
}
};
?????????????enable_if??????SFINAE????
????????????????????????????int?????????????д??????????????????????????????????????????????????????????????2????????????????????????
??????

???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11