From 15fc54b3790cb43eacc49d101cb3a7dbd1adfda1 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 24 Jan 2016 18:54:16 +0900 Subject: [PATCH] fix non-const constexpr function call --- sprout/checksum/md5.hpp | 73 +++++++++++++++++---------- sprout/checksum/sha1.hpp | 27 +++++++--- sprout/checksum/sum.hpp | 23 +++++++-- sprout/checksum/xor.hpp | 23 +++++++-- sprout/functional/mem_fn.hpp | 2 +- sprout/type_traits/inherit_if_xxx.hpp | 2 +- sprout/uuid/md5_name_generator.hpp | 16 +++--- sprout/uuid/sha1_name_generator.hpp | 16 +++--- 8 files changed, 124 insertions(+), 58 deletions(-) diff --git a/sprout/checksum/md5.hpp b/sprout/checksum/md5.hpp index b190863d..f6391d7d 100644 --- a/sprout/checksum/md5.hpp +++ b/sprout/checksum/md5.hpp @@ -279,7 +279,7 @@ namespace sprout { } SPROUT_CONSTEXPR md5 const process_bits_impl(std::uint8_t bits, std::size_t i) const { return i == 0 ? *this - : process_bit(((bits >> (i - 1)) & 1) != 0).process_bits_impl(bits, i - 1) + : c_process_bit(((bits >> (i - 1)) & 1) != 0).process_bits_impl(bits, i - 1) ; } SPROUT_CONSTEXPR md5 const process_byte_impl(std::uint8_t byte, std::size_t index, std::size_t offset) const { @@ -304,7 +304,7 @@ namespace sprout { template SPROUT_CONSTEXPR md5 const process_block_impl(InputIterator first, InputIterator last) const { return first == last ? *this - : process_byte(*first).process_block_impl(sprout::next(first), last) + : c_process_byte(*first).process_block_impl(sprout::next(first), last) ; } SPROUT_CONSTEXPR std::uint64_t pad_size() const { @@ -312,18 +312,18 @@ namespace sprout { } SPROUT_CONSTEXPR md5 const process_padding(std::uint64_t pad_size) const { return pad_size == 0 ? *this - : process_bit(false).process_padding(pad_size - 1) + : c_process_bit(false).process_padding(pad_size - 1) ; } SPROUT_CONSTEXPR md5 const process_length(std::uint64_t bit_count) const { - return process_byte(static_cast(bit_count & 0xFF)) - .process_byte(static_cast((bit_count >> 8) & 0xFF)) - .process_byte(static_cast((bit_count >> 16) & 0xFF)) - .process_byte(static_cast((bit_count >> 24) & 0xFF)) - .process_byte(static_cast((bit_count >> 32) & 0xFF)) - .process_byte(static_cast((bit_count >> 40) & 0xFF)) - .process_byte(static_cast((bit_count >> 48) & 0xFF)) - .process_byte(static_cast((bit_count >> 56) & 0xFF)) + return c_process_byte(static_cast(bit_count & 0xFF)) + .c_process_byte(static_cast((bit_count >> 8) & 0xFF)) + .c_process_byte(static_cast((bit_count >> 16) & 0xFF)) + .c_process_byte(static_cast((bit_count >> 24) & 0xFF)) + .c_process_byte(static_cast((bit_count >> 32) & 0xFF)) + .c_process_byte(static_cast((bit_count >> 40) & 0xFF)) + .c_process_byte(static_cast((bit_count >> 48) & 0xFF)) + .c_process_byte(static_cast((bit_count >> 56) & 0xFF)) ; } SPROUT_CONSTEXPR value_type make_value() const { @@ -376,45 +376,66 @@ namespace sprout { } SPROUT_CONSTEXPR md5 const process_bit(bool bit) const { + return c_process_bit(bit); + } + SPROUT_CONSTEXPR md5 const process_bits(std::uint8_t bits, std::size_t bit_count) const { + return c_process_bits(bits, bit_count); + } + SPROUT_CONSTEXPR md5 const process_byte(std::uint8_t byte) const { + return c_process_byte(byte); + } + template + SPROUT_CONSTEXPR md5 const process_block(InputIterator bytes_begin, InputIterator bytes_end) const { + return c_process_block(bytes_begin, bytes_end); + } + template + SPROUT_CONSTEXPR md5 const process_bytes(InputIterator buffer, std::size_t byte_count) const { + return c_process_bytes(buffer, byte_count); + } + template + SPROUT_CONSTEXPR md5 const process_range(InputRange const& bytes_range) const { + return c_process_range(bytes_range); + } + SPROUT_CONSTEXPR md5 const c_process_bit(bool bit) const { return process_bit_impl( bit, static_cast(bit_count_ % (64 * 8) / 32), static_cast(bit_count_ % 32) ); } - SPROUT_CONSTEXPR md5 const process_bits(std::uint8_t bits, std::size_t bit_count) const { + SPROUT_CONSTEXPR md5 const c_process_bits(std::uint8_t bits, std::size_t bit_count) const { return process_bits_impl(bits, bit_count); } - SPROUT_CONSTEXPR md5 const process_byte(std::uint8_t byte) const { + SPROUT_CONSTEXPR md5 const c_process_byte(std::uint8_t byte) const { return bit_count_ % 8 == 0 ? process_byte_impl( byte, static_cast(bit_count_ % (64 * 8) / 32), static_cast(bit_count_ % 32) ) - : process_bit(((byte >> 7) & 1) != 0) - .process_bit(((byte >> 6) & 1) != 0) - .process_bit(((byte >> 5) & 1) != 0) - .process_bit(((byte >> 4) & 1) != 0) - .process_bit(((byte >> 3) & 1) != 0) - .process_bit(((byte >> 2) & 1) != 0) - .process_bit(((byte >> 1) & 1) != 0) - .process_bit((byte & 1) != 0) + : c_process_bit(((byte >> 7) & 1) != 0) + .c_process_bit(((byte >> 6) & 1) != 0) + .c_process_bit(((byte >> 5) & 1) != 0) + .c_process_bit(((byte >> 4) & 1) != 0) + .c_process_bit(((byte >> 3) & 1) != 0) + .c_process_bit(((byte >> 2) & 1) != 0) + .c_process_bit(((byte >> 1) & 1) != 0) + .c_process_bit((byte & 1) != 0) ; } template - SPROUT_CONSTEXPR md5 const process_block(InputIterator bytes_begin, InputIterator bytes_end) const { + SPROUT_CONSTEXPR md5 const c_process_block(InputIterator bytes_begin, InputIterator bytes_end) const { return process_block_impl( sprout::make_bytes_iterator(bytes_begin), sprout::make_bytes_iterator(bytes_end) ); } template - SPROUT_CONSTEXPR md5 const process_bytes(InputIterator buffer, std::size_t byte_count) const { - return process_block(buffer, sprout::next(buffer, byte_count)); + SPROUT_CONSTEXPR md5 const c_process_bytes(InputIterator buffer, std::size_t byte_count) const { + return c_process_block(buffer, sprout::next(buffer, byte_count)); } template - SPROUT_CONSTEXPR md5 const process_range(InputRange const& bytes_range) const { - return process_block(sprout::begin(bytes_range), sprout::end(bytes_range)); + SPROUT_CONSTEXPR md5 const c_process_range(InputRange const& bytes_range) const { + return c_process_block(sprout::begin(bytes_range), sprout::end(bytes_range)); } SPROUT_CXX14_CONSTEXPR void process_bit(bool bit) { diff --git a/sprout/checksum/sha1.hpp b/sprout/checksum/sha1.hpp index 40ec4f78..80ca87f8 100644 --- a/sprout/checksum/sha1.hpp +++ b/sprout/checksum/sha1.hpp @@ -263,7 +263,7 @@ namespace sprout { ; } SPROUT_CONSTEXPR sha1 const process_block() const { - return process_block_1(h_[0], h_[1], h_[2], h_[3], h_[4]); + return c_process_block(); } SPROUT_CONSTEXPR sha1 const c_process_block() const { return process_block_1(h_[0], h_[1], h_[2], h_[3], h_[4]); @@ -458,6 +458,21 @@ namespace sprout { } SPROUT_CONSTEXPR sha1 const process_byte(std::uint8_t byte) const { + return c_process_byte(byte); + } + template + SPROUT_CONSTEXPR sha1 const process_block(InputIterator bytes_begin, InputIterator bytes_end) const { + return c_process_block(bytes_begin, bytes_end); + } + template + SPROUT_CONSTEXPR sha1 const process_bytes(InputIterator buffer, std::size_t byte_count) const { + return c_process_bytes(buffer, byte_count); + } + template + SPROUT_CONSTEXPR sha1 const process_range(InputRange const& bytes_range) const { + return c_process_range(bytes_range); + } + SPROUT_CONSTEXPR sha1 const c_process_byte(std::uint8_t byte) const { return process( h_, sprout::fixed::set(block_, block_.begin() + block_byte_index_, byte), @@ -466,19 +481,19 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR sha1 const process_block(InputIterator bytes_begin, InputIterator bytes_end) const { + SPROUT_CONSTEXPR sha1 const c_process_block(InputIterator bytes_begin, InputIterator bytes_end) const { return process_block_impl( sprout::make_bytes_iterator(bytes_begin), sprout::make_bytes_iterator(bytes_end) ); } template - SPROUT_CONSTEXPR sha1 const process_bytes(InputIterator buffer, std::size_t byte_count) const { - return process_block(buffer, sprout::next(buffer, byte_count)); + SPROUT_CONSTEXPR sha1 const c_process_bytes(InputIterator buffer, std::size_t byte_count) const { + return c_process_block(buffer, sprout::next(buffer, byte_count)); } template - SPROUT_CONSTEXPR sha1 const process_range(InputRange const& bytes_range) const { - return process_block(sprout::begin(bytes_range), sprout::end(bytes_range)); + SPROUT_CONSTEXPR sha1 const c_process_range(InputRange const& bytes_range) const { + return c_process_block(sprout::begin(bytes_range), sprout::end(bytes_range)); } SPROUT_CXX14_CONSTEXPR void process_byte(std::uint8_t byte) { diff --git a/sprout/checksum/sum.hpp b/sprout/checksum/sum.hpp index 462c8beb..9d89487b 100644 --- a/sprout/checksum/sum.hpp +++ b/sprout/checksum/sum.hpp @@ -59,19 +59,34 @@ namespace sprout { } SPROUT_CONSTEXPR sum_basic const process_byte(std::uint8_t byte) const { - return sum_basic(sum_ + byte); + return c_process_byte(byte); } template SPROUT_CONSTEXPR sum_basic const process_block(InputIterator bytes_begin, InputIterator bytes_end) const { - return sum_basic(calc_sum(bytes_begin, bytes_end)); + return c_process_block(bytes_begin, bytes_end); } template SPROUT_CONSTEXPR sum_basic const process_bytes(InputIterator buffer, std::size_t byte_count) const { - return process_block(buffer, sprout::next(buffer, byte_count)); + return c_process_bytes(buffer, byte_count); } template SPROUT_CONSTEXPR sum_basic const process_range(InputRange const& bytes_range) const { - return process_block(sprout::begin(bytes_range), sprout::end(bytes_range)); + return c_process_range(bytes_range); + } + SPROUT_CONSTEXPR sum_basic const c_process_byte(std::uint8_t byte) const { + return sum_basic(sum_ + byte); + } + template + SPROUT_CONSTEXPR sum_basic const c_process_block(InputIterator bytes_begin, InputIterator bytes_end) const { + return sum_basic(calc_sum(bytes_begin, bytes_end)); + } + template + SPROUT_CONSTEXPR sum_basic const c_process_bytes(InputIterator buffer, std::size_t byte_count) const { + return c_process_block(buffer, sprout::next(buffer, byte_count)); + } + template + SPROUT_CONSTEXPR sum_basic const c_process_range(InputRange const& bytes_range) const { + return c_process_block(sprout::begin(bytes_range), sprout::end(bytes_range)); } SPROUT_CXX14_CONSTEXPR void process_byte(std::uint8_t byte) { diff --git a/sprout/checksum/xor.hpp b/sprout/checksum/xor.hpp index 25a5cb46..344eac5b 100644 --- a/sprout/checksum/xor.hpp +++ b/sprout/checksum/xor.hpp @@ -48,19 +48,34 @@ namespace sprout { } SPROUT_CONSTEXPR xor8 const process_byte(std::uint8_t byte) const { - return xor8(sum_ ^ byte); + return c_process_byte(byte); } template SPROUT_CONSTEXPR xor8 const process_block(InputIterator bytes_begin, InputIterator bytes_end) const { - return xor8(calc_sum(bytes_begin, bytes_end)); + return c_process_block(bytes_begin, bytes_end); } template SPROUT_CONSTEXPR xor8 const process_bytes(InputIterator buffer, std::size_t byte_count) const { - return process_block(buffer, sprout::next(buffer, byte_count)); + return c_process_bytes(buffer, byte_count); } template SPROUT_CONSTEXPR xor8 const process_range(InputRange const& bytes_range) const { - return process_block(sprout::begin(bytes_range), sprout::end(bytes_range)); + return c_process_range(bytes_range); + } + SPROUT_CONSTEXPR xor8 const c_process_byte(std::uint8_t byte) const { + return xor8(sum_ ^ byte); + } + template + SPROUT_CONSTEXPR xor8 const c_process_block(InputIterator bytes_begin, InputIterator bytes_end) const { + return xor8(calc_sum(bytes_begin, bytes_end)); + } + template + SPROUT_CONSTEXPR xor8 const c_process_bytes(InputIterator buffer, std::size_t byte_count) const { + return c_process_block(buffer, sprout::next(buffer, byte_count)); + } + template + SPROUT_CONSTEXPR xor8 const c_process_range(InputRange const& bytes_range) const { + return c_process_block(sprout::begin(bytes_range), sprout::end(bytes_range)); } SPROUT_CXX14_CONSTEXPR void process_byte(std::uint8_t byte) { diff --git a/sprout/functional/mem_fn.hpp b/sprout/functional/mem_fn.hpp index afb659b5..d789acfd 100644 --- a/sprout/functional/mem_fn.hpp +++ b/sprout/functional/mem_fn.hpp @@ -207,7 +207,7 @@ namespace sprout { struct result_type : public sprout::detail::mem_fn_const_or_non< Res, - (sizeof(two) == sizeof(check_const(get_ref(), sprout::identity::type()))) + (sizeof(two) == sizeof(check_const(get_ref(), typename sprout::identity::type()))) > {}; template diff --git a/sprout/type_traits/inherit_if_xxx.hpp b/sprout/type_traits/inherit_if_xxx.hpp index 625e48e3..2172dfa4 100644 --- a/sprout/type_traits/inherit_if_xxx.hpp +++ b/sprout/type_traits/inherit_if_xxx.hpp @@ -62,7 +62,7 @@ typename std::enable_if::value>::type \ > { \ public: \ - SPROUT_STATIC_CONSTEXPR std::size_t ALIAS = T::CONSTANT; \ + SPROUT_STATIC_CONSTEXPR typename std::decay::type/*std::size_t*/ ALIAS = T::CONSTANT; \ };/* \ template \ SPROUT_CONSTEXPR_OR_CONST std::size_t NAME< \ diff --git a/sprout/uuid/md5_name_generator.hpp b/sprout/uuid/md5_name_generator.hpp index a7495b63..1afc48a9 100644 --- a/sprout/uuid/md5_name_generator.hpp +++ b/sprout/uuid/md5_name_generator.hpp @@ -23,7 +23,7 @@ namespace sprout { public: typedef sprout::uuids::uuid result_type; private: - typedef typename result_type::value_type value_type; + typedef result_type::value_type value_type; private: sprout::md5 sum_; private: @@ -52,26 +52,26 @@ namespace sprout { } public: SPROUT_CONSTEXPR md5_name_generator() - : sum_(sprout::md5::const_type().process_range(sprout::uuids::uuid{{0}})) + : sum_(sprout::md5().c_process_range(sprout::uuids::uuid{{0}})) {} explicit SPROUT_CONSTEXPR md5_name_generator(sprout::uuids::uuid const& namespace_uuid) - : sum_(sprout::md5::const_type().process_range(namespace_uuid)) + : sum_(sprout::md5().c_process_range(namespace_uuid)) {} template SPROUT_CONSTEXPR result_type operator()(sprout::basic_string const& name) const { - return sha_to_uuid(sum_.process_range(name)); + return sha_to_uuid(sum_.c_process_range(name)); } SPROUT_CONSTEXPR result_type operator()(char const* name) const { - return sha_to_uuid(sum_.process_bytes(name, sprout::char_traits::length(name))); + return sha_to_uuid(sum_.c_process_bytes(name, sprout::char_traits::length(name))); } SPROUT_CONSTEXPR result_type operator()(wchar_t const* name) const { - return sha_to_uuid(sum_.process_bytes(name, sprout::char_traits::length(name))); + return sha_to_uuid(sum_.c_process_bytes(name, sprout::char_traits::length(name))); } SPROUT_CONSTEXPR result_type operator()(char16_t const* name) const { - return sha_to_uuid(sum_.process_bytes(name, sprout::char_traits::length(name))); + return sha_to_uuid(sum_.c_process_bytes(name, sprout::char_traits::length(name))); } SPROUT_CONSTEXPR result_type operator()(char32_t const* name) const { - return sha_to_uuid(sum_.process_bytes(name, sprout::char_traits::length(name))); + return sha_to_uuid(sum_.c_process_bytes(name, sprout::char_traits::length(name))); } }; diff --git a/sprout/uuid/sha1_name_generator.hpp b/sprout/uuid/sha1_name_generator.hpp index 89c94f26..78a431a6 100644 --- a/sprout/uuid/sha1_name_generator.hpp +++ b/sprout/uuid/sha1_name_generator.hpp @@ -23,7 +23,7 @@ namespace sprout { public: typedef sprout::uuids::uuid result_type; private: - typedef typename result_type::value_type value_type; + typedef result_type::value_type value_type; private: sprout::sha1 sum_; private: @@ -52,26 +52,26 @@ namespace sprout { } public: SPROUT_CONSTEXPR sha1_name_generator() - : sum_(sprout::sha1::const_type().process_range(sprout::uuids::uuid{{0}})) + : sum_(sprout::sha1().c_process_range(sprout::uuids::uuid{{0}})) {} explicit SPROUT_CONSTEXPR sha1_name_generator(sprout::uuids::uuid const& namespace_uuid) - : sum_(sprout::sha1::const_type().process_range(namespace_uuid)) + : sum_(sprout::sha1().c_process_range(namespace_uuid)) {} template SPROUT_CONSTEXPR result_type operator()(sprout::basic_string const& name) const { - return sha_to_uuid(sum_.process_range(name)); + return sha_to_uuid(sum_.c_process_range(name)); } SPROUT_CONSTEXPR result_type operator()(char const* name) const { - return sha_to_uuid(sum_.process_bytes(name, sprout::char_traits::length(name))); + return sha_to_uuid(sum_.c_process_bytes(name, sprout::char_traits::length(name))); } SPROUT_CONSTEXPR result_type operator()(wchar_t const* name) const { - return sha_to_uuid(sum_.process_bytes(name, sprout::char_traits::length(name))); + return sha_to_uuid(sum_.c_process_bytes(name, sprout::char_traits::length(name))); } SPROUT_CONSTEXPR result_type operator()(char16_t const* name) const { - return sha_to_uuid(sum_.process_bytes(name, sprout::char_traits::length(name))); + return sha_to_uuid(sum_.c_process_bytes(name, sprout::char_traits::length(name))); } SPROUT_CONSTEXPR result_type operator()(char32_t const* name) const { - return sha_to_uuid(sum_.process_bytes(name, sprout::char_traits::length(name))); + return sha_to_uuid(sum_.c_process_bytes(name, sprout::char_traits::length(name))); } };