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
です。