【C++】template 統合スレ -- Part6 at TECH
[2ch|▼Menu]
485:デフォルトの名無しさん
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);
};


次ページ
続きを表示
1を表示
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
暇つぶし2ch

5371日前に更新/262 KB
担当:undef