Allow choosing the underlying container type

The user can now choose the underlying container used by dynamic_bitset.
This allows e.g. having small buffer optimization by using
boost::container::small_vector.

Since the underlying container is no longer guaranteed to be
std::vector, we revert "Reflect some noexcept specifications of
std::vector in dynamic_bitset" and the related "Let MrDocs compile the
code as C++17".

Note that we didn't add serialization tests (dyn_bitset_unit_tests5.cpp)
because boost::container::small_vector has no serialization support.

This closes issue #76.
This commit is contained in:
Gennaro Prota
2025-09-05 18:00:00 +02:00
parent 467e121a68
commit 1f6e471132
10 changed files with 763 additions and 713 deletions

View File

@@ -85,10 +85,6 @@ if (DYNAMIC_BITSET_MRDOCS_BUILD)
# Create a custom target for MrDocs.
add_library(dynamic_bitset_mrdocs_target ${TEMP_CPP_FILE})
# This is to get some noexcept specifications which are only added
# if the code is compiled as C++17 or later.
set_target_properties(dynamic_bitset_mrdocs_target PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES)
# Set any other target properties here.
target_include_directories(dynamic_bitset_mrdocs_target PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(dynamic_bitset_mrdocs_target PRIVATE boost_dynamic_bitset)

View File

@@ -20,12 +20,62 @@
#include "boost/core/allocator_access.hpp"
#include <cstddef>
#include <memory>
#include <type_traits>
#include <utility>
namespace boost {
namespace detail {
namespace dynamic_bitset_impl {
template< typename AllocatorOrContainer, typename Block >
class is_container
{
private:
template< typename U >
static decltype(
std::declval< U >().resize( std::size_t{} ),
std::declval< U >()[ 0 ],
typename U::value_type(),
std::is_same< typename U::value_type, Block >{},
std::true_type{}
) test( int );
template< typename >
static std::false_type test( ... );
public:
static constexpr bool value = decltype( test< AllocatorOrContainer >( 0 ) )::value;
};
template< typename AllocatorOrContainer, typename Block, bool IsContainer >
class allocator_type_extractor_impl;
template< typename AllocatorOrContainer, typename Block >
class allocator_type_extractor_impl< AllocatorOrContainer, Block, false >
{
public:
typedef AllocatorOrContainer type;
};
template< typename AllocatorOrContainer, typename Block >
class allocator_type_extractor_impl< AllocatorOrContainer, Block, true >
{
public:
typedef typename AllocatorOrContainer::allocator_type type;
};
template< typename AllocatorOrContainer, typename Block >
class allocator_type_extractor
{
public:
typedef typename allocator_type_extractor_impl<
AllocatorOrContainer,
Block,
is_container< AllocatorOrContainer, Block >::value
>::type type;
};
template< typename T, int amount, int width /* = default */ >
struct shifter
{
@@ -138,21 +188,4 @@ 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

@@ -37,8 +37,8 @@ namespace std {
//! You can exclude this support by defining the macro
//! `BOOST_DYNAMIC_BITSET_NO_STD_HASH`.
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
struct hash< boost::dynamic_bitset< Block, Allocator > >;
template< typename Block, typename AllocatorOrContainer >
struct hash< boost::dynamic_bitset< Block, AllocatorOrContainer > >;
}
#endif
@@ -52,9 +52,9 @@ namespace boost {
//! The integer type in which the bits are stored. Defaults to
//! `unsigned long`.
//!
//! - `Allocator`
//! The allocator type used for all internal memory management.
//! Defaults to `std::allocator< Block >`.
//! - `AllocatorOrContainer`
//! Either an allocator (to use for all internal memory management) or
//! a container of Block's. Defaults to `std::allocator< Block >`.
//!
//! \par Concepts modeled
//! DefaultConstructible, CopyConstructible, CopyAssignable,
@@ -63,23 +63,29 @@ namespace boost {
//!
//! \par Type requirements
//! `Block` is a cv-unqualified unsigned integer type other than
//! `bool`. `Allocator` satisfies the standard requirements for an
//! <a href="https://en.cppreference.com/w/cpp/named_req/Allocator.html">allocator</a>.
//! `bool`. `AllocatorOrContainer` satisfies the standard requirements for an
//! <a href="https://en.cppreference.com/w/cpp/named_req/Allocator.html">allocator</a>
//! or is a container-like type.
// ---------------------------------------------------------------------------
template< typename Block, typename Allocator >
template< typename Block, typename AllocatorOrContainer >
class dynamic_bitset
{
BOOST_STATIC_ASSERT( (bool)detail::dynamic_bitset_impl::allowed_block_type< Block >::value );
typedef std::vector< Block, Allocator > buffer_type;
typedef typename std::conditional<
detail::dynamic_bitset_impl::is_container< AllocatorOrContainer, Block >::value,
AllocatorOrContainer,
std::vector< Block, AllocatorOrContainer >
>::type buffer_type;
public:
//! The same type as `Block`.
// -----------------------------------------------------------------------
typedef Block block_type;
//! The same type as `Allocator`.
//! The allocator used for all memory allocations.
// -----------------------------------------------------------------------
typedef Allocator allocator_type;
typedef typename detail::dynamic_bitset_impl::allocator_type_extractor< AllocatorOrContainer, Block >::type
allocator_type;
//! An unsigned integral type that can represent the size of the
//! bitset. See \ref size().
@@ -175,7 +181,7 @@ public:
// -----------------------------------------------------------------------
class reference
{
friend class dynamic_bitset< Block, Allocator >;
friend class dynamic_bitset< Block, AllocatorOrContainer >;
//! The one and only non-copy ctor
// -------------------------------------------------------------------
@@ -245,8 +251,7 @@ public:
// -----------------------------------------------------------------------
typedef bool const_reference;
//! Constructs a bitset of size zero. The allocator for this
//! bitset is a default-constructed object of type `Allocator`.
//! Constructs a bitset of size zero.
//!
//! \par Postconditions
//! `this->size() == 0`.
@@ -255,9 +260,7 @@ public:
// -----------------------------------------------------------------------
dynamic_bitset();
//! Constructs a bitset of size zero. A copy of the `alloc`
//! object will be used in subsequent bitset operations such as
//! `resize()` to allocate memory.
//! Constructs a bitset of size zero.
//!
//! \param alloc An allocator, a copy of which will be used to
//! allocate memory when needed.
@@ -265,7 +268,7 @@ public:
//! \par Postconditions
//! `this->size() == 0`
// -----------------------------------------------------------------------
explicit dynamic_bitset( const Allocator & alloc );
explicit dynamic_bitset( const allocator_type & alloc );
//! Constructs a bitset from an integer.
//!
@@ -299,9 +302,9 @@ public:
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc`
//! if `Allocator` is a `std::allocator`).
//! if `allocator_type` is a `std::allocator`).
// -----------------------------------------------------------------------
explicit dynamic_bitset( size_type num_bits, unsigned long value = 0, const Allocator & alloc = Allocator() );
explicit dynamic_bitset( size_type num_bits, unsigned long value = 0, const allocator_type & alloc = allocator_type() );
//! Constructs a bitset from a string of 0's and 1's. The size
//! of the bitset is `num_bits` if `num_bits != npos`, otherwise
@@ -325,7 +328,7 @@ public:
//! \param alloc The allocator to use.
// -----------------------------------------------------------------------
template< typename CharT, typename Traits, typename Alloc >
dynamic_bitset( const std::basic_string< CharT, Traits, Alloc > & s, typename std::basic_string< CharT, Traits, Alloc >::size_type pos = 0, typename std::basic_string< CharT, Traits, Alloc >::size_type n = (std::basic_string<CharT, Traits, Alloc>::npos), size_type num_bits = npos, const Allocator & alloc = Allocator() );
dynamic_bitset( const std::basic_string< CharT, Traits, Alloc > & s, typename std::basic_string< CharT, Traits, Alloc >::size_type pos = 0, typename std::basic_string< CharT, Traits, Alloc >::size_type n = (std::basic_string<CharT, Traits, Alloc>::npos), size_type num_bits = npos, const allocator_type & alloc = allocator_type() );
//! Constructs a bitset from a range of blocks or from an
//! integer.
@@ -348,7 +351,7 @@ public:
//! \code
//! dynamic_bitset(size_type num_bits,
//! unsigned long value = 0,
//! const Allocator& alloc = Allocator())
//! const allocator_type & alloc = allocator_type())
//! \endcode
//!
//! with arguments:
@@ -356,7 +359,7 @@ public:
//! \code
//! static_cast< dynamic_bitset< unsigned short >::size_type >( 8 ),
//! 7,
//! Allocator()
//! allocator_type()
//! \endcode
//!
//! Note:
@@ -396,10 +399,10 @@ public:
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc`
//! if `Allocator` is a `std::allocator`).
//! if `allocator_type` is a `std::allocator`).
// -----------------------------------------------------------------------
template< typename BlockInputIterator >
dynamic_bitset( BlockInputIterator first, BlockInputIterator last, const Allocator & alloc = Allocator() );
dynamic_bitset( BlockInputIterator first, BlockInputIterator last, const allocator_type & alloc = allocator_type() );
//! Copy constructor.
//!
@@ -412,7 +415,7 @@ public:
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc`
//! if `Allocator` is a `std::allocator`).
//! if `allocator_type` is a `std::allocator`).
//!
//! (Required by <a href="https://en.cppreference.com/w/cpp/named_req/CopyConstructible">CopyConstructible</a>.)
// -----------------------------------------------------------------------
@@ -431,7 +434,7 @@ public:
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc`
//! if `Allocator` is a `std::allocator`).
//! if `allocator_type` is a `std::allocator`).
//! (Required by <a href="https://en.cppreference.com/w/cpp/named_req/CopyAssignable">CopyAssignable</a>.)
// -----------------------------------------------------------------------
dynamic_bitset & operator=( const dynamic_bitset & b );
@@ -447,10 +450,10 @@ public:
//!
//! \param b The bitset to be swapped with `*this`.
//!
//! This member has a `noexcept` specification if and only if
//! DynamicBitset is compiled as C++17 or later.
//! \par Throws
//! Nothing.
// -----------------------------------------------------------------------
void swap( dynamic_bitset & b ) BOOST_DYNAMIC_BITSET_SWAP_NOEXCEPT;
void swap( dynamic_bitset & b ) noexcept;
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
//! Move constructor.
@@ -459,23 +462,24 @@ public:
//! while using the resources from `src`. The allocator for this
//! bitset is moved from the allocator in `src`.
//!
//! This member has a `noexcept` specification if and only if
//! DynamicBitset is compiled as C++17 or later.
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc`
//! if `allocator_type` is a `std::allocator`).
// -----------------------------------------------------------------------
dynamic_bitset( dynamic_bitset && src ) BOOST_DYNAMIC_BITSET_CPP17_OR_LATER( noexcept );
dynamic_bitset( dynamic_bitset && src );
//! 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 ) BOOST_DYNAMIC_BITSET_MOVE_ASSIGN_NOEXCEPT;
dynamic_bitset & operator=( dynamic_bitset && src );
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
//! Returns a copy of the allocator object used to construct
@@ -510,7 +514,7 @@ public:
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc`
//! if `Allocator` is a `std::allocator`).
//! if `allocator_type` is a `std::allocator`).
//!
//! \param bit The value to set the most significant bit to.
// -----------------------------------------------------------------------
@@ -667,7 +671,7 @@ public:
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc`
//! if `Allocator` is a `std::allocator`).
//! if `allocator_type` is a `std::allocator`).
// -----------------------------------------------------------------------
dynamic_bitset operator<<( size_type n ) const;
@@ -681,7 +685,7 @@ public:
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc`
//! if `Allocator` is a `std::allocator`).
//! if `allocator_type` is a `std::allocator`).
// -----------------------------------------------------------------------
dynamic_bitset operator>>( size_type n ) const;
@@ -886,7 +890,7 @@ public:
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc`
//! if `Allocator` is a `std::allocator`).
//! if `allocator_type` is a `std::allocator`).
// -----------------------------------------------------------------------
dynamic_bitset operator~() const;
@@ -1015,7 +1019,7 @@ public:
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc`
//! if `Allocator` is a `std::allocator`).
//! if `allocator_type` is a `std::allocator`).
// -----------------------------------------------------------------------
void shrink_to_fit();
@@ -1213,7 +1217,7 @@ private:
void init_from_string( const std::basic_string< CharT, Traits, Alloc > & s, typename std::basic_string< CharT, Traits, Alloc >::size_type pos, typename std::basic_string< CharT, Traits, Alloc >::size_type n, size_type num_bits );
void init_from_unsigned_long( size_type num_bits, unsigned long value /*,
const Allocator& alloc*/
const allocator_type& alloc*/
);
template< typename BlockInputIterator >
@@ -1264,17 +1268,17 @@ private:
#if ! defined BOOST_NO_INCLASS_MEMBER_INITIALIZATION
template< typename Block, typename Allocator >
template< typename Block, typename AllocatorOrContainer >
const int
dynamic_bitset< Block, Allocator >::bits_per_block;
dynamic_bitset< Block, AllocatorOrContainer >::bits_per_block;
template< typename Block, typename Allocator >
const typename dynamic_bitset< Block, Allocator >::size_type
dynamic_bitset< Block, Allocator >::npos;
template< typename Block, typename AllocatorOrContainer >
const typename dynamic_bitset< Block, AllocatorOrContainer >::size_type
dynamic_bitset< Block, AllocatorOrContainer >::npos;
template< typename Block, typename Allocator >
template< typename Block, typename AllocatorOrContainer >
const int
dynamic_bitset< Block, Allocator >::ulong_width;
dynamic_bitset< Block, AllocatorOrContainer >::ulong_width;
#endif
@@ -1289,8 +1293,8 @@ const int
//!
//! (Required by <a href="https://en.cppreference.com/w/cpp/named_req/EqualityComparable">EqualityComparable</a>.)
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
bool operator==( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template< typename Block, typename AllocatorOrContainer >
bool operator==( const dynamic_bitset< Block, AllocatorOrContainer > & a, const dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Compares two bitsets.
//!
@@ -1300,8 +1304,8 @@ bool operator==( const dynamic_bitset< Block, Allocator > & a, const dynamic_bit
//! \par Throws
//! Nothing.
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
bool operator!=( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template< typename Block, typename AllocatorOrContainer >
bool operator!=( const dynamic_bitset< Block, AllocatorOrContainer > & a, const dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Compares two bitsets.
//!
@@ -1314,8 +1318,8 @@ bool operator!=( const dynamic_bitset< Block, Allocator > & a, const dynamic_bit
//!
//! (Required by <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.)
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
bool operator<( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template< typename Block, typename AllocatorOrContainer >
bool operator<( const dynamic_bitset< Block, AllocatorOrContainer > & a, const dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Compares two bitsets.
//!
@@ -1325,8 +1329,8 @@ bool operator<( const dynamic_bitset< Block, Allocator > & a, const dynamic_bits
//! \par Throws
//! Nothing.
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
bool operator<=( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template< typename Block, typename AllocatorOrContainer >
bool operator<=( const dynamic_bitset< Block, AllocatorOrContainer > & a, const dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Compares two bitsets.
//!
@@ -1336,8 +1340,8 @@ bool operator<=( const dynamic_bitset< Block, Allocator > & a, const dynamic_bit
//! \par Throws
//! Nothing.
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
bool operator>( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template< typename Block, typename AllocatorOrContainer >
bool operator>( const dynamic_bitset< Block, AllocatorOrContainer > & a, const dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Compares two bitsets.
//!
@@ -1347,8 +1351,8 @@ bool operator>( const dynamic_bitset< Block, Allocator > & a, const dynamic_bits
//! \par Throws
//! Nothing.
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
bool operator>=( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template< typename Block, typename AllocatorOrContainer >
bool operator>=( const dynamic_bitset< Block, AllocatorOrContainer > & a, const dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Inserts a textual representation of `b` into the stream `os`,
//! highest bit first.
@@ -1376,9 +1380,9 @@ bool operator>=( const dynamic_bitset< Block, Allocator > & a, const dynamic_bit
//! \return
//! `os`.
// -----------------------------------------------------------------------
template< typename CharT, typename Traits, typename Block, typename Allocator >
template< typename CharT, typename Traits, typename Block, typename AllocatorOrContainer >
std::basic_ostream< CharT, Traits > &
operator<<( std::basic_ostream< CharT, Traits > & os, const dynamic_bitset< Block, Allocator > & b );
operator<<( std::basic_ostream< CharT, Traits > & os, const dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Extracts a `dynamic_bitset` from an input stream.
//!
@@ -1416,9 +1420,9 @@ operator<<( std::basic_ostream< CharT, Traits > & os, const dynamic_bitset< Bloc
//! \return
//! `is`.
// -----------------------------------------------------------------------
template< typename CharT, typename Traits, typename Block, typename Allocator >
template< typename CharT, typename Traits, typename Block, typename AllocatorOrContainer >
std::basic_istream< CharT, Traits > &
operator>>( std::basic_istream< CharT, Traits > & is, dynamic_bitset< Block, Allocator > & b );
operator>>( std::basic_istream< CharT, Traits > & is, dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Performs a bitwise-AND of two bitsets.
//!
@@ -1431,11 +1435,11 @@ operator>>( std::basic_istream< CharT, Traits > & is, dynamic_bitset< Block, All
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc` if
//! `Allocator` is a `std::allocator`).
//! `AllocatorOrContainer` is a `std::allocator`).
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
dynamic_bitset< Block, Allocator >
operator&( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template< typename Block, typename AllocatorOrContainer >
dynamic_bitset< Block, AllocatorOrContainer >
operator&( const dynamic_bitset< Block, AllocatorOrContainer > & a, const dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Performs a bitwise-OR of two bitsets.
//!
@@ -1447,11 +1451,11 @@ operator&( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< B
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc` if
//! `Allocator` is a `std::allocator`).
//! `allocator_type` is a `std::allocator`).
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
dynamic_bitset< Block, Allocator >
operator|( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template< typename Block, typename AllocatorOrContainer >
dynamic_bitset< Block, AllocatorOrContainer >
operator|( const dynamic_bitset< Block, AllocatorOrContainer > & a, const dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Performs a bitwise-XOR of two bitsets.
//!
@@ -1464,11 +1468,11 @@ operator|( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< B
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc` if
//! `Allocator` is a `std::allocator`).
//! `allocator_type` is a `std::allocator`).
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
dynamic_bitset< Block, Allocator >
operator^( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template< typename Block, typename AllocatorOrContainer >
dynamic_bitset< Block, AllocatorOrContainer >
operator^( const dynamic_bitset< Block, AllocatorOrContainer > & a, const dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Calculates the set difference of two bitsets.
//!
@@ -1481,23 +1485,22 @@ operator^( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< B
//!
//! \par Throws
//! An allocation error if memory is exhausted (`std::bad_alloc` if
//! `Allocator` is a `std::allocator`).
//! `allocator_type` is a `std::allocator`).
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
dynamic_bitset< Block, Allocator >
operator-( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template< typename Block, typename AllocatorOrContainer >
dynamic_bitset< Block, AllocatorOrContainer >
operator-( const dynamic_bitset< Block, AllocatorOrContainer > & a, const dynamic_bitset< Block, AllocatorOrContainer > & b );
//! Exchanges the contents of `a` and `b`.
//!
//! \param a The bitset to exchange the contents of with `b`.
//! \param b The bitset to exchange the contents of with `a`.
//!
//! This member has a `noexcept` specification if and only if
//! DynamicBitset is compiled as C++17 or later.
//! \par Throws
//! Nothing.
// -----------------------------------------------------------------------
template< typename Block, typename Allocator >
void swap( dynamic_bitset< Block, Allocator > & a, dynamic_bitset< Block, Allocator > & b )
BOOST_DYNAMIC_BITSET_CPP17_OR_LATER( noexcept( noexcept( a.swap( b ) ) ) );
template< typename Block, typename AllocatorOrContainer >
void swap( dynamic_bitset< Block, AllocatorOrContainer > & a, dynamic_bitset< Block, AllocatorOrContainer > & b ) noexcept;
//! Copies a representation of `b` into the string `s`.
//!
@@ -1520,9 +1523,9 @@ void swap( dynamic_bitset< Block, Allocator > & a, dynamic_bitset< Block, Alloca
//! \param b The bitset of which to copy the representation.
//! \param s The string in which to copy the representation.
// -----------------------------------------------------------------------
template< typename Block, typename Allocator, typename StringT >
template< typename Block, typename AllocatorOrContainer, typename StringT >
void
to_string( const dynamic_bitset< Block, Allocator > & b, StringT & s );
to_string( const dynamic_bitset< Block, AllocatorOrContainer > & b, StringT & s );
//! Writes the bits of the bitset into the iterator `result`, a
//! block at a time.
@@ -1544,9 +1547,9 @@ to_string( const dynamic_bitset< Block, Allocator > & b, StringT & s );
//! \param b The bitset of which to copy the bits.
//! \param result The start of the range to write to.
// -----------------------------------------------------------------------
template< typename Block, typename Allocator, typename BlockOutputIterator >
template< typename Block, typename AllocatorOrContainer, typename BlockOutputIterator >
void
to_block_range( const dynamic_bitset< Block, Allocator > & b, BlockOutputIterator result );
to_block_range( const dynamic_bitset< Block, AllocatorOrContainer > & b, BlockOutputIterator result );
//! Reads blocks from the iterator range into the bitset.
//!
@@ -1561,9 +1564,9 @@ to_block_range( const dynamic_bitset< Block, Allocator > & b, BlockOutputIterato
//! \param last The end of the range.
//! \param result The resulting bitset.
// -----------------------------------------------------------------------
template< typename BlockIterator, typename Block, typename Allocator >
template< typename BlockIterator, typename Block, typename AllocatorOrContainer >
void
from_block_range( BlockIterator first, BlockIterator last, dynamic_bitset< Block, Allocator > & result );
from_block_range( BlockIterator first, BlockIterator last, dynamic_bitset< Block, AllocatorOrContainer > & result );
}

File diff suppressed because it is too large Load Diff

View File

@@ -16,7 +16,7 @@
namespace boost {
template< typename Block = unsigned long, typename Allocator = std::allocator< Block > >
template< typename Block = unsigned long, typename AllocatorOrContainer = std::allocator< Block > >
class dynamic_bitset;
}

View File

@@ -15,6 +15,7 @@
#define BOOST_BITSET_TEST_HPP_GP_20040319
#include "boost/config.hpp"
#include "boost/container/small_vector.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/filesystem.hpp"
@@ -28,6 +29,10 @@
# include <locale>
#endif
template< typename T >
using small_vector = boost::container::small_vector< T, 8 >;
template< typename Block >
bool
nth_bit( Block num, std::size_t n )
@@ -347,8 +352,11 @@ struct bitset_test
b1.swap( b2 );
BOOST_TEST( b2[ i ] == x ); // now it must be equal..
b2.flip( i );
BOOST_TEST( ref == b2[ i ] ); // .. and ref must be into b2
BOOST_TEST( ref == ! x );
// Since we transformed the Allocator parameter into
// AllocatorOrContainer, the following is no longer true (think e.g.
// of boost::container::small_vector).
// BOOST_TEST( ref == b2[ i ] ); // .. and ref must be into b2
// BOOST_TEST( ref == ! x );
}
}
@@ -817,19 +825,9 @@ struct bitset_test
}
static void
capacity_test_one( const Bitset & lhs )
capacity( const Bitset & lhs )
{
// empty bitset
Bitset b( lhs );
BOOST_TEST( b.capacity() == 0 );
}
static void
capacity_test_two( const Bitset & lhs )
{
// bitset constructed with size "100"
Bitset b( lhs );
BOOST_TEST( b.capacity() >= 100 );
b.resize( 200 );
BOOST_TEST( b.capacity() >= 200 );
}
@@ -864,7 +862,7 @@ struct bitset_test
Bitset b( lhs );
b.shrink_to_fit();
BOOST_TEST( b.size() == 0 );
BOOST_TEST( b.capacity() == 0 );
BOOST_TEST( b.capacity() == Bitset().capacity() );
}
static void
@@ -875,11 +873,11 @@ struct bitset_test
b.shrink_to_fit();
BOOST_TEST( b.capacity() >= 100 );
BOOST_TEST( b.size() == 100 );
b.reserve( 200 );
BOOST_TEST( b.capacity() >= 200 );
b.reserve( 550 );
BOOST_TEST( b.capacity() >= 550 );
BOOST_TEST( b.size() == 100 );
b.shrink_to_fit();
BOOST_TEST( b.capacity() < 200 );
BOOST_TEST( b.capacity() < 550 );
BOOST_TEST( b.size() == 100 );
}

View File

@@ -132,11 +132,12 @@ run_numeric_ctor_tests( BOOST_EXPLICIT_TEMPLATE_TYPE( Tests )
}
}
template< typename Block >
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
typedef boost::dynamic_bitset< Block > bitset_type;
typedef boost::dynamic_bitset< Block, AllocatorOrContainer >
bitset_type;
typedef bitset_test< bitset_type > Tests;
const int bits_per_block = bitset_type::bits_per_block;
@@ -250,15 +251,15 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test copy constructor
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::copy_constructor( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::copy_constructor( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b ( long_string );
Tests::copy_constructor( b );
}
//=====================================================================
@@ -290,15 +291,15 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test move constructor
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::move_constructor( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::move_constructor( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::move_constructor( b );
}
//=====================================================================
@@ -352,121 +353,121 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test resize
{
boost::dynamic_bitset< Block > a;
bitset_type a;
Tests::resize( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) );
bitset_type a( std::string( "0" ) );
Tests::resize( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) );
bitset_type a( std::string( "1" ) );
Tests::resize( a );
}
{
boost::dynamic_bitset< Block > a( long_string );
bitset_type a( long_string );
Tests::resize( a );
}
//=====================================================================
// Test clear
{
boost::dynamic_bitset< Block > a;
bitset_type a;
Tests::clear( a );
}
{
boost::dynamic_bitset< Block > a( long_string );
bitset_type a( long_string );
Tests::clear( a );
}
//=====================================================================
// Test pop back
{
boost::dynamic_bitset< Block > a( std::string( "01" ) );
bitset_type a( std::string( "01" ) );
Tests::pop_back( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "10" ) );
bitset_type a( std::string( "10" ) );
Tests::pop_back( a );
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
boost::dynamic_bitset< Block > a( size_to_fill_all_blocks, 255ul );
const int size_to_fill_all_blocks = 4 * bits_per_block;
bitset_type a( size_to_fill_all_blocks, 255ul );
Tests::pop_back( a );
}
{
boost::dynamic_bitset< Block > a( long_string );
bitset_type a( long_string );
Tests::pop_back( a );
}
//=====================================================================
// Test append bit
{
boost::dynamic_bitset< Block > a;
bitset_type a;
Tests::append_bit( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) );
bitset_type a( std::string( "0" ) );
Tests::append_bit( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) );
bitset_type a( std::string( "1" ) );
Tests::append_bit( a );
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
boost::dynamic_bitset< Block > a( size_to_fill_all_blocks, 255ul );
const int size_to_fill_all_blocks = 4 * bits_per_block;
bitset_type a( size_to_fill_all_blocks, 255ul );
Tests::append_bit( a );
}
{
boost::dynamic_bitset< Block > a( long_string );
bitset_type a( long_string );
Tests::append_bit( a );
}
//=====================================================================
// Test append block
{
boost::dynamic_bitset< Block > a;
bitset_type a;
Tests::append_block( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) );
bitset_type a( std::string( "0" ) );
Tests::append_block( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) );
bitset_type a( std::string( "1" ) );
Tests::append_block( a );
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
boost::dynamic_bitset< Block > a( size_to_fill_all_blocks, 15ul );
const int size_to_fill_all_blocks = 4 * bits_per_block;
bitset_type a( size_to_fill_all_blocks, 15ul );
Tests::append_block( a );
}
{
boost::dynamic_bitset< Block > a( long_string );
bitset_type a( long_string );
Tests::append_block( a );
}
//=====================================================================
// Test append block range
{
boost::dynamic_bitset< Block > a;
std::vector< Block > blocks;
bitset_type a;
std::vector< Block > blocks;
Tests::append_block_range( a, blocks );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) );
std::vector< Block > blocks( 3 );
bitset_type a( std::string( "0" ) );
std::vector< Block > blocks( 3 );
blocks[ 0 ] = static_cast< Block >( 0 );
blocks[ 1 ] = static_cast< Block >( 1 );
blocks[ 2 ] = all_1s;
Tests::append_block_range( a, blocks );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) );
const unsigned int n = ( std::numeric_limits< unsigned char >::max )();
std::vector< Block > blocks( n );
bitset_type a( std::string( "1" ) );
const unsigned int n = ( std::numeric_limits< unsigned char >::max )();
std::vector< Block > blocks( n );
for ( typename std::vector< Block >::size_type i = 0; i < n; ++i )
blocks[ i ] = static_cast< Block >( i );
Tests::append_block_range( a, blocks );
}
{
boost::dynamic_bitset< Block > a;
bitset_type a;
a.append( Block( 1 ) );
a.append( Block( 2 ) );
Block x[] = { 3, 4, 5 };
@@ -475,8 +476,8 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
Tests::append_block_range( a, blocks );
}
{
boost::dynamic_bitset< Block > a( long_string );
std::vector< Block > blocks( 3 );
bitset_type a( long_string );
std::vector< Block > blocks( 3 );
blocks[ 0 ] = static_cast< Block >( 0 );
blocks[ 1 ] = static_cast< Block >( 1 );
blocks[ 2 ] = all_1s;
@@ -485,19 +486,19 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test bracket operator
{
boost::dynamic_bitset< Block > b1;
std::vector< bool > bitvec1;
bitset_type b1;
std::vector< bool > bitvec1;
Tests::operator_bracket( b1, bitvec1 );
}
{
boost::dynamic_bitset< Block > b( std::string( "1" ) );
std::vector< bool > bit_vec( 1, true );
bitset_type b( std::string( "1" ) );
std::vector< bool > bit_vec( 1, true );
Tests::operator_bracket( b, bit_vec );
}
{
boost::dynamic_bitset< Block > b( long_string );
std::size_t n = long_string.size();
std::vector< bool > bit_vec( n );
bitset_type b( long_string );
std::size_t n = long_string.size();
std::vector< bool > bit_vec( n );
for ( std::size_t i = 0; i < n; ++i )
bit_vec[ i ] = long_string[ n - 1 - i ] == '0' ? 0 : 1;
Tests::operator_bracket( b, bit_vec );
@@ -505,19 +506,19 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test at
{
boost::dynamic_bitset< Block > b1;
std::vector< bool > bitvec1;
bitset_type b1;
std::vector< bool > bitvec1;
Tests::at( b1, bitvec1 );
}
{
boost::dynamic_bitset< Block > b( std::string( "1" ) );
std::vector< bool > bit_vec( 1, true );
bitset_type b( std::string( "1" ) );
std::vector< bool > bit_vec( 1, true );
Tests::at( b, bit_vec );
}
{
boost::dynamic_bitset< Block > b( long_string );
std::size_t n = long_string.size();
std::vector< bool > bit_vec( n );
bitset_type b( long_string );
std::size_t n = long_string.size();
std::vector< bool > bit_vec( n );
for ( std::size_t i = 0; i < n; ++i )
bit_vec[ i ] = long_string[ n - 1 - i ] == '0' ? 0 : 1;
Tests::at( b, bit_vec );
@@ -531,7 +532,7 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
#endif
// Test copy-initialize with default constructor
{
boost::dynamic_bitset< Block > b[ 1 ] = {};
bitset_type b[ 1 ] = {};
(void)b;
}
}
@@ -540,11 +541,16 @@ int
main()
{
run_test_cases< unsigned char >();
run_test_cases< unsigned char, small_vector< unsigned char > >();
run_test_cases< unsigned short >();
run_test_cases< unsigned short, small_vector< unsigned short > >();
run_test_cases< unsigned int >();
run_test_cases< unsigned int, small_vector< unsigned int > >();
run_test_cases< unsigned long >();
run_test_cases< unsigned long, small_vector< unsigned long > >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type >();
run_test_cases< ::boost::ulong_long_type, small_vector< ::boost::ulong_long_type > >();
#endif
return boost::report_errors();

View File

@@ -14,11 +14,11 @@
#include "boost/config.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
template< typename Block >
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
typedef boost::dynamic_bitset< Block > bitset_type;
typedef boost::dynamic_bitset< Block, AllocatorOrContainer > bitset_type;
typedef bitset_test< bitset_type > Tests;
const int bits_per_block = bitset_type::bits_per_block;
@@ -27,73 +27,73 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test operator&=
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::and_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::and_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 0 ), rhs( long_string );
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::and_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 1 ), rhs( long_string );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::and_assignment( lhs, rhs );
}
//=====================================================================
// Test operator |=
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::or_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::or_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 0 ), rhs( long_string );
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::or_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 1 ), rhs( long_string );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::or_assignment( lhs, rhs );
}
//=====================================================================
// Test operator^=
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::xor_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::xor_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
bitset_type lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
Tests::xor_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string ), rhs( long_string );
bitset_type lhs( long_string ), rhs( long_string );
Tests::xor_assignment( lhs, rhs );
}
//=====================================================================
// Test operator-=
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::sub_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::sub_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
bitset_type lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
Tests::sub_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string ), rhs( long_string );
bitset_type lhs( long_string ), rhs( long_string );
Tests::sub_assignment( lhs, rhs );
}
//=====================================================================
@@ -101,15 +101,15 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{ // case pos == 0
std::size_t pos = 0;
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::shift_left_assignment( b, pos );
}
{
boost::dynamic_bitset< Block > b( std::string( "1010" ) );
bitset_type b( std::string( "1010" ) );
Tests::shift_left_assignment( b, pos );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::shift_left_assignment( b, pos );
}
}
@@ -120,7 +120,7 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
for ( int i = 1; i <= how_many; ++i ) {
std::size_t multiple = i * bits_per_block;
std::size_t non_multiple = multiple - 1;
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::shift_left_assignment( b, multiple );
Tests::shift_left_assignment( b, non_multiple );
@@ -128,12 +128,12 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::shift_left_assignment( b, pos );
}
{ // case pos >= n
std::size_t pos = long_string.size();
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::shift_left_assignment( b, pos );
}
//=====================================================================
@@ -141,15 +141,15 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{ // case pos == 0
std::size_t pos = 0;
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::shift_right_assignment( b, pos );
}
{
boost::dynamic_bitset< Block > b( std::string( "1010" ) );
bitset_type b( std::string( "1010" ) );
Tests::shift_right_assignment( b, pos );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::shift_right_assignment( b, pos );
}
}
@@ -160,7 +160,7 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
for ( int i = 1; i <= how_many; ++i ) {
std::size_t multiple = i * bits_per_block;
std::size_t non_multiple = multiple - 1;
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::shift_right_assignment( b, multiple );
Tests::shift_right_assignment( b, non_multiple );
@@ -168,197 +168,197 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::shift_right_assignment( b, pos );
}
{ // case pos >= n
std::size_t pos = long_string.size();
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::shift_right_assignment( b, pos );
}
//=====================================================================
// test b.set()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::set_all( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::set_all( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::set_all( b );
}
//=====================================================================
// Test b.set(pos)
{ // case pos >= b.size()
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::set_one( b, 0, true );
Tests::set_one( b, 0, false );
}
{ // case pos < b.size()
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::set_one( b, 0, true );
Tests::set_one( b, 0, false );
}
{ // case pos == b.size() / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::set_one( b, long_string.size() / 2, true );
Tests::set_one( b, long_string.size() / 2, false );
}
//=====================================================================
// Test b.set(pos, len)
{ // case size is 1
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::set_segment( b, 0, 1, true );
Tests::set_segment( b, 0, 1, false );
}
{ // case fill the whole set
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::set_segment( b, 0, b.size(), true );
Tests::set_segment( b, 0, b.size(), false );
}
{ // case pos = size / 4, len = size / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::set_segment( b, b.size() / 4, b.size() / 2, true );
Tests::set_segment( b, b.size() / 4, b.size() / 2, false );
}
{ // case pos = block_size / 2, len = size - block_size
boost::dynamic_bitset< Block > b( long_string );
Tests::set_segment( b, boost::dynamic_bitset< Block >::bits_per_block / 2, b.size() - boost::dynamic_bitset< Block >::bits_per_block, true );
Tests::set_segment( b, boost::dynamic_bitset< Block >::bits_per_block / 2, b.size() - boost::dynamic_bitset< Block >::bits_per_block, false );
bitset_type b( long_string );
Tests::set_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block, true );
Tests::set_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block, false );
}
{ // case pos = 1, len = size - 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::set_segment( b, 1, b.size() - 2, true );
Tests::set_segment( b, 1, b.size() - 2, false );
}
{ // case pos = 3, len = 7
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::set_segment( b, 3, 7, true );
Tests::set_segment( b, 3, 7, false );
}
//=====================================================================
// Test b.reset()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::reset_all( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::reset_all( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_all( b );
}
//=====================================================================
// Test b.reset(pos)
{ // case pos >= b.size()
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::reset_one( b, 0 );
}
{ // case pos < b.size()
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::reset_one( b, 0 );
}
{ // case pos == b.size() / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_one( b, long_string.size() / 2 );
}
//=====================================================================
// Test b.reset(pos, len)
{ // case size is 1
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::reset_segment( b, 0, 1 );
}
{ // case fill the whole set
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_segment( b, 0, b.size() );
}
{ // case pos = size / 4, len = size / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_segment( b, b.size() / 4, b.size() / 2 );
}
{ // case pos = block_size / 2, len = size - block_size
boost::dynamic_bitset< Block > b( long_string );
Tests::reset_segment( b, boost::dynamic_bitset< Block >::bits_per_block / 2, b.size() - boost::dynamic_bitset< Block >::bits_per_block );
bitset_type b( long_string );
Tests::reset_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block );
}
{ // case pos = 1, len = size - 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_segment( b, 1, b.size() - 2 );
}
{ // case pos = 3, len = 7
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_segment( b, 3, 7 );
}
//=====================================================================
// Test ~b
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::operator_flip( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "1" ) );
bitset_type b( std::string( "1" ) );
Tests::operator_flip( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::operator_flip( b );
}
//=====================================================================
// Test b.flip()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::flip_all( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "1" ) );
bitset_type b( std::string( "1" ) );
Tests::flip_all( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_all( b );
}
//=====================================================================
// Test b.flip(pos)
{ // case pos >= b.size()
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::flip_one( b, 0 );
}
{ // case pos < b.size()
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::flip_one( b, 0 );
}
{ // case pos == b.size() / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_one( b, long_string.size() / 2 );
}
//=====================================================================
// Test b.flip(pos, len)
{ // case size is 1
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::flip_segment( b, 0, 1 );
}
{ // case fill the whole set
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_segment( b, 0, b.size() );
}
{ // case pos = size / 4, len = size / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_segment( b, b.size() / 4, b.size() / 2 );
}
{ // case pos = block_size / 2, len = size - block_size
boost::dynamic_bitset< Block > b( long_string );
Tests::flip_segment( b, boost::dynamic_bitset< Block >::bits_per_block / 2, b.size() - boost::dynamic_bitset< Block >::bits_per_block );
bitset_type b( long_string );
Tests::flip_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block );
}
{ // case pos = 1, len = size - 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_segment( b, 1, b.size() - 2 );
}
{ // case pos = 3, len = 7
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_segment( b, 3, 7 );
}
}
@@ -367,11 +367,16 @@ int
main()
{
run_test_cases< unsigned char >();
run_test_cases< unsigned char, small_vector< unsigned char > >();
run_test_cases< unsigned short >();
run_test_cases< unsigned short, small_vector< unsigned short > >();
run_test_cases< unsigned int >();
run_test_cases< unsigned int, small_vector< unsigned int > >();
run_test_cases< unsigned long >();
run_test_cases< unsigned long, small_vector< unsigned long > >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type >();
run_test_cases< ::boost::ulong_long_type, small_vector< ::boost::ulong_long_type > >();
#endif
return boost::report_errors();

View File

@@ -16,12 +16,12 @@
#include "boost/limits.hpp"
#include <assert.h>
template< typename Block >
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
// a bunch of typedefs which will be handy later on
typedef boost::dynamic_bitset< Block > bitset_type;
typedef boost::dynamic_bitset< Block, AllocatorOrContainer > bitset_type;
typedef bitset_test< bitset_type > Tests;
// typedef typename bitset_type::size_type size_type; // unusable with Borland 5.5.1
@@ -45,129 +45,129 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test b.to_long()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::to_ulong( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "1" ) );
bitset_type b( std::string( "1" ) );
Tests::to_ulong( b );
}
{
boost::dynamic_bitset< Block > b( bitset_type::bits_per_block, static_cast< unsigned long >( -1 ) );
bitset_type b( bitset_type::bits_per_block, static_cast< unsigned long >( -1 ) );
Tests::to_ulong( b );
}
{
std::string str( ul_width - 1, '1' );
boost::dynamic_bitset< Block > b( str );
bitset_type b( str );
Tests::to_ulong( b );
}
{
std::string ul_str( ul_width, '1' );
boost::dynamic_bitset< Block > b( ul_str );
bitset_type b( ul_str );
Tests::to_ulong( b );
}
{ // case overflow
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::to_ulong( b );
}
//=====================================================================
// Test to_string(b, str)
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::to_string( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::to_string( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::to_string( b );
}
//=====================================================================
// Test b.count()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::count( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::count( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "1" ) );
bitset_type b( std::string( "1" ) );
Tests::count( b );
}
{
boost::dynamic_bitset< Block > b( 8, 255ul );
bitset_type b( 8, 255ul );
Tests::count( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::count( b );
}
//=====================================================================
// Test b.size()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::size( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::size( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::size( b );
}
//=====================================================================
// Test b.capacity()
{
boost::dynamic_bitset< Block > b;
Tests::capacity_test_one( b );
bitset_type b;
Tests::capacity( b );
}
{
boost::dynamic_bitset< Block > b( 100 );
Tests::capacity_test_two( b );
bitset_type b( 100 );
Tests::capacity( b );
}
//=====================================================================
// Test b.reserve()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::reserve_test_one( b );
}
{
boost::dynamic_bitset< Block > b( 100 );
bitset_type b( 100 );
Tests::reserve_test_two( b );
}
//=====================================================================
// Test b.shrink_to_fit()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::shrink_to_fit_test_one( b );
}
{
boost::dynamic_bitset< Block > b( 100 );
bitset_type b( 100 );
Tests::shrink_to_fit_test_two( b );
}
//=====================================================================
// Test b.all()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::all( b );
Tests::all( ~b );
Tests::all( b.set() );
Tests::all( b.reset() );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::all( b );
Tests::all( ~b );
Tests::all( b.set() );
Tests::all( b.reset() );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::all( b );
Tests::all( ~b );
Tests::all( b.set() );
@@ -176,21 +176,21 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test b.any()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::any( b );
Tests::any( ~b );
Tests::any( b.set() );
Tests::any( b.reset() );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::any( b );
Tests::any( ~b );
Tests::any( b.set() );
Tests::any( b.reset() );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::any( b );
Tests::any( ~b );
Tests::any( b.set() );
@@ -199,21 +199,21 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test b.none()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::none( b );
Tests::none( ~b );
Tests::none( b.set() );
Tests::none( b.reset() );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::none( b );
Tests::none( ~b );
Tests::none( b.set() );
Tests::none( b.reset() );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::none( b );
Tests::none( ~b );
Tests::none( b.set() );
@@ -222,56 +222,56 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test a.is_subset_of(b)
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::subset( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::subset( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) ), b( std::string( "1" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::subset( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::subset( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::subset( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::subset( a, b );
}
//=====================================================================
// Test a.is_proper_subset_of(b)
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::proper_subset( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::proper_subset( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) ), b( std::string( "1" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::proper_subset( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::proper_subset( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::proper_subset( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::proper_subset( a, b );
}
@@ -420,288 +420,288 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test operator==
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::operator_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) ), b( std::string( "1" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::operator_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_equal( a, b );
}
//=====================================================================
// Test operator!=
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::operator_not_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_not_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) ), b( std::string( "1" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_not_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::operator_not_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_not_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_not_equal( a, b );
}
//=====================================================================
// Test operator<
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) ), b( std::string( "1" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "10" ) ), b( std::string( "11" ) );
bitset_type a( std::string( "10" ) ), b( std::string( "11" ) );
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "101" ) ), b( std::string( "11" ) );
bitset_type a( std::string( "101" ) ), b( std::string( "11" ) );
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "10" ) ), b( std::string( "111" ) );
bitset_type a( std::string( "10" ) ), b( std::string( "111" ) );
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_less_than( a, b );
}
// check for consistency with ulong behaviour when the sizes are equal
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 5ul );
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( a < b );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 4ul );
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( ! ( a < b ) );
}
{
boost::dynamic_bitset< Block > a( 3, 5ul ), b( 3, 4ul );
bitset_type a( 3, 5ul ), b( 3, 4ul );
BOOST_TEST( ! ( a < b ) );
}
// when the sizes are not equal lexicographic compare does not necessarily correspond to ulong behavior
{
boost::dynamic_bitset< Block > a( 4, 4ul ), b( 3, 5ul );
bitset_type a( 4, 4ul ), b( 3, 5ul );
BOOST_TEST( a < b );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 4, 5ul );
bitset_type a( 3, 4ul ), b( 4, 5ul );
BOOST_TEST( ! ( a < b ) );
}
{
boost::dynamic_bitset< Block > a( 4, 4ul ), b( 3, 4ul );
bitset_type a( 4, 4ul ), b( 3, 4ul );
BOOST_TEST( a < b );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 4, 4ul );
bitset_type a( 3, 4ul ), b( 4, 4ul );
BOOST_TEST( ! ( a < b ) );
}
{
boost::dynamic_bitset< Block > a( 4, 5ul ), b( 3, 4ul );
bitset_type a( 4, 5ul ), b( 3, 4ul );
BOOST_TEST( a < b );
}
{
boost::dynamic_bitset< Block > a( 3, 5ul ), b( 4, 4ul );
bitset_type a( 3, 5ul ), b( 4, 4ul );
BOOST_TEST( ! ( a < b ) );
}
//=====================================================================
// Test operator<=
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::operator_less_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_less_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) ), b( std::string( "1" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_less_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::operator_less_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_less_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_less_than_eq( a, b );
}
// check for consistency with ulong behaviour
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 5ul );
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( a <= b );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 4ul );
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( a <= b );
}
{
boost::dynamic_bitset< Block > a( 3, 5ul ), b( 3, 4ul );
bitset_type a( 3, 5ul ), b( 3, 4ul );
BOOST_TEST( ! ( a <= b ) );
}
//=====================================================================
// Test operator>
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::operator_greater_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_greater_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) ), b( std::string( "1" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_greater_than( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::operator_greater_than( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_greater_than( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_greater_than( a, b );
}
// check for consistency with ulong behaviour
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 5ul );
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( ! ( a > b ) );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 4ul );
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( ! ( a > b ) );
}
{
boost::dynamic_bitset< Block > a( 3, 5ul ), b( 3, 4ul );
bitset_type a( 3, 5ul ), b( 3, 4ul );
BOOST_TEST( a > b );
}
//=====================================================================
// Test operator<=
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::operator_greater_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_greater_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) ), b( std::string( "1" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_greater_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::operator_greater_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_greater_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_greater_than_eq( a, b );
}
// check for consistency with ulong behaviour
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 5ul );
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( ! ( a >= b ) );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 4ul );
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( a >= b );
}
{
boost::dynamic_bitset< Block > a( 3, 5ul ), b( 3, 4ul );
bitset_type a( 3, 5ul ), b( 3, 4ul );
BOOST_TEST( a >= b );
}
//=====================================================================
// Test b.test(pos)
{ // case pos >= b.size()
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::test_bit( b, 0 );
}
{ // case pos < b.size()
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::test_bit( b, 0 );
}
{ // case pos == b.size() / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::test_bit( b, long_string.size() / 2 );
}
//=====================================================================
// Test b.test_set(pos)
{ // case pos >= b.size()
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::test_set_bit( b, 0, true );
Tests::test_set_bit( b, 0, false );
}
{ // case pos < b.size()
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::test_set_bit( b, 0, true );
Tests::test_set_bit( b, 0, false );
}
{ // case pos == b.size() / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::test_set_bit( b, long_string.size() / 2, true );
Tests::test_set_bit( b, long_string.size() / 2, false );
}
@@ -709,106 +709,106 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
// Test b << pos
{ // case pos == 0
std::size_t pos = 0;
boost::dynamic_bitset< Block > b( std::string( "1010" ) );
bitset_type b( std::string( "1010" ) );
Tests::operator_shift_left( b, pos );
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::operator_shift_left( b, pos );
}
{ // case pos >= n
std::size_t pos = long_string.size();
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::operator_shift_left( b, pos );
}
//=====================================================================
// Test b >> pos
{ // case pos == 0
std::size_t pos = 0;
boost::dynamic_bitset< Block > b( std::string( "1010" ) );
bitset_type b( std::string( "1010" ) );
Tests::operator_shift_right( b, pos );
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::operator_shift_right( b, pos );
}
{ // case pos >= n
std::size_t pos = long_string.size();
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::operator_shift_right( b, pos );
}
//=====================================================================
// Test a & b
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::operator_and( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::operator_and( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 0 ), rhs( long_string );
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::operator_and( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 1 ), rhs( long_string );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_and( lhs, rhs );
}
//=====================================================================
// Test a | b
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::operator_or( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::operator_or( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 0 ), rhs( long_string );
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::operator_or( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 1 ), rhs( long_string );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_or( lhs, rhs );
}
//=====================================================================
// Test a^b
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::operator_xor( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::operator_xor( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 0 ), rhs( long_string );
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::operator_xor( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 1 ), rhs( long_string );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_xor( lhs, rhs );
}
//=====================================================================
// Test a-b
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::operator_sub( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::operator_sub( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 0 ), rhs( long_string );
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::operator_sub( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string.size(), 1 ), rhs( long_string );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_sub( lhs, rhs );
}
}
@@ -817,11 +817,16 @@ int
main()
{
run_test_cases< unsigned char >();
run_test_cases< unsigned char, small_vector< unsigned char > >();
run_test_cases< unsigned short >();
run_test_cases< unsigned short, small_vector< unsigned short > >();
run_test_cases< unsigned int >();
run_test_cases< unsigned int, small_vector< unsigned int > >();
run_test_cases< unsigned long >();
run_test_cases< unsigned long, small_vector< unsigned long > >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type >();
run_test_cases< ::boost::ulong_long_type, small_vector< ::boost::ulong_long_type > >();
#endif
return boost::report_errors();

View File

@@ -45,11 +45,11 @@ widen_string( const std::string & str, const std::locale & loc = std::locale() )
}
#endif
template< typename Block >
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
typedef boost::dynamic_bitset< Block > bitset_type;
typedef boost::dynamic_bitset< Block, AllocatorOrContainer > bitset_type;
typedef bitset_test< bitset_type > Tests;
//=====================================================================
@@ -300,11 +300,16 @@ int
main()
{
run_test_cases< unsigned char >();
run_test_cases< unsigned char, small_vector< unsigned char > >();
run_test_cases< unsigned short >();
run_test_cases< unsigned short, small_vector< unsigned short > >();
run_test_cases< unsigned int >();
run_test_cases< unsigned int, small_vector< unsigned int > >();
run_test_cases< unsigned long >();
run_test_cases< unsigned long, small_vector< unsigned long > >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type >();
run_test_cases< ::boost::ulong_long_type, small_vector< ::boost::ulong_long_type > >();
#endif
return boost::report_errors();