diff --git a/include/boost/dynamic_bitset/dynamic_bitset.hpp b/include/boost/dynamic_bitset/dynamic_bitset.hpp index 4f96abb..232a6b4 100644 --- a/include/boost/dynamic_bitset/dynamic_bitset.hpp +++ b/include/boost/dynamic_bitset/dynamic_bitset.hpp @@ -1249,6 +1249,11 @@ public: // ----------------------------------------------------------------------- BOOST_DYNAMIC_BITSET_CONSTEXPR20 bool intersects( const dynamic_bitset & b ) const; + //! A deprecated synonym for `find_first_one()`. + // ----------------------------------------------------------------------- + BOOST_DEPRECATED( "Use find_first_one(), instead" ) + BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_first( size_type pos = 0 ) const; + //! Finds the first set bit in `*this` with an index >= `pos`, //! if any. //! @@ -1260,8 +1265,13 @@ public: //! \par Throws //! Nothing. // ----------------------------------------------------------------------- - BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_first( size_type pos = 0 ) const; + BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_first_one( size_type pos = 0 ) const; + //! A deprecated synonym for `find_first_zero()`. + // ----------------------------------------------------------------------- + BOOST_DEPRECATED( "Use find_first_zero(), instead" ) + BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_first_off( size_type pos = 0 ) const; + //! Finds the first unset bit in `*this` with an index >= `pos`, //! if any. //! @@ -1276,7 +1286,12 @@ public: //! \par Throws //! Nothing. // ----------------------------------------------------------------------- - BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_first_off( size_type pos = 0 ) const; + BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_first_zero( size_type pos = 0 ) const; + + //! A deprecated synonym for `find_next_one()`. + // ----------------------------------------------------------------------- + BOOST_DEPRECATED( "Use find_next_one(), instead" ) + BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_next( size_type pos ) const; //! Finds the first bit set in `*this` with an index > `pos`, if //! any. @@ -1291,7 +1306,12 @@ public: //! \par Throws //! Nothing. // ----------------------------------------------------------------------- - BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_next( size_type pos ) const; + BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_next_one( size_type pos ) const; + + //! A deprecated synonym for `find_next_zero()`. + // ----------------------------------------------------------------------- + BOOST_DEPRECATED( "Use find_next_zero(), instead" ) + BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_next_off( size_type pos ) const; //! Finds the first unset bit in `*this` with an index > `pos`, //! if any. @@ -1303,7 +1323,7 @@ public: //! The lowest index `i` greater than `pos` such that bit `i` is //! unset, or `npos` if no such index exists. // ----------------------------------------------------------------------- - BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_next_off( size_type pos ) const; + BOOST_DYNAMIC_BITSET_CONSTEXPR20 size_type find_next_zero( size_type pos ) const; template< typename B, typename A > friend BOOST_DYNAMIC_BITSET_CONSTEXPR20 bool operator==( const dynamic_bitset< B, A > & a, const dynamic_bitset< B, A > & b ); diff --git a/include/boost/dynamic_bitset/impl/dynamic_bitset.ipp b/include/boost/dynamic_bitset/impl/dynamic_bitset.ipp index e2ce360..15d7beb 100644 --- a/include/boost/dynamic_bitset/impl/dynamic_bitset.ipp +++ b/include/boost/dynamic_bitset/impl/dynamic_bitset.ipp @@ -1207,7 +1207,7 @@ dynamic_bitset< Block, AllocatorOrContainer >:: // Check for overflows. This may be a performance burden on very large // bitsets but is required by the specification, sorry. - if ( find_first( ulong_width ) != npos ) { + if ( find_first_one( ulong_width ) != npos ) { BOOST_THROW_EXCEPTION( std::overflow_error( "boost::dynamic_bitset::to_ulong overflow" ) ); } @@ -1392,6 +1392,13 @@ dynamic_bitset< Block, AllocatorOrContainer >::m_do_find_from( size_type first_b template< typename Block, typename AllocatorOrContainer > BOOST_DYNAMIC_BITSET_CONSTEXPR20 typename dynamic_bitset< Block, AllocatorOrContainer >::size_type dynamic_bitset< Block, AllocatorOrContainer >::find_first( size_type pos ) const +{ + return find_first_one( pos ); +} + +template< typename Block, typename AllocatorOrContainer > +BOOST_DYNAMIC_BITSET_CONSTEXPR20 typename dynamic_bitset< Block, AllocatorOrContainer >::size_type +dynamic_bitset< Block, AllocatorOrContainer >::find_first_one( size_type pos ) const { const size_type sz = size(); if ( pos >= sz ) { @@ -1412,6 +1419,13 @@ dynamic_bitset< Block, AllocatorOrContainer >::find_first( size_type pos ) const template< typename Block, typename AllocatorOrContainer > BOOST_DYNAMIC_BITSET_CONSTEXPR20 typename dynamic_bitset< Block, AllocatorOrContainer >::size_type dynamic_bitset< Block, AllocatorOrContainer >::find_first_off( size_type pos ) const +{ + return find_first_zero( pos ); +} + +template< typename Block, typename AllocatorOrContainer > +BOOST_DYNAMIC_BITSET_CONSTEXPR20 typename dynamic_bitset< Block, AllocatorOrContainer >::size_type +dynamic_bitset< Block, AllocatorOrContainer >::find_first_zero( size_type pos ) const { if ( pos >= size() ) { return npos; @@ -1439,19 +1453,33 @@ dynamic_bitset< Block, AllocatorOrContainer >::find_first_off( size_type pos ) c template< typename Block, typename AllocatorOrContainer > BOOST_DYNAMIC_BITSET_CONSTEXPR20 typename dynamic_bitset< Block, AllocatorOrContainer >::size_type dynamic_bitset< Block, AllocatorOrContainer >::find_next( size_type pos ) const +{ + return find_next_one( pos ); +} + +template< typename Block, typename AllocatorOrContainer > +BOOST_DYNAMIC_BITSET_CONSTEXPR20 typename dynamic_bitset< Block, AllocatorOrContainer >::size_type +dynamic_bitset< Block, AllocatorOrContainer >::find_next_one( size_type pos ) const { return pos == npos ? npos - : find_first( pos + 1 ); + : find_first_one( pos + 1 ); } template< typename Block, typename AllocatorOrContainer > BOOST_DYNAMIC_BITSET_CONSTEXPR20 typename dynamic_bitset< Block, AllocatorOrContainer >::size_type dynamic_bitset< Block, AllocatorOrContainer >::find_next_off( size_type pos ) const +{ + return find_next_zero( pos ); +} + +template< typename Block, typename AllocatorOrContainer > +BOOST_DYNAMIC_BITSET_CONSTEXPR20 typename dynamic_bitset< Block, AllocatorOrContainer >::size_type +dynamic_bitset< Block, AllocatorOrContainer >::find_next_zero( size_type pos ) const { return pos == npos ? npos - : find_first_off( pos + 1 ); + : find_first_zero( pos + 1 ); } //----------------------------------------------------------------------------- diff --git a/test/bitset_test.hpp b/test/bitset_test.hpp index 3fb18a8..3293703 100644 --- a/test/bitset_test.hpp +++ b/test/bitset_test.hpp @@ -1091,8 +1091,8 @@ struct bitset_test find_first( const Bitset & b, typename Bitset::size_type offset = 0, bool value = true ) { const typename Bitset::size_type result = value - ? b.find_first( offset ) - : b.find_first_off( offset ); + ? b.find_first_one( offset ) + : b.find_first_zero( offset ); // find first bit with value `value` from offset onwards, if any typename Bitset::size_type i = offset; @@ -1112,9 +1112,9 @@ struct bitset_test { find_first( b, pos, value); if ( value ) { - BOOST_TEST( next_bit_on( b, pos ) == b.find_next( pos ) ); + BOOST_TEST( next_bit_on( b, pos ) == b.find_next_one( pos ) ); } else { - BOOST_TEST( next_bit_off( b, pos ) == b.find_next_off( pos ) ); + BOOST_TEST( next_bit_off( b, pos ) == b.find_next_zero( pos ) ); } } diff --git a/test/dyn_bitset_unit_tests3.cpp b/test/dyn_bitset_unit_tests3.cpp index b9739ee..7e54396 100644 --- a/test/dyn_bitset_unit_tests3.cpp +++ b/test/dyn_bitset_unit_tests3.cpp @@ -299,7 +299,7 @@ run_test_cases() Tests::intersects( a, b ); } //===================================================================== - // Test find_first + // Test find_first_one/find_first_zero { // empty bitset bitset_type b; @@ -334,7 +334,7 @@ run_test_cases() Tests::find_first( b, 0, false ); } //===================================================================== - // Test find_next, find_next_off, offset find_first and offset find_first_off + // Test find_next_one, find_next_zero { // empty bitset bitset_type b; @@ -350,7 +350,7 @@ run_test_cases() Tests::find_pos( b, b.npos, false ); } { - // bitset of size 1 (find_next can never find) + // bitset of size 1 (find_next_one or find_next_zero can never find) bitset_type b( 1, 1ul ); // check