C++11の機能を使ったmake_arrayはこちらを参照して下さいmake_array 書いてみた - とくにあぶなくないRiSKのブログ
Visual C++ Nov 2012 CTPで可変長テンプレート引数対応とのことですが、不完全なうえ標準ライブラリが可変長テンプレート引数未対応なのでまだまだVC++での使用が難しいです。なのでBoost.Preprocessorを使って擬似可変長テンプレート引数なmake_arrayを書いてみました。
#include <array> #include <type_traits> #include <boost/preprocessor/repeat_from_to.hpp> #include <boost/preprocessor/enum_params.hpp> #include <boost/preprocessor/arithmetic/add.hpp> #include <boost/preprocessor/repetition/enum_binary_params.hpp> #define MAKE_ARRAY(z, n, d)\ template <BOOST_PP_ENUM_PARAMS(n, class T)>\ std::array<typename std::common_type<BOOST_PP_ENUM_PARAMS(n, T)>::type, n> make_array(BOOST_PP_ENUM_BINARY_PARAMS(n, T, arg))\ {\ std::array<typename std::common_type<BOOST_PP_ENUM_PARAMS(n, T)>::type, n> ar = {BOOST_PP_ENUM_PARAMS(n, arg)};\ return ar;\ } BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_ADD(_VARIADIC_MAX, 5), MAKE_ARRAY, _) #undef MAKE_ARRAY int main() { auto ar = make_array(1, 2, 3.0, 4.0); }
特に説明することはないと思います。