C++相談室 part58 at TECH
[2ch|▼Menu]
104:デフォルトの名無しさん
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

5360日前に更新/51 KB
担当:undef