Vector 〜その2〜

ずいぶん長い明日になってしまった…。
1回書かないと間が空いてしまうのは悪い癖。

って事で前回の続き。

    
#include #include #include #include // ############################################################################# // 前回作ったベクトルクラス template< unsigned int D, typename T > struct Vector; /** ############################################################################ 各ベクトルの特性 */ /** -------------------------------------------------------- ベクトル? */ template< typename VecType > struct is_vector{ static const bool result = false; }; template< unsigned int D, typename T > struct is_vector >{ static const bool result = true; }; /** DirectX 系の特性 */ #ifdef D3DVECTOR_DEFINED template<> struct is_vector{ static const bool result = true; }; #endif // #ifdef D3DVECTOR_DEFINED /** -------------------------------------------------------- 保持している値の型は? */ template< typename T > struct vec_value_type{ typedef float type; }; template< unsigned int D, typename T > struct vec_value_type >{ typedef T type; }; /** DirectX 系の特性 */ #ifdef D3DVECTOR_DEFINED template<> struct vec_value_type{ typedef float type; }; #endif // #ifdef D3DVECTOR_DEFINED /** -------------------------------------------------------- 次元の取得 */ template< typename T > struct dimension{ static const unsigned int value = sizeof(T) / sizeof(vec_value_type::type); }; int main(){ std::cout << ( is_vector::result ? "ベクトルです" : "ベクトルじゃありません" )<< "\n"; std::cout << ( is_vector::result ? "ベクトルです" : "ベクトルじゃありません" )<< "\n"; std::cout << dimension::value << "次元" << "\n"; return 0; } /** ############################################################################ 実行結果: ベクトルです ベクトルじゃありません 4次元

しかし、毎回ソースを載せると長い…。

もうちょっと小刻みでいったほうが読みやすいかしら?
もうソースを短くするようにしてみるか。