定数の定義

boost::fusion を使っててふと思ったんですが。

typedef std::size_t dimension_type;

struct my_vec{
    static const dimension_type dimension = 3;
    float x, y, z;
};

BOOST_STATIC_ASSERT( my_vec::dimension == 3 );

こうやって定義するよりも……。

template<std::size_t N>
struct dimension : public boost::integral_constant<std::size_t, N>{};

struct my_vec{
    typedef dimension<3> dimension_type;
    float x, y, z;
};

BOOST_STATIC_ASSERT( my_vec::dimension_type::value == 3 );

こっちの方がいいでゲソか?


[追記]
dimension の実装を boost::integral_constant 使用に変更。


割とどうでもいいでゲソ。