定数の has_xxx

template<int N>
struct sfinae_helper{
    typedef void type;
};

template<typename T, typename U = void>
struct has_dimension_impl{
    static const bool value = false;
};

template<typename T>
struct has_dimension_impl<T, typename sfinae_helper<T::dimension>::type>{
    static const bool value = true;
};

template<typename T>
struct has_dimension : public has_dimension_impl<T>{};

struct vec{
    static const int dimension = 3;
};


BOOST_STATIC_ASSERT(( has_dimension<int>::value == false ));
BOOST_STATIC_ASSERT(( has_dimension<vec>::value == true ));        // error


こんな感じで、定数 dimension を定義しているかどうかをチェックするメタ関数を書いたんですが、msvc-8.0 の場合だと、これではうまく動きませんでした。
色々と調べてみたら has_dimension_impl を継承している辺りがまずいみたい。

BOOST_STATIC_ASSERT(( has_dimension_impl<vec>::value == true ));    // これは問題なく動く


とりあえず、boost::mpl::bool_ をかませることでうまく動きました。

template<typename T>
struct has_dimension : public boost::mpl::bool_<has_dimension_impl<T>::value>{};

BOOST_STATIC_ASSERT(( has_dimension<vec>::value == true ));        // ok


うーむ、無駄に時間を食ってしまった。
C++ にはふしぎがいっぱいです。

[参照]
http://cpplover.blogspot.com/2008/10/hasxxx.html