05/05/10 01:05:27
>>480
まあ実用性のことは置いておいて、メタプログラミングのいい勉強になるかな、
と思ってちょっと書いてみた。
ここは BOOST スレじゃないので、敢えて boost::mpl とかは使わず。
template <class T0, class T1>
struct is_same_type {
static const bool value = false;
};
template <class T>
struct is_same_type<T, T> {
static const bool value = true;
};
struct sfinae_type {
typedef char one;
typedef struct { char arr[2]; } two;
};
template <class T>
struct has_key_type : sfinae_type {
template <class U> static one test(typename U::key_type*);
template <class U> static two test(...);
static const bool value = (sizeof(test<T>(0)) == 1);
};
template <class T>
struct has_value_first_type : sfinae_type {
template <class U> static one test(typename U::value_type::first_type*);
template <class U> static two test(...);
static const bool value = (sizeof(test<T>(0)) == 1);
};