From 3e0107909bb48fa5eb1d7ab09223ad00c9fac9f3 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Wed, 22 Jan 2020 07:41:06 -0500 Subject: [PATCH] Replace Block(~0) with a max_limit::value --- .../boost/dynamic_bitset/detail/dynamic_bitset.hpp | 8 ++++++++ include/boost/dynamic_bitset/dynamic_bitset.hpp | 12 ++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/boost/dynamic_bitset/detail/dynamic_bitset.hpp b/include/boost/dynamic_bitset/detail/dynamic_bitset.hpp index fb2343a..36c3757 100644 --- a/include/boost/dynamic_bitset/detail/dynamic_bitset.hpp +++ b/include/boost/dynamic_bitset/detail/dynamic_bitset.hpp @@ -30,6 +30,14 @@ namespace boost { namespace detail { namespace dynamic_bitset_impl { + template + struct max_limit { + BOOST_STATIC_CONSTEXPR T value = static_cast(-1); + }; + + template + BOOST_CONSTEXPR_OR_CONST T max_limit::value; + // Gives (read-)access to the object representation // of an object of type T (3.9p4). CANNOT be used // on a base sub-object diff --git a/include/boost/dynamic_bitset/dynamic_bitset.hpp b/include/boost/dynamic_bitset/dynamic_bitset.hpp index f224051..56be3be 100644 --- a/include/boost/dynamic_bitset/dynamic_bitset.hpp +++ b/include/boost/dynamic_bitset/dynamic_bitset.hpp @@ -384,7 +384,7 @@ private: static Block bit_mask(size_type first, size_type last) BOOST_NOEXCEPT { Block res = (last == bits_per_block - 1) - ? static_cast(~0) + ? detail::dynamic_bitset_impl::max_limit::value : ((Block(1) << (last + 1)) - 1); res ^= (Block(1) << first) - 1; return res; @@ -406,7 +406,7 @@ private: } inline static Block set_block_full(Block) BOOST_NOEXCEPT { - return static_cast(~0); + return detail::dynamic_bitset_impl::max_limit::value; } inline static Block reset_block_partial(Block block, size_type first, size_type last) BOOST_NOEXCEPT @@ -764,7 +764,7 @@ resize(size_type num_bits, bool value) // strong guarantee const size_type old_num_blocks = num_blocks(); const size_type required_blocks = calc_num_blocks(num_bits); - const block_type v = value? ~Block(0) : Block(0); + const block_type v = value? detail::dynamic_bitset_impl::max_limit::value : Block(0); if (required_blocks != old_num_blocks) { m_bits.resize(required_blocks, v); // s.g. (copy) @@ -1045,7 +1045,7 @@ template dynamic_bitset& dynamic_bitset::set() { - std::fill(m_bits.begin(), m_bits.end(), static_cast(~0)); + std::fill(m_bits.begin(), m_bits.end(), detail::dynamic_bitset_impl::max_limit::value); m_zero_unused_bits(); return *this; } @@ -1138,7 +1138,7 @@ bool dynamic_bitset::all() const } const block_width_type extra_bits = count_extra_bits(); - block_type const all_ones = static_cast(~0); + block_type const all_ones = detail::dynamic_bitset_impl::max_limit::value; if (extra_bits == 0) { for (size_type i = 0, e = num_blocks(); i < e; ++i) { @@ -2107,7 +2107,7 @@ bool dynamic_bitset::m_check_invariants() const { const block_width_type extra_bits = count_extra_bits(); if (extra_bits > 0) { - const block_type mask = block_type(~0) << extra_bits; + const block_type mask = detail::dynamic_bitset_impl::max_limit::value << extra_bits; if ((m_highest_block() & mask) != 0) return false; }