C++相談室 part58at TECH
C++相談室 part58 - 暇つぶし2ch104:デフォルトの名無しさん
07/09/30 23:06:47
>>100
> あ、::type付けわすれた…
検索エンジン経由で来るひとのために、一応訂正版貼っときますね。

#include <cstdio>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>

struct X {
  template<typename T, typename U = void> struct Y {
    Y() { std::printf("genecic\n"); }
  };
  template<typename T> struct Y <T, typename boost::enable_if<boost::is_same<T, int> >::type> {
    Y() { std::printf("specialized for int\n"); }
  };
};
class Z {};

int main() {
  X::Y<Z> a;
  X::Y<int> b;
  X::Y<float> c;
}

実行結果は、
genecic
specialized for int
genecic
です。



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