From 4e0b3991b18954c5e2765e520613227615ec87c2 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Thu, 10 Mar 2016 01:07:55 +0900 Subject: [PATCH] fix static date member in specialized class template --- sprout/checksum/md5.hpp | 48 +++++++++++++++------------ sprout/math/quaternion/quaternion.hpp | 45 ++++++++++++++++--------- sprout/uuid/detail/table.hpp | 11 +++--- 3 files changed, 62 insertions(+), 42 deletions(-) diff --git a/sprout/checksum/md5.hpp b/sprout/checksum/md5.hpp index 381dc2f5..4c58364b 100644 --- a/sprout/checksum/md5.hpp +++ b/sprout/checksum/md5.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -95,12 +96,12 @@ namespace sprout { return sprout::md5_detail::round_x_impl(k[0], k[1], k[2], k[3], x, round_op, xis, ts, ss); } - template + template struct round_table; # define SPROUT_MD5_DETAIL_ROUND_TABLE_DEF(N, XIS, TS, SS) \ - template<> \ - struct round_table { \ + template \ + struct round_table { \ public: \ typedef sprout::array xis_type; \ typedef sprout::array ts_type; \ @@ -116,50 +117,53 @@ namespace sprout { SPROUT_STATIC_CONSTEXPR_DATA_MEMBER_INNER(SS) \ ; \ }; \ - SPROUT_CONSTEXPR_OR_CONST sprout::md5_detail::round_table::xis_type sprout::md5_detail::round_table::xis \ + template \ + SPROUT_CONSTEXPR_OR_CONST typename sprout::md5_detail::round_table::xis_type sprout::md5_detail::round_table::xis \ SPROUT_STATIC_CONSTEXPR_DATA_MEMBER_OUTER(XIS) \ ; \ - SPROUT_CONSTEXPR_OR_CONST sprout::md5_detail::round_table::ts_type sprout::md5_detail::round_table::ts \ + template \ + SPROUT_CONSTEXPR_OR_CONST typename sprout::md5_detail::round_table::ts_type sprout::md5_detail::round_table::ts \ SPROUT_STATIC_CONSTEXPR_DATA_MEMBER_OUTER(TS) \ ; \ - SPROUT_CONSTEXPR_OR_CONST sprout::md5_detail::round_table::ss_type sprout::md5_detail::round_table::ss \ + template \ + SPROUT_CONSTEXPR_OR_CONST typename sprout::md5_detail::round_table::ss_type sprout::md5_detail::round_table::ss \ SPROUT_STATIC_CONSTEXPR_DATA_MEMBER_OUTER(SS) SPROUT_MD5_DETAIL_ROUND_TABLE_DEF( \ 1, \ - (xis_type{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}}), \ - (ts_type{{ \ + sprout::make_array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), \ + sprout::make_array( \ 0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501, \ 0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821 \ - }}), \ - (ss_type{{7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22}}) \ + ), \ + sprout::make_array(7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22) \ ); SPROUT_MD5_DETAIL_ROUND_TABLE_DEF( \ 2, \ - (xis_type{{1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12}}), \ - (ts_type{{ \ + sprout::make_array(1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12), \ + sprout::make_array( \ 0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, 0xD62F105D, 0x02441453, 0xD8A1E681, 0xE7D3FBC8, \ 0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A \ - }}), \ - (ss_type{{5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20}}) \ + ), \ + sprout::make_array(5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20) \ ); SPROUT_MD5_DETAIL_ROUND_TABLE_DEF( \ 3, \ - (xis_type{{5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2}}), \ - (ts_type{{ \ + sprout::make_array(5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2), \ + sprout::make_array( \ 0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70, \ 0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x04881D05, 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665 \ - }}), \ - (ss_type{{4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23}}) \ + ), \ + sprout::make_array(4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23) \ ); SPROUT_MD5_DETAIL_ROUND_TABLE_DEF( \ 4, \ - (xis_type{{0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9}}), \ - (ts_type{{ \ + sprout::make_array(0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9), \ + sprout::make_array( \ 0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1, \ 0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391 \ - }}), \ - (ss_type{{6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21}}) \ + ), \ + sprout::make_array(6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21) \ ); # undef SPROUT_MD5_DETAIL_ROUND_TABLE_DEF diff --git a/sprout/math/quaternion/quaternion.hpp b/sprout/math/quaternion/quaternion.hpp index 5da2363e..b70fb371 100644 --- a/sprout/math/quaternion/quaternion.hpp +++ b/sprout/math/quaternion/quaternion.hpp @@ -17,6 +17,21 @@ #include namespace sprout { + namespace detail { + template + struct base_static_size { + public: + SPROUT_STATIC_CONSTEXPR T static_size = V; + }; + template + SPROUT_CONSTEXPR_OR_CONST T sprout::detail::base_static_size::static_size; + + template + struct inherit_static_size + : public sprout::detail::base_static_size + {}; + } // namespace detail + namespace math { #define SPROUT_QUATERNION_ACCESSOR_GENERATOR(type) \ @@ -77,7 +92,9 @@ namespace sprout { // quaternion // template - class quaternion { + class quaternion + : public sprout::detail::inherit_static_size > + { private: typedef sprout::array array_type; public: @@ -91,8 +108,6 @@ namespace sprout { typedef typename array_type::const_pointer const_pointer; typedef typename array_type::reverse_iterator reverse_iterator; typedef typename array_type::const_reverse_iterator const_reverse_iterator; - public: - SPROUT_STATIC_CONSTEXPR size_type static_size = array_type::static_size; private: array_type elems_; public: @@ -337,8 +352,6 @@ namespace sprout { return elems_.c_array(); } }; - template - SPROUT_CONSTEXPR_OR_CONST typename sprout::math::quaternion::size_type sprout::math::quaternion::static_size; template<> class quaternion; @@ -361,8 +374,6 @@ namespace sprout { typedef typename array_type::const_pointer const_pointer; \ typedef typename array_type::reverse_iterator reverse_iterator; \ typedef typename array_type::const_reverse_iterator const_reverse_iterator; \ - public: \ - SPROUT_STATIC_CONSTEXPR size_type static_size = array_type::static_size; \ private: \ array_type elems_; @@ -640,11 +651,14 @@ namespace sprout { return elems_.c_array(); \ } -#define SPROUT_QUATERNION_MEMBER_STATIC_SIZE_SPECIALIZATION_GENERATOR(type) \ - SPROUT_CONSTEXPR_OR_CONST typename sprout::math::quaternion::size_type sprout::math::quaternion::static_size; +#define SPROUT_QUATERNION_BASE_STATIC_SIZE_DECL(type) \ + public sprout::detail::inherit_static_size > + template<> - class quaternion { + class quaternion + : SPROUT_QUATERNION_BASE_STATIC_SIZE_DECL(float) + { public: SPROUT_QUATERNION_MEMBER_TYPE_DATA_GENERATOR(float) public: @@ -656,10 +670,11 @@ namespace sprout { SPROUT_QUATERNION_MEMBER_ALGEBRAIC_GENERATOR(float) SPROUT_QUATERNION_MEMBER_CONTAINER_GENERATOR(float) }; - SPROUT_QUATERNION_MEMBER_STATIC_SIZE_SPECIALIZATION_GENERATOR(float) template<> - class quaternion { + class quaternion + : SPROUT_QUATERNION_BASE_STATIC_SIZE_DECL(double) + { public: SPROUT_QUATERNION_MEMBER_TYPE_DATA_GENERATOR(double) public: @@ -671,10 +686,11 @@ namespace sprout { SPROUT_QUATERNION_MEMBER_ALGEBRAIC_GENERATOR(double) SPROUT_QUATERNION_MEMBER_CONTAINER_GENERATOR(double) }; - SPROUT_QUATERNION_MEMBER_STATIC_SIZE_SPECIALIZATION_GENERATOR(double) template<> - class quaternion { + class quaternion + : SPROUT_QUATERNION_BASE_STATIC_SIZE_DECL(long double) + { public: SPROUT_QUATERNION_MEMBER_TYPE_DATA_GENERATOR(long double) public: @@ -686,7 +702,6 @@ namespace sprout { SPROUT_QUATERNION_MEMBER_ALGEBRAIC_GENERATOR(long double) SPROUT_QUATERNION_MEMBER_CONTAINER_GENERATOR(long double) }; - SPROUT_QUATERNION_MEMBER_STATIC_SIZE_SPECIALIZATION_GENERATOR(long double) SPROUT_CONSTEXPR sprout::math::quaternion::quaternion(sprout::math::quaternion const& a_recopier) : elems_{{ diff --git a/sprout/uuid/detail/table.hpp b/sprout/uuid/detail/table.hpp index 912cbd96..24a55dd6 100644 --- a/sprout/uuid/detail/table.hpp +++ b/sprout/uuid/detail/table.hpp @@ -22,14 +22,14 @@ namespace sprout { SPROUT_LITERAL_CHAR_DEF(lbrace, '{'); SPROUT_LITERAL_CHAR_DEF(rbrace, '}'); - template + template struct values; # define SPROUT_UUID_TABLE_DEF \ {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15}} - template<> - struct values { + template + struct values { public: typedef sprout::array table_type; public: @@ -37,8 +37,9 @@ namespace sprout { SPROUT_STATIC_CONSTEXPR_DATA_MEMBER_INNER(SPROUT_UUID_TABLE_DEF) ; }; - SPROUT_CONSTEXPR_OR_CONST sprout::uuids::detail::values::table_type - sprout::uuids::detail::values::table + template + SPROUT_CONSTEXPR_OR_CONST typename sprout::uuids::detail::values::table_type + sprout::uuids::detail::values::table SPROUT_STATIC_CONSTEXPR_DATA_MEMBER_OUTER(SPROUT_UUID_TABLE_DEF) ;