Reflect some noexcept specifications of std::vector in dynamic_bitset

This closes issue #85.
This commit is contained in:
Gennaro Prota
2025-08-04 16:23:36 +02:00
parent 41c20338ef
commit 74d1e42a3f
3 changed files with 36 additions and 18 deletions

View File

@@ -138,4 +138,21 @@ BOOST_dynamic_bitset_is_numeric( ::boost::ulong_long_type );
} // namespace boost
#if ( defined( _MSVC_LANG ) && _MSVC_LANG >= 201703L ) || __cplusplus >= 201703L
#define BOOST_DYNAMIC_BITSET_CPP17_OR_LATER( x ) x
#else
#define BOOST_DYNAMIC_BITSET_CPP17_OR_LATER( x ) /**/
#endif
#define BOOST_DYNAMIC_BITSET_MOVE_ASSIGN_NOEXCEPT \
BOOST_DYNAMIC_BITSET_CPP17_OR_LATER( \
noexcept( std::allocator_traits< Allocator >::propagate_on_container_move_assignment::value \
|| std::allocator_traits< Allocator >::is_always_equal::value ) ) /**/
#define BOOST_DYNAMIC_BITSET_SWAP_NOEXCEPT \
BOOST_DYNAMIC_BITSET_CPP17_OR_LATER( \
noexcept( std::allocator_traits< Allocator >::propagate_on_container_swap::value \
|| std::allocator_traits< Allocator >::is_always_equal::value ) ) /**/
#endif // include guard

View File

@@ -407,10 +407,10 @@ public:
//! Swaps the contents of this bitset and bitset `b`.
//!
//! \par Throws
//! Nothing.
//! This member has a `noexcept` specification if and only if
//! DynamicBitset is compiled as C++17 or later.
// -----------------------------------------------------------------------
void swap( dynamic_bitset & b ) BOOST_NOEXCEPT;
void swap( dynamic_bitset & b ) BOOST_DYNAMIC_BITSET_SWAP_NOEXCEPT;
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
//! Move constructor.
@@ -419,24 +419,23 @@ public:
//! while using the resources from `src`. The allocator for this
//! bitset is moved from the allocator in `src`.
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc`
//! if `Allocator` is a `std::allocator`).
//! This member has a `noexcept` specification if and only if
//! DynamicBitset is compiled as C++17 or later.
// -----------------------------------------------------------------------
dynamic_bitset( dynamic_bitset && src );
dynamic_bitset( dynamic_bitset && src ) BOOST_DYNAMIC_BITSET_CPP17_OR_LATER( noexcept );
//! Move assignment operator.
//!
//! This bitset becomes the same as the bitset `src`, while
//! using the resources from `src`.
//!
//! This member has a `noexcept` specification if and only if
//! DynamicBitset is compiled as C++17 or later.
//!
//! \return
//! `*this`.
//!
//! \par Throws
//! Nothing.
// -----------------------------------------------------------------------
dynamic_bitset & operator=( dynamic_bitset && src );
dynamic_bitset & operator=( dynamic_bitset && src ) BOOST_DYNAMIC_BITSET_MOVE_ASSIGN_NOEXCEPT;
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
//! Returns a copy of the allocator object used to construct
@@ -1343,11 +1342,12 @@ operator-( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< B
//! Exchanges the contents of `a` and `b`.
//!
//! \par Throws
//! Nothing.
//! This member has a `noexcept` specification if and only if
//! DynamicBitset is compiled as C++17 or later.
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
void swap( dynamic_bitset< Block, Allocator > & a, dynamic_bitset< Block, Allocator > & b ) BOOST_NOEXCEPT;
void swap( dynamic_bitset< Block, Allocator > & a, dynamic_bitset< Block, Allocator > & b )
BOOST_DYNAMIC_BITSET_CPP17_OR_LATER( noexcept( noexcept( a.swap( b ) ) ) );
//! Copies a representation of `b` into the string `s`.
//!

View File

@@ -231,7 +231,7 @@ dynamic_bitset< Block, Allocator >::~dynamic_bitset()
template< typename Block, typename Allocator >
void
dynamic_bitset< Block, Allocator >::
swap( dynamic_bitset< Block, Allocator > & b ) BOOST_NOEXCEPT
swap( dynamic_bitset< Block, Allocator > & b ) BOOST_DYNAMIC_BITSET_SWAP_NOEXCEPT
{
std::swap( m_bits, b.m_bits );
std::swap( m_num_bits, b.m_num_bits );
@@ -251,7 +251,7 @@ operator=( const dynamic_bitset< Block, Allocator > & b )
template< typename Block, typename Allocator >
dynamic_bitset< Block, Allocator >::
dynamic_bitset( dynamic_bitset< Block, Allocator > && b )
dynamic_bitset( dynamic_bitset< Block, Allocator > && b ) BOOST_DYNAMIC_BITSET_CPP17_OR_LATER( noexcept )
: m_bits( boost::move( b.m_bits ) ), m_num_bits( boost::move( b.m_num_bits ) )
{
// Required so that BOOST_ASSERT(m_check_invariants()); works.
@@ -262,7 +262,7 @@ dynamic_bitset< Block, Allocator >::
template< typename Block, typename Allocator >
dynamic_bitset< Block, Allocator > &
dynamic_bitset< Block, Allocator >::
operator=( dynamic_bitset< Block, Allocator > && b )
operator=( dynamic_bitset< Block, Allocator > && b ) BOOST_DYNAMIC_BITSET_MOVE_ASSIGN_NOEXCEPT
{
if ( &b == this ) {
return *this;
@@ -1332,7 +1332,8 @@ operator-( const dynamic_bitset< Block, Allocator > & x, const dynamic_bitset< B
template< typename Block, typename Allocator >
void
swap( dynamic_bitset< Block, Allocator > & left, dynamic_bitset< Block, Allocator > & right ) BOOST_NOEXCEPT
swap( dynamic_bitset< Block, Allocator > & left, dynamic_bitset< Block, Allocator > & right )
BOOST_DYNAMIC_BITSET_CPP17_OR_LATER( noexcept( noexcept( left.swap( right ) ) ) )
{
left.swap( right );
}