Reformat all the C++ code (with ClangFormat)

This commit is contained in:
Gennaro Prota
2025-06-24 15:46:38 +02:00
parent 1092cdbfe6
commit 12acc40123
20 changed files with 4568 additions and 4627 deletions

View File

@@ -3,8 +3,6 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// An example of setting and reading some bits. Note that operator[]
// goes from the least-significant bit at 0 to the most significant
// bit at size()-1. The operator<< for dynamic_bitset prints the
@@ -20,14 +18,15 @@
#include "boost/dynamic_bitset.hpp"
#include <iostream>
int main()
int
main()
{
boost::dynamic_bitset<> x(5); // all 0's by default
x[0] = 1;
x[1] = 1;
x[4] = 1;
for (boost::dynamic_bitset<>::size_type i = 0; i < x.size(); ++i)
std::cout << x[i];
boost::dynamic_bitset<> x( 5 ); // all 0's by default
x[ 0 ] = 1;
x[ 1 ] = 1;
x[ 4 ] = 1;
for ( boost::dynamic_bitset<>::size_type i = 0; i < x.size(); ++i )
std::cout << x[ i ];
std::cout << "\n";
std::cout << x << "\n";

View File

@@ -13,18 +13,19 @@
#include "boost/dynamic_bitset.hpp"
#include <iostream>
int main()
int
main()
{
const boost::dynamic_bitset<> b0(2, 0ul);
const boost::dynamic_bitset<> b0( 2, 0ul );
std::cout << "bits(0) = " << b0 << std::endl;
const boost::dynamic_bitset<> b1(2, 1ul);
const boost::dynamic_bitset<> b1( 2, 1ul );
std::cout << "bits(1) = " << b1 << std::endl;
const boost::dynamic_bitset<> b2(2, 2ul);
const boost::dynamic_bitset<> b2( 2, 2ul );
std::cout << "bits(2) = " << b2 << std::endl;
const boost::dynamic_bitset<> b3(2, 3ul);
const boost::dynamic_bitset<> b3( 2, 3ul );
std::cout << "bits(3) = " << b3 << std::endl;
return 0;

View File

@@ -19,23 +19,21 @@
// Shifted left by 1: 001000100
// Shifted right by 1: 010010001
#include "boost/dynamic_bitset.hpp"
#include <iostream>
#include <ostream>
int main()
int
main()
{
boost::dynamic_bitset<> mask(12, 2730ul);
boost::dynamic_bitset<> mask( 12, 2730ul );
std::cout << "mask = " << mask << std::endl;
boost::dynamic_bitset<> x;
std::cout << "x.size() = " << x.size() << std::endl;
std::cout << "Enter a bitset in binary: x = " << std::flush;
if (std::cin >> x) {
if ( std::cin >> x ) {
const std::size_t sz = x.size();
std::cout << std::endl;
std::cout << "Input number: " << x << std::endl;
@@ -45,12 +43,12 @@ int main()
unsigned long ul = 0;
try {
ul = x.to_ulong();
} catch(std::overflow_error &) {
} catch ( std::overflow_error & ) {
fits_in_ulong = false;
}
std::cout << "As unsigned long: ";
if(fits_in_ulong) {
if ( fits_in_ulong ) {
std::cout << ul;
} else {
std::cout << "(overflow exception)";
@@ -58,14 +56,14 @@ int main()
std::cout << std::endl;
mask.resize(sz);
mask.resize( sz );
std::cout << "Mask (possibly resized): " << mask << std::endl;
std::cout << "And with mask: " << (x & mask) << std::endl;
std::cout << "Or with mask: " << (x | mask) << std::endl;
std::cout << "Shifted left by 1: " << (x << 1) << std::endl;
std::cout << "Shifted right by 1: " << (x >> 1) << std::endl;
std::cout << "And with mask: " << ( x & mask ) << std::endl;
std::cout << "Or with mask: " << ( x | mask ) << std::endl;
std::cout << "Shifted left by 1: " << ( x << 1 ) << std::endl;
std::cout << "Shifted right by 1: " << ( x >> 1 ) << std::endl;
}
return 0;
}

View File

@@ -16,15 +16,22 @@
// no-op function to workaround gcc bug c++/8419
//
namespace boost { namespace detail {
template <typename T> T make_non_const(T t) { return t; }
}}
namespace boost {
namespace detail {
template< typename T >
T
make_non_const( T t )
{
return t;
}
}
}
#if defined(__GNUC__)
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(expr) \
(boost::detail::make_non_const(expr))
#if defined( __GNUC__ )
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT( expr ) \
( boost::detail::make_non_const( expr ) )
#else
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(expr) (expr)
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT( expr ) ( expr )
#endif
// A couple of macros to cope with libraries without locale
@@ -34,18 +41,18 @@ namespace boost { namespace detail {
// the first macro is a no-op and the second one just expands
// to its parameter c.
//
#if defined (BOOST_USE_FACET)
#if defined( BOOST_USE_FACET )
#define BOOST_DYNAMIC_BITSET_CTYPE_FACET(ch, name, loc) \
const std::ctype<ch> & name = \
BOOST_USE_FACET(std::ctype<ch>, loc) /**/
# define BOOST_DYNAMIC_BITSET_CTYPE_FACET( ch, name, loc ) \
const std::ctype< ch > & name = \
BOOST_USE_FACET( std::ctype< ch >, loc ) /**/
#define BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, c) \
(fac.widen(c))
# define BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, c ) \
( fac.widen( c ) )
#else
#define BOOST_DYNAMIC_BITSET_CTYPE_FACET(ch, name, loc) /**/
#define BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, c) c
# define BOOST_DYNAMIC_BITSET_CTYPE_FACET( ch, name, loc ) /**/
# define BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, c ) c
#endif

View File

@@ -23,111 +23,130 @@
namespace boost {
namespace detail {
namespace dynamic_bitset_impl {
namespace detail {
namespace dynamic_bitset_impl {
template<class T>
struct max_limit {
BOOST_STATIC_CONSTEXPR T value = static_cast<T>(-1);
};
template< class T >
struct max_limit
{
BOOST_STATIC_CONSTEXPR T value = static_cast< T >( -1 );
};
template<class T>
BOOST_CONSTEXPR_OR_CONST T max_limit<T>::value;
template< class T >
BOOST_CONSTEXPR_OR_CONST T max_limit< T >::value;
template<typename T, int amount, int width /* = default */>
struct shifter
template< typename T, int amount, int width /* = default */ >
struct shifter
{
static void
left_shift( T & v )
{
static void left_shift(T & v) {
amount >= width ? (v = 0)
: (v >>= BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(amount));
amount >= width ? ( v = 0 )
: ( v >>= BOOST_DYNAMIC_BITSET_WRAP_CONSTANT( amount ) );
}
};
};
template <bool value>
struct value_to_type
template< bool value >
struct value_to_type
{
value_to_type()
{
value_to_type() {}
};
// Some library implementations simply return a dummy
// value such as
//
// size_type(-1) / sizeof(T)
//
// from vector<>::max_size. This tries to get more
// meaningful info.
//
template <typename T>
inline typename T::size_type vector_max_size_workaround(const T & v)
}
};
// Some library implementations simply return a dummy
// value such as
//
// size_type(-1) / sizeof(T)
//
// from vector<>::max_size. This tries to get more
// meaningful info.
//
template< typename T >
inline typename T::size_type
vector_max_size_workaround( const T & v )
BOOST_NOEXCEPT
{
{
typedef typename T::allocator_type allocator_type;
const allocator_type& alloc = v.get_allocator();
const allocator_type & alloc = v.get_allocator();
typename boost::allocator_size_type<allocator_type>::type alloc_max =
boost::allocator_max_size(alloc);
typename boost::allocator_size_type< allocator_type >::type alloc_max =
boost::allocator_max_size( alloc );
const typename T::size_type container_max = v.max_size();
return alloc_max < container_max ? alloc_max : container_max;
}
}
// for static_asserts
template <typename T>
struct allowed_block_type {
enum { value = T(-1) > 0 }; // ensure T has no sign
// for static_asserts
template< typename T >
struct allowed_block_type
{
enum
{
value = T( -1 ) > 0 // ensure T has no sign
};
};
template <>
struct allowed_block_type<bool> {
enum { value = false };
template<>
struct allowed_block_type< bool >
{
enum
{
value = false
};
};
template <typename T>
struct is_numeric {
enum { value = false };
template< typename T >
struct is_numeric
{
enum
{
value = false
};
};
# define BOOST_dynamic_bitset_is_numeric(x) \
#define BOOST_dynamic_bitset_is_numeric( x ) \
template<> \
struct is_numeric< x > { \
enum { value = true }; \
struct is_numeric< x > \
{ \
enum \
{ \
value = true \
}; \
} /**/
BOOST_dynamic_bitset_is_numeric(bool);
BOOST_dynamic_bitset_is_numeric(char);
BOOST_dynamic_bitset_is_numeric( bool );
BOOST_dynamic_bitset_is_numeric( char );
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
BOOST_dynamic_bitset_is_numeric(wchar_t);
#if ! defined( BOOST_NO_INTRINSIC_WCHAR_T )
BOOST_dynamic_bitset_is_numeric( wchar_t );
#endif
BOOST_dynamic_bitset_is_numeric(signed char);
BOOST_dynamic_bitset_is_numeric(short int);
BOOST_dynamic_bitset_is_numeric(int);
BOOST_dynamic_bitset_is_numeric(long int);
BOOST_dynamic_bitset_is_numeric( signed char );
BOOST_dynamic_bitset_is_numeric( short int );
BOOST_dynamic_bitset_is_numeric( int );
BOOST_dynamic_bitset_is_numeric( long int );
BOOST_dynamic_bitset_is_numeric(unsigned char);
BOOST_dynamic_bitset_is_numeric(unsigned short);
BOOST_dynamic_bitset_is_numeric(unsigned int);
BOOST_dynamic_bitset_is_numeric(unsigned long);
BOOST_dynamic_bitset_is_numeric( unsigned char );
BOOST_dynamic_bitset_is_numeric( unsigned short );
BOOST_dynamic_bitset_is_numeric( unsigned int );
BOOST_dynamic_bitset_is_numeric( unsigned long );
#if defined(BOOST_HAS_LONG_LONG)
BOOST_dynamic_bitset_is_numeric(::boost::long_long_type);
BOOST_dynamic_bitset_is_numeric(::boost::ulong_long_type);
#if defined( BOOST_HAS_LONG_LONG )
BOOST_dynamic_bitset_is_numeric( ::boost::long_long_type );
BOOST_dynamic_bitset_is_numeric( ::boost::ulong_long_type );
#endif
// intentionally omitted
//BOOST_dynamic_bitset_is_numeric(float);
//BOOST_dynamic_bitset_is_numeric(double);
//BOOST_dynamic_bitset_is_numeric(long double);
// intentionally omitted
// BOOST_dynamic_bitset_is_numeric(float);
// BOOST_dynamic_bitset_is_numeric(double);
// BOOST_dynamic_bitset_is_numeric(long double);
#undef BOOST_dynamic_bitset_is_numeric
} // dynamic_bitset_impl
} // namespace detail
} // dynamic_bitset_impl
} // namespace detail
} // namespace boost
#endif // include guard

View File

@@ -20,16 +20,16 @@
namespace boost {
namespace detail {
template <typename T>
template< typename T >
int
lowest_bit(T x)
lowest_bit( T x )
{
BOOST_ASSERT(x >= 1);
BOOST_ASSERT( x >= 1 );
// Clear all the bits that are set except the rightmost one,
// then calculate the logarithm to base 2.
//
return boost::integer_log2<T>(x - (x & (x - 1)));
return boost::integer_log2< T >( x - ( x & ( x - 1 ) ) );
}
}

View File

@@ -31,7 +31,6 @@
#include "boost/move/move.hpp"
#include "boost/static_assert.hpp"
#include "boost/throw_exception.hpp"
#include <algorithm>
#include <climits>
#include <istream>
@@ -47,11 +46,11 @@
namespace boost {
template <typename Block, typename Allocator>
template< typename Block, typename Allocator >
class dynamic_bitset
{
BOOST_STATIC_ASSERT((bool)detail::dynamic_bitset_impl::allowed_block_type<Block>::value);
typedef std::vector<Block, Allocator> buffer_type;
BOOST_STATIC_ASSERT( (bool)detail::dynamic_bitset_impl::allowed_block_type< Block >::value );
typedef std::vector< Block, Allocator > buffer_type;
public:
typedef Block block_type;
@@ -59,38 +58,35 @@ public:
typedef std::size_t size_type;
typedef typename buffer_type::size_type block_width_type;
BOOST_STATIC_CONSTANT(block_width_type, bits_per_block = (std::numeric_limits<Block>::digits));
BOOST_STATIC_CONSTANT(size_type, npos = static_cast<size_type>(-1));
BOOST_STATIC_CONSTANT( block_width_type, bits_per_block = ( std::numeric_limits< Block >::digits ) );
BOOST_STATIC_CONSTANT( size_type, npos = static_cast< size_type >( -1 ) );
// A proxy class to simulate lvalues of bit type.
//
class reference
{
friend class dynamic_bitset<Block, Allocator>;
friend class dynamic_bitset< Block, Allocator >;
// the one and only non-copy ctor
reference(block_type & b, block_width_type pos);
reference( block_type & b, block_width_type pos );
void operator&(); // left undefined
public:
// copy constructor: compiler generated
operator bool() const;
bool operator~() const;
reference& flip();
reference & flip();
reference& operator=(bool x);
reference& operator=(const reference& rhs);
reference & operator=( bool x );
reference & operator=( const reference & rhs );
reference& operator|=(bool x);
reference& operator&=(bool x);
reference& operator^=(bool x);
reference& operator-=(bool x);
reference & operator|=( bool x );
reference & operator&=( bool x );
reference & operator^=( bool x );
reference & operator-=( bool x );
private:
block_type & m_block;
@@ -99,7 +95,7 @@ public:
void do_set();
void do_reset();
void do_flip();
void do_assign(bool x);
void do_assign( bool x );
};
typedef bool const_reference;
@@ -107,13 +103,9 @@ public:
// constructors, etc.
dynamic_bitset();
explicit
dynamic_bitset(const Allocator& alloc);
explicit
dynamic_bitset(size_type num_bits, unsigned long value = 0,
const Allocator& alloc = Allocator());
explicit dynamic_bitset( const Allocator & alloc );
explicit dynamic_bitset( size_type num_bits, unsigned long value = 0, const Allocator & alloc = Allocator() );
// WARNING: you should avoid using this constructor.
//
@@ -126,73 +118,66 @@ public:
// NOTE 2:
// split into two constructors because of bugs in MSVC 6.0sp5 with STLport
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,
typename std::basic_string<CharT, Traits, Alloc>::size_type n,
size_type num_bits = npos,
const Allocator& alloc = Allocator());
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, typename std::basic_string< CharT, Traits, Alloc >::size_type n, size_type num_bits = npos, const Allocator & alloc = Allocator() );
template <typename CharT, typename Traits, typename Alloc>
explicit
dynamic_bitset(const std::basic_string<CharT, Traits, Alloc>& s,
typename std::basic_string<CharT, Traits, Alloc>::size_type pos = 0);
template< typename CharT, typename Traits, typename Alloc >
explicit dynamic_bitset( const std::basic_string< CharT, Traits, Alloc > & s, typename std::basic_string< CharT, Traits, Alloc >::size_type pos = 0 );
// The first bit in *first is the least significant bit, and the
// last bit in the block just before *last is the most significant bit.
template <typename BlockInputIterator>
dynamic_bitset(BlockInputIterator first, BlockInputIterator last,
const Allocator& alloc = Allocator());
template< typename BlockInputIterator >
dynamic_bitset( BlockInputIterator first, BlockInputIterator last, const Allocator & alloc = Allocator() );
// copy constructor
dynamic_bitset(const dynamic_bitset& b);
dynamic_bitset( const dynamic_bitset & b );
~dynamic_bitset();
void swap(dynamic_bitset& b) BOOST_NOEXCEPT;
dynamic_bitset& operator=(const dynamic_bitset& b);
void swap( dynamic_bitset & b ) BOOST_NOEXCEPT;
dynamic_bitset & operator=( const dynamic_bitset & b );
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
dynamic_bitset(dynamic_bitset&& src);
dynamic_bitset& operator=(dynamic_bitset&& src);
dynamic_bitset( dynamic_bitset && src );
dynamic_bitset & operator=( dynamic_bitset && src );
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
allocator_type get_allocator() const;
// size changing operations
void resize(size_type num_bits, bool value = false);
void resize( size_type num_bits, bool value = false );
void clear();
void push_back(bool bit);
void push_back( bool bit );
void pop_back();
void append(Block block);
void append( Block block );
template <typename BlockInputIterator>
void append(BlockInputIterator first, BlockInputIterator last); // strong guarantee
template< typename BlockInputIterator >
void append( BlockInputIterator first, BlockInputIterator last ); // strong guarantee
// bitset operations
dynamic_bitset& operator&=(const dynamic_bitset& b);
dynamic_bitset& operator|=(const dynamic_bitset& b);
dynamic_bitset& operator^=(const dynamic_bitset& b);
dynamic_bitset& operator-=(const dynamic_bitset& b);
dynamic_bitset& operator<<=(size_type n);
dynamic_bitset& operator>>=(size_type n);
dynamic_bitset operator<<(size_type n) const;
dynamic_bitset operator>>(size_type n) const;
dynamic_bitset & operator&=( const dynamic_bitset & b );
dynamic_bitset & operator|=( const dynamic_bitset & b );
dynamic_bitset & operator^=( const dynamic_bitset & b );
dynamic_bitset & operator-=( const dynamic_bitset & b );
dynamic_bitset & operator<<=( size_type n );
dynamic_bitset & operator>>=( size_type n );
dynamic_bitset operator<<( size_type n ) const;
dynamic_bitset operator>>( size_type n ) const;
// basic bit operations
dynamic_bitset& set(size_type n, size_type len, bool val /* = true */); // default would make it ambiguous
dynamic_bitset& set(size_type n, bool val = true);
dynamic_bitset& set();
dynamic_bitset& reset(size_type n, size_type len);
dynamic_bitset& reset(size_type n);
dynamic_bitset& reset();
dynamic_bitset& flip(size_type n, size_type len);
dynamic_bitset& flip(size_type n);
dynamic_bitset& flip();
reference at(size_type n);
bool at(size_type n) const;
bool test(size_type n) const;
bool test_set(size_type n, bool val = true);
dynamic_bitset & set( size_type n, size_type len, bool val /* = true */ ); // default would make it ambiguous
dynamic_bitset & set( size_type n, bool val = true );
dynamic_bitset & set();
dynamic_bitset & reset( size_type n, size_type len );
dynamic_bitset & reset( size_type n );
dynamic_bitset & reset();
dynamic_bitset & flip( size_type n, size_type len );
dynamic_bitset & flip( size_type n );
dynamic_bitset & flip();
reference at( size_type n );
bool at( size_type n ) const;
bool test( size_type n ) const;
bool test_set( size_type n, bool val = true );
bool all() const;
bool any() const;
bool none() const;
@@ -200,8 +185,8 @@ public:
size_type count() const BOOST_NOEXCEPT;
// subscript
reference operator[](size_type pos);
bool operator[](size_type pos) const;
reference operator[]( size_type pos );
bool operator[]( size_type pos ) const;
unsigned long to_ulong() const;
@@ -210,122 +195,104 @@ public:
size_type max_size() const BOOST_NOEXCEPT;
bool empty() const BOOST_NOEXCEPT;
size_type capacity() const BOOST_NOEXCEPT;
void reserve(size_type num_bits);
void reserve( size_type num_bits );
void shrink_to_fit();
bool is_subset_of(const dynamic_bitset& a) const;
bool is_proper_subset_of(const dynamic_bitset& a) const;
bool intersects(const dynamic_bitset & a) const;
bool is_subset_of( const dynamic_bitset & a ) const;
bool is_proper_subset_of( const dynamic_bitset & a ) const;
bool intersects( const dynamic_bitset & a ) const;
// lookup
size_type find_first() const;
size_type find_first(size_type pos) const;
size_type find_next(size_type pos) const;
size_type find_first( size_type pos ) const;
size_type find_next( size_type pos ) const;
// lexicographical comparison
template <typename B, typename A>
friend bool operator==(const dynamic_bitset<B, A>& a,
const dynamic_bitset<B, A>& b);
template< typename B, typename A >
friend bool operator==( const dynamic_bitset< B, A > & a, const dynamic_bitset< B, A > & b );
template <typename B, typename A>
friend bool operator<(const dynamic_bitset<B, A>& a,
const dynamic_bitset<B, A>& b);
template< typename B, typename A >
friend bool operator<( const dynamic_bitset< B, A > & a, const dynamic_bitset< B, A > & b );
template <typename B, typename A, typename BlockOutputIterator>
friend void to_block_range(const dynamic_bitset<B, A>& b,
BlockOutputIterator result);
template< typename B, typename A, typename BlockOutputIterator >
friend void to_block_range( const dynamic_bitset< B, A > & b, BlockOutputIterator result );
template <typename BlockIterator, typename B, typename A>
friend void from_block_range(BlockIterator first, BlockIterator last,
dynamic_bitset<B, A>& result);
template< typename BlockIterator, typename B, typename A >
friend void from_block_range( BlockIterator first, BlockIterator last, dynamic_bitset< B, A > & result );
template< typename CharT, typename Traits, typename B, typename A >
friend std::basic_istream< CharT, Traits > & operator>>( std::basic_istream< CharT, Traits > & is, dynamic_bitset< B, A > & b );
template <typename CharT, typename Traits, typename B, typename A>
friend std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is,
dynamic_bitset<B, A>& b);
template <typename B, typename A, typename stringT>
friend void to_string_helper(const dynamic_bitset<B, A> & b, stringT & s, bool dump_all);
template <typename B, typename A>
friend std::size_t hash_value(const dynamic_bitset<B, A>& a);
template< typename B, typename A, typename stringT >
friend void to_string_helper( const dynamic_bitset< B, A > & b, stringT & s, bool dump_all );
template< typename B, typename A >
friend std::size_t hash_value( const dynamic_bitset< B, A > & a );
// forward declaration for optional zero-copy serialization support
class serialize_impl;
friend class serialize_impl;
private:
BOOST_STATIC_CONSTANT(block_width_type, ulong_width = std::numeric_limits<unsigned long>::digits);
BOOST_STATIC_CONSTANT( block_width_type, ulong_width = std::numeric_limits< unsigned long >::digits );
dynamic_bitset& range_operation(size_type pos, size_type len,
Block (*partial_block_operation)(Block, size_type, size_type),
Block (*full_block_operation)(Block));
dynamic_bitset & range_operation( size_type pos, size_type len, Block ( *partial_block_operation )( Block, size_type, size_type ), Block ( *full_block_operation )( Block ) );
void m_zero_unused_bits();
bool m_check_invariants() const;
static bool m_not_empty(Block x);
size_type m_do_find_from(size_type first_block) const;
static bool m_not_empty( Block x );
size_type m_do_find_from( size_type first_block ) const;
block_width_type count_extra_bits() const BOOST_NOEXCEPT;
static size_type block_index(size_type pos) BOOST_NOEXCEPT;
static block_width_type bit_index(size_type pos) BOOST_NOEXCEPT;
static Block bit_mask(size_type pos) BOOST_NOEXCEPT;
static Block bit_mask(size_type first, size_type last) BOOST_NOEXCEPT;
static Block set_block_bits(Block block, size_type first,
size_type last, bool val) BOOST_NOEXCEPT;
static size_type block_index( size_type pos ) BOOST_NOEXCEPT;
static block_width_type bit_index( size_type pos ) BOOST_NOEXCEPT;
static Block bit_mask( size_type pos ) BOOST_NOEXCEPT;
static Block bit_mask( size_type first, size_type last ) BOOST_NOEXCEPT;
static Block set_block_bits( Block block, size_type first, size_type last, bool val ) BOOST_NOEXCEPT;
// Functions for operations on ranges
inline static Block set_block_partial(Block block, size_type first,
size_type last) BOOST_NOEXCEPT;
inline static Block set_block_full(Block) BOOST_NOEXCEPT;
inline static Block reset_block_partial(Block block, size_type first,
size_type last) BOOST_NOEXCEPT;
inline static Block reset_block_full(Block) BOOST_NOEXCEPT;
inline static Block flip_block_partial(Block block, size_type first,
size_type last) BOOST_NOEXCEPT;
inline static Block flip_block_full(Block block) BOOST_NOEXCEPT;
inline static Block set_block_partial( Block block, size_type first, size_type last ) BOOST_NOEXCEPT;
inline static Block set_block_full( Block ) BOOST_NOEXCEPT;
inline static Block reset_block_partial( Block block, size_type first, size_type last ) BOOST_NOEXCEPT;
inline static Block reset_block_full( Block ) BOOST_NOEXCEPT;
inline static Block flip_block_partial( Block block, size_type first, size_type last ) BOOST_NOEXCEPT;
inline static Block flip_block_full( Block block ) BOOST_NOEXCEPT;
template <typename T>
void dispatch_init(T num_bits, unsigned long value,
detail::dynamic_bitset_impl::value_to_type<true>);
template< typename T >
void dispatch_init( T num_bits, unsigned long value, detail::dynamic_bitset_impl::value_to_type< true > );
template <typename T>
void dispatch_init(T first, T last,
detail::dynamic_bitset_impl::value_to_type<false>);
template< typename T >
void dispatch_init( T first, T last, detail::dynamic_bitset_impl::value_to_type< false > );
template <typename BlockIter>
void init_from_block_range(BlockIter first, BlockIter last);
template< typename BlockIter >
void init_from_block_range( BlockIter first, BlockIter last );
template <typename CharT, typename Traits, typename Alloc>
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);
template< typename CharT, typename Traits, typename Alloc >
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*/);
void init_from_unsigned_long( size_type num_bits, unsigned long value /*,
const Allocator& alloc*/
);
template <typename BlockInputIterator>
void m_append(BlockInputIterator first, BlockInputIterator last, std::input_iterator_tag);
template< typename BlockInputIterator >
void m_append( BlockInputIterator first, BlockInputIterator last, std::input_iterator_tag );
template <typename BlockInputIterator>
void m_append(BlockInputIterator first, BlockInputIterator last, std::forward_iterator_tag);
template< typename BlockInputIterator >
void m_append( BlockInputIterator first, BlockInputIterator last, std::forward_iterator_tag );
bool m_unchecked_test(size_type pos) const;
static size_type calc_num_blocks(size_type num_bits);
bool m_unchecked_test( size_type pos ) const;
static size_type calc_num_blocks( size_type num_bits );
Block& m_highest_block();
const Block& m_highest_block() const;
Block & m_highest_block();
const Block & m_highest_block() const;
buffer_type m_bits;
size_type m_num_bits;
class bit_appender;
friend class bit_appender;
class bit_appender {
class bit_appender
{
// helper for stream >>
// Supplies to the lack of an efficient append at the less
// significant end: bits are actually appended "at left" but
@@ -341,107 +308,91 @@ private:
Block * current;
// not implemented
bit_appender(const bit_appender &);
bit_appender & operator=(const bit_appender &);
bit_appender( const bit_appender & );
bit_appender & operator=( const bit_appender & );
public:
bit_appender(dynamic_bitset & r);
bit_appender( dynamic_bitset & r );
~bit_appender();
inline void do_append(bool value);
inline void do_append( bool value );
size_type get_count() const;
};
};
#if !defined BOOST_NO_INCLASS_MEMBER_INITIALIZATION
#if ! defined BOOST_NO_INCLASS_MEMBER_INITIALIZATION
template <typename Block, typename Allocator>
const typename dynamic_bitset<Block, Allocator>::block_width_type
dynamic_bitset<Block, Allocator>::bits_per_block;
template< typename Block, typename Allocator >
const typename dynamic_bitset< Block, Allocator >::block_width_type
dynamic_bitset< Block, Allocator >::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 Allocator >
const typename dynamic_bitset< Block, Allocator >::size_type
dynamic_bitset< Block, Allocator >::npos;
template <typename Block, typename Allocator>
const typename dynamic_bitset<Block, Allocator>::block_width_type
dynamic_bitset<Block, Allocator>::ulong_width;
template< typename Block, typename Allocator >
const typename dynamic_bitset< Block, Allocator >::block_width_type
dynamic_bitset< Block, Allocator >::ulong_width;
#endif
// Global Functions:
// comparison
template <typename Block, typename Allocator>
bool operator!=(const dynamic_bitset<Block, Allocator>& a,
const dynamic_bitset<Block, Allocator>& b);
template< typename Block, typename Allocator >
bool operator!=( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template <typename Block, typename Allocator>
bool operator<=(const dynamic_bitset<Block, Allocator>& a,
const dynamic_bitset<Block, Allocator>& b);
template< typename Block, typename Allocator >
bool operator<=( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template <typename Block, typename Allocator>
bool operator>(const dynamic_bitset<Block, Allocator>& a,
const dynamic_bitset<Block, Allocator>& b);
template< typename Block, typename Allocator >
bool operator>( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
template <typename Block, typename Allocator>
bool operator>=(const dynamic_bitset<Block, Allocator>& a,
const dynamic_bitset<Block, Allocator>& b);
template< typename Block, typename Allocator >
bool operator>=( const dynamic_bitset< Block, Allocator > & a, const dynamic_bitset< Block, Allocator > & b );
// stream operators
template <typename CharT, typename Traits, typename Block, typename Allocator>
std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
const dynamic_bitset<Block, Allocator>& b);
template< typename CharT, typename Traits, typename Block, typename Allocator >
std::basic_ostream< CharT, Traits > &
operator<<( std::basic_ostream< CharT, Traits > & os, const dynamic_bitset< Block, Allocator > & b );
template <typename CharT, typename Traits, typename Block, typename Allocator>
std::basic_istream<CharT, Traits>&
operator>>(std::basic_istream<CharT, Traits>& is,
dynamic_bitset<Block, Allocator>& b);
template< typename CharT, typename Traits, typename Block, typename Allocator >
std::basic_istream< CharT, Traits > &
operator>>( std::basic_istream< CharT, Traits > & is, dynamic_bitset< Block, Allocator > & b );
// bitset operations
template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>
operator&(const dynamic_bitset<Block, Allocator>& b1,
const dynamic_bitset<Block, Allocator>& b2);
template< typename Block, typename Allocator >
dynamic_bitset< Block, Allocator >
operator&( const dynamic_bitset< Block, Allocator > & b1, const dynamic_bitset< Block, Allocator > & b2 );
template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>
operator|(const dynamic_bitset<Block, Allocator>& b1,
const dynamic_bitset<Block, Allocator>& b2);
template< typename Block, typename Allocator >
dynamic_bitset< Block, Allocator >
operator|( const dynamic_bitset< Block, Allocator > & b1, const dynamic_bitset< Block, Allocator > & b2 );
template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>
operator^(const dynamic_bitset<Block, Allocator>& b1,
const dynamic_bitset<Block, Allocator>& b2);
template< typename Block, typename Allocator >
dynamic_bitset< Block, Allocator >
operator^( const dynamic_bitset< Block, Allocator > & b1, const dynamic_bitset< Block, Allocator > & b2 );
template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>
operator-(const dynamic_bitset<Block, Allocator>& b1,
const dynamic_bitset<Block, Allocator>& b2);
template< typename Block, typename Allocator >
dynamic_bitset< Block, Allocator >
operator-( const dynamic_bitset< Block, Allocator > & b1, const dynamic_bitset< Block, Allocator > & b2 );
// namespace scope swap
template<typename Block, typename Allocator>
void swap(dynamic_bitset<Block, Allocator>& b1,
dynamic_bitset<Block, Allocator>& b2) BOOST_NOEXCEPT;
template< typename Block, typename Allocator >
void swap( dynamic_bitset< Block, Allocator > & b1, dynamic_bitset< Block, Allocator > & b2 ) BOOST_NOEXCEPT;
template <typename Block, typename Allocator, typename stringT>
template< typename Block, typename Allocator, typename stringT >
void
to_string(const dynamic_bitset<Block, Allocator>& b, stringT & s);
to_string( const dynamic_bitset< Block, Allocator > & b, stringT & s );
template <typename Block, typename Allocator, typename BlockOutputIterator>
template< typename Block, typename Allocator, typename BlockOutputIterator >
void
to_block_range(const dynamic_bitset<Block, Allocator>& b,
BlockOutputIterator result);
to_block_range( const dynamic_bitset< Block, Allocator > & b, BlockOutputIterator result );
template <typename BlockIterator, typename B, typename A>
template< typename BlockIterator, typename B, typename A >
inline void
from_block_range(BlockIterator first, BlockIterator last,
dynamic_bitset<B, A>& result);
from_block_range( BlockIterator first, BlockIterator last, dynamic_bitset< B, A > & result );
}
#include "impl/dynamic_bitset.tpp"
#endif // include guard

File diff suppressed because it is too large Load Diff

View File

@@ -16,31 +16,34 @@
namespace boost {
// implementation for optional zero-copy serialization support
template <typename Block, typename Allocator>
class dynamic_bitset<Block, Allocator>::serialize_impl
// implementation for optional zero-copy serialization support
template< typename Block, typename Allocator >
class dynamic_bitset< Block, Allocator >::serialize_impl
{
public:
template< typename Ar >
static void
serialize( Ar & ar, dynamic_bitset< Block, Allocator > & bs, unsigned )
{
public:
template <typename Ar>
static void serialize(Ar& ar, dynamic_bitset<Block, Allocator>& bs, unsigned) {
ar & boost::make_nvp("m_num_bits", bs.m_num_bits)
& boost::make_nvp("m_bits", bs.m_bits);
ar & boost::make_nvp( "m_num_bits", bs.m_num_bits )
& boost::make_nvp( "m_bits", bs.m_bits );
}
};
};
}
// ADL hook to Boost Serialization library
namespace boost {
namespace serialization {
namespace serialization {
template <typename Ar, typename Block, typename Allocator>
void serialize(Ar& ar, dynamic_bitset<Block, Allocator>& bs, unsigned version) {
dynamic_bitset<Block, Allocator>::serialize_impl::serialize(ar, bs, version);
}
template< typename Ar, typename Block, typename Allocator >
void
serialize( Ar & ar, dynamic_bitset< Block, Allocator > & bs, unsigned version )
{
dynamic_bitset< Block, Allocator >::serialize_impl::serialize( ar, bs, version );
}
} // namespace serialization
} // namespace serialization
} // namespace boost
#endif // include guard

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -19,101 +19,101 @@
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/limits.hpp"
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#include <cstdlib>
#if ! defined( BOOST_NO_CXX11_ALLOCATOR )
# include <cstdlib>
template<class T>
class minimal_allocator {
template< class T >
class minimal_allocator
{
public:
typedef T value_type;
minimal_allocator() {}
minimal_allocator()
{
}
template <typename U>
minimal_allocator(const minimal_allocator<U>&) {}
template< typename U >
minimal_allocator( const minimal_allocator< U > & )
{
}
T* allocate(std::size_t n) {
void* p = std::malloc(sizeof(T) * n);
if (!p) {
T *
allocate( std::size_t n )
{
void * p = std::malloc( sizeof( T ) * n );
if ( ! p ) {
throw std::bad_alloc();
}
return static_cast<T*>(p);
return static_cast< T * >( p );
}
void deallocate(T* p, std::size_t) {
std::free(p);
void
deallocate( T * p, std::size_t )
{
std::free( p );
}
};
#endif
#define BOOST_BITSET_TEST_COUNT(x) (sizeof(x)/sizeof(x[0]))
#define BOOST_BITSET_TEST_COUNT( x ) ( sizeof( x ) / sizeof( x[ 0 ] ) )
// Codewarrior 8.3 for Win fails without this.
// Thanks Howard Hinnant ;)
#if defined __MWERKS__ && BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
#if defined __MWERKS__ && BOOST_WORKAROUND( __MWERKS__, <= 0x3003 ) // 8.x
# pragma parse_func_templ off
#endif
template <typename Tests, typename String>
void run_string_tests(const String& s
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tests)
)
template< typename Tests, typename String >
void
run_string_tests( const String & s BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE( Tests ) )
{
const std::size_t len = s.length();
const std::size_t step = len/4 ? len/4 : 1;
const std::size_t step = len / 4 ? len / 4 : 1;
// bitset length determined by the string-related arguments
std::size_t i;
for (i = 0; i <= len/2 ; i += step) {
Tests::from_string(s, i, len/2); // len/2 - i bits
Tests::from_string(s, i, len); // len - i bits
Tests::from_string(s, i, 1 + len*2); // len - i bits
for ( i = 0; i <= len / 2; i += step ) {
Tests::from_string( s, i, len / 2 ); // len/2 - i bits
Tests::from_string( s, i, len ); // len - i bits
Tests::from_string( s, i, 1 + len * 2 ); // len - i bits
}
// bitset length explicitly specified
for (i = 0; i <= len/2; i += step) {
for (std::size_t sz = 0; sz <= len*4; sz+= step*2) {
Tests::from_string(s, i, len/2, sz);
Tests::from_string(s, i, len, sz);
Tests::from_string(s, i, 1 + len*2, sz);
for ( i = 0; i <= len / 2; i += step ) {
for ( std::size_t sz = 0; sz <= len * 4; sz += step * 2 ) {
Tests::from_string( s, i, len / 2, sz );
Tests::from_string( s, i, len, sz );
Tests::from_string( s, i, 1 + len * 2, sz );
}
}
}
// tests the do-the-right-thing constructor dispatch
template <typename Tests, typename T>
void run_numeric_ctor_tests( BOOST_EXPLICIT_TEMPLATE_TYPE(Tests)
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T) )
template< typename Tests, typename T >
void
run_numeric_ctor_tests( BOOST_EXPLICIT_TEMPLATE_TYPE( Tests )
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE( T ) )
{
const int bits_per_block = Tests::bits_per_block;
const int width = std::numeric_limits<T>::digits;
const T ma = (std::numeric_limits<T>::max)();
const T mi = (std::numeric_limits<T>::min)();
const int width = std::numeric_limits< T >::digits;
const T ma = ( std::numeric_limits< T >::max )();
const T mi = ( std::numeric_limits< T >::min )();
int sizes[] = {
0, 7*width/10, width, 13*width/10, 3*width,
7*bits_per_block/10, bits_per_block, 13*bits_per_block/10, 3*bits_per_block
0, 7 * width / 10, width, 13 * width / 10, 3 * width, 7 * bits_per_block / 10, bits_per_block, 13 * bits_per_block / 10, 3 * bits_per_block
};
const T numbers[] = {
T(-1), T(-3), T(-8), T(-15), T(mi/2), T(mi),
T(0), T(1), T(3), T(8), T(15), T(ma/2), T(ma)
T( -1 ), T( -3 ), T( -8 ), T( -15 ), T( mi / 2 ), T( mi ), T( 0 ), T( 1 ), T( 3 ), T( 8 ), T( 15 ), T( ma / 2 ), T( ma )
};
for (std::size_t s = 0; s < BOOST_BITSET_TEST_COUNT(sizes); ++s) {
for (std::size_t n = 0; n < BOOST_BITSET_TEST_COUNT(numbers); ++n ) {
for ( std::size_t s = 0; s < BOOST_BITSET_TEST_COUNT( sizes ); ++s ) {
for ( std::size_t n = 0; n < BOOST_BITSET_TEST_COUNT( numbers ); ++n ) {
// can match ctor from ulong or templated one
Tests::from_unsigned_long(sizes[s], numbers[n]);
Tests::from_unsigned_long( sizes[ s ], numbers[ n ] );
typedef std::size_t compare_type;
const compare_type sz = sizes[s];
const compare_type sz = sizes[ s ];
// this condition is to be sure that size is representable in T, so
// that for signed T's we avoid implementation-defined behavior [if ma
// is larger than what std::size_t can hold then this is ok for our
@@ -122,28 +122,26 @@ void run_numeric_ctor_tests( BOOST_EXPLICIT_TEMPLATE_TYPE(Tests)
// later converted to a very large unsigned. Example: signed 8-bit
// char (CHAR_MAX=127), bits_per_block=64, sz = 192 > 127.
const bool fits =
sz <= static_cast<compare_type>(ma);
sz <= static_cast< compare_type >( ma );
if (fits) {
if ( fits ) {
// can match templated ctor only (so we test dispatching)
Tests::from_unsigned_long(static_cast<T>(sizes[s]), numbers[n]);
}
Tests::from_unsigned_long( static_cast< T >( sizes[ s ] ), numbers[ n ] );
}
}
}
}
template <typename Block>
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
template< typename Block >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
typedef boost::dynamic_bitset<Block> bitset_type;
typedef bitset_test<bitset_type> Tests;
typedef boost::dynamic_bitset< Block > bitset_type;
typedef bitset_test< bitset_type > Tests;
const int bits_per_block = bitset_type::bits_per_block;
const std::string long_string = get_long_string();
const Block all_1s = static_cast<Block>(-1);
const Block all_1s = static_cast< Block >( -1 );
//=====================================================================
// Test construction from unsigned long
@@ -157,388 +155,383 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
// which is likely to work on broken compilers
//
const int sizes[] = {
0, 1, 3,
7*bits_per_block/10, bits_per_block, 13*bits_per_block/10, 3*bits_per_block
0, 1, 3, 7 * bits_per_block / 10, bits_per_block, 13 * bits_per_block / 10, 3 * bits_per_block
};
const bool values[] = { false, true };
for (std::size_t s = 0; s < BOOST_BITSET_TEST_COUNT(sizes); ++s) {
for (std::size_t v = 0; v < BOOST_BITSET_TEST_COUNT(values); ++v) {
Tests::from_unsigned_long(sizes[s], values[v]);
Tests::from_unsigned_long(sizes[s] != 0, values[v]);
for ( std::size_t s = 0; s < BOOST_BITSET_TEST_COUNT( sizes ); ++s ) {
for ( std::size_t v = 0; v < BOOST_BITSET_TEST_COUNT( values ); ++v ) {
Tests::from_unsigned_long( sizes[ s ], values[ v ] );
Tests::from_unsigned_long( sizes[ s ] != 0, values[ v ] );
}
}
run_numeric_ctor_tests<Tests, char>();
run_numeric_ctor_tests< Tests, char >();
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
run_numeric_ctor_tests<Tests, wchar_t>();
#if ! defined( BOOST_NO_INTRINSIC_WCHAR_T )
run_numeric_ctor_tests< Tests, wchar_t >();
#endif
run_numeric_ctor_tests<Tests, signed char>();
run_numeric_ctor_tests<Tests, short int>();
run_numeric_ctor_tests<Tests, int>();
run_numeric_ctor_tests<Tests, long int>();
run_numeric_ctor_tests< Tests, signed char >();
run_numeric_ctor_tests< Tests, short int >();
run_numeric_ctor_tests< Tests, int >();
run_numeric_ctor_tests< Tests, long int >();
run_numeric_ctor_tests<Tests, unsigned char>();
run_numeric_ctor_tests<Tests, unsigned short>();
run_numeric_ctor_tests<Tests, unsigned int>();
run_numeric_ctor_tests<Tests, unsigned long>();
run_numeric_ctor_tests< Tests, unsigned char >();
run_numeric_ctor_tests< Tests, unsigned short >();
run_numeric_ctor_tests< Tests, unsigned int >();
run_numeric_ctor_tests< Tests, unsigned long >();
#if defined(BOOST_HAS_LONG_LONG)
run_numeric_ctor_tests<Tests, ::boost::long_long_type>();
run_numeric_ctor_tests<Tests, ::boost::ulong_long_type>();
#if defined( BOOST_HAS_LONG_LONG )
run_numeric_ctor_tests< Tests, ::boost::long_long_type >();
run_numeric_ctor_tests< Tests, ::boost::ulong_long_type >();
#endif
}
//=====================================================================
// Test construction from a string
{
run_string_tests< Tests >( std::string( "" ) ); // empty string
run_string_tests< Tests >( std::string( "1" ) );
run_string_tests<Tests>(std::string("")); // empty string
run_string_tests<Tests>(std::string("1"));
run_string_tests< Tests >( long_string );
run_string_tests<Tests>(long_string);
# if !defined BOOST_NO_STD_WSTRING
#if ! defined BOOST_NO_STD_WSTRING
// I need to decide what to do for non "C" locales here. On
// one hand I should have better tests. On the other one
// I don't want tests for dynamic_bitset to cope with locales,
// ctype::widen, etc. (but that's what you deserve when you
// don't separate concerns at the library level)
//
run_string_tests<Tests>(
std::wstring(L"11111000000111111111010101010101010101010111111"));
# endif
run_string_tests< Tests >(
std::wstring( L"11111000000111111111010101010101010101010111111" ) );
#endif
// Note that these are _valid_ arguments
Tests::from_string(std::string("x11y"), 1, 2);
Tests::from_string(std::string("x11"), 1, 10);
Tests::from_string(std::string("x11"), 1, 10, 10);
Tests::from_string( std::string( "x11y" ), 1, 2 );
Tests::from_string( std::string( "x11" ), 1, 10 );
Tests::from_string( std::string( "x11" ), 1, 10, 10 );
}
//=====================================================================
// test from_block_range
{
std::vector<Block> blocks;
Tests::from_block_range(blocks);
std::vector< Block > blocks;
Tests::from_block_range( blocks );
}
{
std::vector<Block> blocks(3);
blocks[0] = static_cast<Block>(0);
blocks[1] = static_cast<Block>(1);
blocks[2] = all_1s;
Tests::from_block_range(blocks);
std::vector< Block > blocks( 3 );
blocks[ 0 ] = static_cast< Block >( 0 );
blocks[ 1 ] = static_cast< Block >( 1 );
blocks[ 2 ] = all_1s;
Tests::from_block_range( blocks );
}
{
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::from_block_range(blocks);
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::from_block_range( blocks );
}
//=====================================================================
// test to_block_range
{
bitset_type b;
Tests::to_block_range(b);
Tests::to_block_range( b );
}
{
bitset_type b(1, 1ul);
Tests::to_block_range(b);
bitset_type b( 1, 1ul );
Tests::to_block_range( b );
}
{
bitset_type b(long_string);
Tests::to_block_range(b);
bitset_type b( long_string );
Tests::to_block_range( b );
}
//=====================================================================
// Test copy constructor
{
boost::dynamic_bitset<Block> b;
Tests::copy_constructor(b);
boost::dynamic_bitset< Block > b;
Tests::copy_constructor( b );
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::copy_constructor(b);
boost::dynamic_bitset< Block > b( std::string( "0" ) );
Tests::copy_constructor( b );
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::copy_constructor(b);
boost::dynamic_bitset< Block > b( long_string );
Tests::copy_constructor( b );
}
//=====================================================================
// Test copy assignment operator
{
bitset_type a, b;
Tests::copy_assignment_operator(a, b);
Tests::copy_assignment_operator( a, b );
}
{
bitset_type a(std::string("1")), b(std::string("0"));
Tests::copy_assignment_operator(a, b);
bitset_type a( std::string( "1" ) ), b( std::string( "0" ) );
Tests::copy_assignment_operator( a, b );
}
{
bitset_type a(long_string), b(long_string);
Tests::copy_assignment_operator(a, b);
bitset_type a( long_string ), b( long_string );
Tests::copy_assignment_operator( a, b );
}
{
bitset_type a;
bitset_type b(long_string); // b greater than a, a empty
Tests::copy_assignment_operator(a, b);
bitset_type b( long_string ); // b greater than a, a empty
Tests::copy_assignment_operator( a, b );
}
{
bitset_type a(std::string("0"));
bitset_type b(long_string); // b greater than a
Tests::copy_assignment_operator(a, b);
bitset_type a( std::string( "0" ) );
bitset_type b( long_string ); // b greater than a
Tests::copy_assignment_operator( a, b );
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
//=====================================================================
// Test move constructor
{
boost::dynamic_bitset<Block> b;
Tests::move_constructor(b);
boost::dynamic_bitset< Block > b;
Tests::move_constructor( b );
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::move_constructor(b);
boost::dynamic_bitset< Block > b( std::string( "0" ) );
Tests::move_constructor( b );
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::move_constructor(b);
boost::dynamic_bitset< Block > b( long_string );
Tests::move_constructor( b );
}
//=====================================================================
// Test move assignment operator
{
bitset_type a, b;
Tests::move_assignment_operator(a, b);
Tests::move_assignment_operator( a, b );
}
{
bitset_type a(std::string("1")), b(std::string("0"));
Tests::move_assignment_operator(a, b);
bitset_type a( std::string( "1" ) ), b( std::string( "0" ) );
Tests::move_assignment_operator( a, b );
}
{
bitset_type a(long_string), b(long_string);
Tests::move_assignment_operator(a, b);
bitset_type a( long_string ), b( long_string );
Tests::move_assignment_operator( a, b );
}
{
bitset_type a;
bitset_type b(long_string); // b greater than a, a empty
Tests::move_assignment_operator(a, b);
bitset_type b( long_string ); // b greater than a, a empty
Tests::move_assignment_operator( a, b );
}
{
bitset_type a(std::string("0"));
bitset_type b(long_string); // b greater than a
Tests::move_assignment_operator(a, b);
bitset_type a( std::string( "0" ) );
bitset_type b( long_string ); // b greater than a
Tests::move_assignment_operator( a, b );
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
//=====================================================================
// Test swap
{
bitset_type a;
bitset_type b(std::string("1"));
Tests::swap(a, b);
Tests::swap(b, a);
Tests::swap(a, a);
bitset_type b( std::string( "1" ) );
Tests::swap( a, b );
Tests::swap( b, a );
Tests::swap( a, a );
}
{
bitset_type a;
bitset_type b(long_string);
Tests::swap(a, b);
Tests::swap(b, a);
bitset_type b( long_string );
Tests::swap( a, b );
Tests::swap( b, a );
}
{
bitset_type a(std::string("0"));
bitset_type b(long_string);
Tests::swap(a, b);
Tests::swap(b, a);
Tests::swap(a, a);
Tests::swap(b, b);
bitset_type a( std::string( "0" ) );
bitset_type b( long_string );
Tests::swap( a, b );
Tests::swap( b, a );
Tests::swap( a, a );
Tests::swap( b, b );
}
//=====================================================================
// Test resize
{
boost::dynamic_bitset<Block> a;
Tests::resize(a);
boost::dynamic_bitset< Block > a;
Tests::resize( a );
}
{
boost::dynamic_bitset<Block> a(std::string("0"));
Tests::resize(a);
boost::dynamic_bitset< Block > a( std::string( "0" ) );
Tests::resize( a );
}
{
boost::dynamic_bitset<Block> a(std::string("1"));
Tests::resize(a);
boost::dynamic_bitset< Block > a( std::string( "1" ) );
Tests::resize( a );
}
{
boost::dynamic_bitset<Block> a(long_string);
Tests::resize(a);
boost::dynamic_bitset< Block > a( long_string );
Tests::resize( a );
}
//=====================================================================
// Test clear
{
boost::dynamic_bitset<Block> a;
Tests::clear(a);
boost::dynamic_bitset< Block > a;
Tests::clear( a );
}
{
boost::dynamic_bitset<Block> a(long_string);
Tests::clear(a);
boost::dynamic_bitset< Block > a( long_string );
Tests::clear( a );
}
//=====================================================================
// Test pop back
{
boost::dynamic_bitset<Block> a(std::string("01"));
Tests::pop_back(a);
boost::dynamic_bitset< Block > a( std::string( "01" ) );
Tests::pop_back( a );
}
{
boost::dynamic_bitset<Block> a(std::string("10"));
Tests::pop_back(a);
boost::dynamic_bitset< Block > 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);
Tests::pop_back(a);
boost::dynamic_bitset< Block > a( size_to_fill_all_blocks, 255ul );
Tests::pop_back( a );
}
{
boost::dynamic_bitset<Block> a(long_string);
Tests::pop_back(a);
boost::dynamic_bitset< Block > a( long_string );
Tests::pop_back( a );
}
//=====================================================================
// Test append bit
{
boost::dynamic_bitset<Block> a;
Tests::append_bit(a);
boost::dynamic_bitset< Block > a;
Tests::append_bit( a );
}
{
boost::dynamic_bitset<Block> a(std::string("0"));
Tests::append_bit(a);
boost::dynamic_bitset< Block > a( std::string( "0" ) );
Tests::append_bit( a );
}
{
boost::dynamic_bitset<Block> a(std::string("1"));
Tests::append_bit(a);
boost::dynamic_bitset< Block > 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);
Tests::append_bit(a);
boost::dynamic_bitset< Block > a( size_to_fill_all_blocks, 255ul );
Tests::append_bit( a );
}
{
boost::dynamic_bitset<Block> a(long_string);
Tests::append_bit(a);
boost::dynamic_bitset< Block > a( long_string );
Tests::append_bit( a );
}
//=====================================================================
// Test append block
{
boost::dynamic_bitset<Block> a;
Tests::append_block(a);
boost::dynamic_bitset< Block > a;
Tests::append_block( a );
}
{
boost::dynamic_bitset<Block> a(std::string("0"));
Tests::append_block(a);
boost::dynamic_bitset< Block > a( std::string( "0" ) );
Tests::append_block( a );
}
{
boost::dynamic_bitset<Block> a(std::string("1"));
Tests::append_block(a);
boost::dynamic_bitset< Block > 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);
Tests::append_block(a);
boost::dynamic_bitset< Block > a( size_to_fill_all_blocks, 15ul );
Tests::append_block( a );
}
{
boost::dynamic_bitset<Block> a(long_string);
Tests::append_block(a);
boost::dynamic_bitset< Block > a( long_string );
Tests::append_block( a );
}
//=====================================================================
// Test append block range
{
boost::dynamic_bitset<Block> a;
std::vector<Block> blocks;
Tests::append_block_range(a, blocks);
boost::dynamic_bitset< Block > a;
std::vector< Block > blocks;
Tests::append_block_range( a, blocks );
}
{
boost::dynamic_bitset<Block> 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( "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);
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( 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;
a.append(Block(1));
a.append(Block(2));
Block x[] = {3, 4, 5};
std::size_t sz = sizeof(x) / sizeof(x[0]);
std::vector<Block> blocks(x, x + sz);
Tests::append_block_range(a, blocks);
boost::dynamic_bitset< Block > a;
a.append( Block( 1 ) );
a.append( Block( 2 ) );
Block x[] = { 3, 4, 5 };
std::size_t sz = sizeof( x ) / sizeof( x[ 0 ] );
std::vector< Block > blocks( x, x + sz );
Tests::append_block_range( a, blocks );
}
{
boost::dynamic_bitset<Block> a(long_string);
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( long_string );
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 );
}
//=====================================================================
// Test bracket operator
{
boost::dynamic_bitset<Block> b1;
std::vector<bool> bitvec1;
Tests::operator_bracket(b1, bitvec1);
boost::dynamic_bitset< Block > 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);
Tests::operator_bracket(b, bit_vec);
boost::dynamic_bitset< Block > b( std::string( "1" ) );
std::vector< bool > bit_vec( 1, true );
Tests::operator_bracket( b, bit_vec );
}
{
boost::dynamic_bitset<Block> b(long_string);
boost::dynamic_bitset< Block > 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);
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 );
}
//=====================================================================
// Test at
{
boost::dynamic_bitset<Block> b1;
std::vector<bool> bitvec1;
Tests::at(b1, bitvec1);
boost::dynamic_bitset< Block > b1;
std::vector< bool > bitvec1;
Tests::at( b1, bitvec1 );
}
{
boost::dynamic_bitset<Block> b(std::string("1"));
std::vector<bool> bit_vec(1, true);
Tests::at(b, bit_vec);
boost::dynamic_bitset< Block > b( std::string( "1" ) );
std::vector< bool > bit_vec( 1, true );
Tests::at( b, bit_vec );
}
{
boost::dynamic_bitset<Block> b(long_string);
boost::dynamic_bitset< Block > 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);
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 );
}
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#if ! defined( BOOST_NO_CXX11_ALLOCATOR )
{
typedef boost::dynamic_bitset<Block,
minimal_allocator<Block> > Bitset;
typedef boost::dynamic_bitset< Block, minimal_allocator< Block > > Bitset;
Bitset b;
bitset_test<Bitset>::max_size(b);
bitset_test< Bitset >::max_size( b );
}
#endif
// Test copy-initialize with default constructor
{
boost::dynamic_bitset<Block> b[1] = {};
boost::dynamic_bitset< Block > b[ 1 ] = {};
(void)b;
}
}
@@ -546,13 +539,13 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
int
main()
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
run_test_cases<unsigned int>();
run_test_cases<unsigned long>();
# ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type>();
# endif
run_test_cases< unsigned char >();
run_test_cases< unsigned short >();
run_test_cases< unsigned int >();
run_test_cases< unsigned long >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::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>
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
template< typename Block >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
typedef boost::dynamic_bitset<Block> bitset_type;
typedef boost::dynamic_bitset< Block > bitset_type;
typedef bitset_test< bitset_type > Tests;
const int bits_per_block = bitset_type::bits_per_block;
@@ -27,357 +27,352 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
//=====================================================================
// Test operator&=
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::and_assignment(lhs, rhs);
boost::dynamic_bitset< Block > lhs, rhs;
Tests::and_assignment( lhs, rhs );
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::and_assignment(lhs, rhs);
boost::dynamic_bitset< Block > 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);
Tests::and_assignment(lhs, rhs);
boost::dynamic_bitset< Block > 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);
Tests::and_assignment(lhs, rhs);
boost::dynamic_bitset< Block > lhs( long_string.size(), 1 ), rhs( long_string );
Tests::and_assignment( lhs, rhs );
}
//=====================================================================
// Test operator |=
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::or_assignment(lhs, rhs);
boost::dynamic_bitset< Block > lhs, rhs;
Tests::or_assignment( lhs, rhs );
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::or_assignment(lhs, rhs);
boost::dynamic_bitset< Block > 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);
Tests::or_assignment(lhs, rhs);
boost::dynamic_bitset< Block > 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);
Tests::or_assignment(lhs, rhs);
boost::dynamic_bitset< Block > lhs( long_string.size(), 1 ), rhs( long_string );
Tests::or_assignment( lhs, rhs );
}
//=====================================================================
// Test operator^=
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::xor_assignment(lhs, rhs);
boost::dynamic_bitset< Block > lhs, rhs;
Tests::xor_assignment( lhs, rhs );
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::xor_assignment(lhs, rhs);
boost::dynamic_bitset< Block > 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"));
Tests::xor_assignment(lhs, rhs);
boost::dynamic_bitset< Block > lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
Tests::xor_assignment( lhs, rhs );
}
{
boost::dynamic_bitset<Block> lhs(long_string), rhs(long_string);
Tests::xor_assignment(lhs, rhs);
boost::dynamic_bitset< Block > lhs( long_string ), rhs( long_string );
Tests::xor_assignment( lhs, rhs );
}
//=====================================================================
// Test operator-=
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::sub_assignment(lhs, rhs);
boost::dynamic_bitset< Block > lhs, rhs;
Tests::sub_assignment( lhs, rhs );
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::sub_assignment(lhs, rhs);
boost::dynamic_bitset< Block > 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"));
Tests::sub_assignment(lhs, rhs);
boost::dynamic_bitset< Block > lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
Tests::sub_assignment( lhs, rhs );
}
{
boost::dynamic_bitset<Block> lhs(long_string), rhs(long_string);
Tests::sub_assignment(lhs, rhs);
boost::dynamic_bitset< Block > lhs( long_string ), rhs( long_string );
Tests::sub_assignment( lhs, rhs );
}
//=====================================================================
// Test operator<<=
{ // case pos == 0
std::size_t pos = 0;
{
boost::dynamic_bitset<Block> b;
Tests::shift_left_assignment(b, pos);
boost::dynamic_bitset< Block > b;
Tests::shift_left_assignment( b, pos );
}
{
boost::dynamic_bitset<Block> b(std::string("1010"));
Tests::shift_left_assignment(b, pos);
boost::dynamic_bitset< Block > b( std::string( "1010" ) );
Tests::shift_left_assignment( b, pos );
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_left_assignment(b, pos);
boost::dynamic_bitset< Block > b( long_string );
Tests::shift_left_assignment( b, pos );
}
}
{
// test with both multiple and
// non multiple of bits_per_block
const int how_many = 10;
for (int i = 1; i <= how_many; ++i) {
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);
boost::dynamic_bitset< Block > b( long_string );
Tests::shift_left_assignment(b, multiple);
Tests::shift_left_assignment(b, non_multiple);
Tests::shift_left_assignment( b, multiple );
Tests::shift_left_assignment( b, non_multiple );
}
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_left_assignment(b, pos);
boost::dynamic_bitset< Block > 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);
Tests::shift_left_assignment(b, pos);
boost::dynamic_bitset< Block > b( long_string );
Tests::shift_left_assignment( b, pos );
}
//=====================================================================
// Test operator>>=
{ // case pos == 0
std::size_t pos = 0;
{
boost::dynamic_bitset<Block> b;
Tests::shift_right_assignment(b, pos);
boost::dynamic_bitset< Block > b;
Tests::shift_right_assignment( b, pos );
}
{
boost::dynamic_bitset<Block> b(std::string("1010"));
Tests::shift_right_assignment(b, pos);
boost::dynamic_bitset< Block > b( std::string( "1010" ) );
Tests::shift_right_assignment( b, pos );
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_right_assignment(b, pos);
boost::dynamic_bitset< Block > b( long_string );
Tests::shift_right_assignment( b, pos );
}
}
{
// test with both multiple and
// non multiple of bits_per_block
const int how_many = 10;
for (int i = 1; i <= how_many; ++i) {
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);
boost::dynamic_bitset< Block > b( long_string );
Tests::shift_right_assignment(b, multiple);
Tests::shift_right_assignment(b, non_multiple);
Tests::shift_right_assignment( b, multiple );
Tests::shift_right_assignment( b, non_multiple );
}
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_right_assignment(b, pos);
boost::dynamic_bitset< Block > 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);
Tests::shift_right_assignment(b, pos);
boost::dynamic_bitset< Block > b( long_string );
Tests::shift_right_assignment( b, pos );
}
//=====================================================================
// test b.set()
{
boost::dynamic_bitset<Block> b;
Tests::set_all(b);
boost::dynamic_bitset< Block > b;
Tests::set_all( b );
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::set_all(b);
boost::dynamic_bitset< Block > b( std::string( "0" ) );
Tests::set_all( b );
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::set_all(b);
boost::dynamic_bitset< Block > b( long_string );
Tests::set_all( b );
}
//=====================================================================
// Test b.set(pos)
{ // case pos >= b.size()
boost::dynamic_bitset<Block> b;
Tests::set_one(b, 0, true);
Tests::set_one(b, 0, false);
boost::dynamic_bitset< Block > 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"));
Tests::set_one(b, 0, true);
Tests::set_one(b, 0, false);
boost::dynamic_bitset< Block > 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);
Tests::set_one(b, long_string.size()/2, true);
Tests::set_one(b, long_string.size()/2, false);
boost::dynamic_bitset< Block > 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"));
Tests::set_segment(b, 0, 1, true);
Tests::set_segment(b, 0, 1, false);
boost::dynamic_bitset< Block > 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);
Tests::set_segment(b, 0, b.size(), true);
Tests::set_segment(b, 0, b.size(), false);
boost::dynamic_bitset< Block > 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);
Tests::set_segment(b, b.size() / 4, b.size() / 2, true);
Tests::set_segment(b, b.size() / 4, b.size() / 2, false);
boost::dynamic_bitset< Block > 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);
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 );
}
{ // case pos = 1, len = size - 2
boost::dynamic_bitset<Block> b(long_string);
Tests::set_segment(b, 1, b.size() - 2, true);
Tests::set_segment(b, 1, b.size() - 2, false);
boost::dynamic_bitset< Block > 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);
Tests::set_segment(b, 3, 7, true);
Tests::set_segment(b, 3, 7, false);
boost::dynamic_bitset< Block > 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;
Tests::reset_all(b);
boost::dynamic_bitset< Block > b;
Tests::reset_all( b );
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::reset_all(b);
boost::dynamic_bitset< Block > b( std::string( "0" ) );
Tests::reset_all( b );
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::reset_all(b);
boost::dynamic_bitset< Block > b( long_string );
Tests::reset_all( b );
}
//=====================================================================
// Test b.reset(pos)
{ // case pos >= b.size()
boost::dynamic_bitset<Block> b;
Tests::reset_one(b, 0);
boost::dynamic_bitset< Block > b;
Tests::reset_one( b, 0 );
}
{ // case pos < b.size()
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::reset_one(b, 0);
boost::dynamic_bitset< Block > b( std::string( "0" ) );
Tests::reset_one( b, 0 );
}
{ // case pos == b.size() / 2
boost::dynamic_bitset<Block> b(long_string);
Tests::reset_one(b, long_string.size()/2);
boost::dynamic_bitset< Block > 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"));
Tests::reset_segment(b, 0, 1);
boost::dynamic_bitset< Block > b( std::string( "0" ) );
Tests::reset_segment( b, 0, 1 );
}
{ // case fill the whole set
boost::dynamic_bitset<Block> b(long_string);
Tests::reset_segment(b, 0, b.size());
boost::dynamic_bitset< Block > b( long_string );
Tests::reset_segment( b, 0, b.size() );
}
{ // case pos = size / 4, len = size / 2
boost::dynamic_bitset<Block> b(long_string);
Tests::reset_segment(b, b.size() / 4, b.size() / 2);
boost::dynamic_bitset< Block > 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);
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 );
}
{ // case pos = 1, len = size - 2
boost::dynamic_bitset<Block> b(long_string);
Tests::reset_segment(b, 1, b.size() - 2);
boost::dynamic_bitset< Block > b( long_string );
Tests::reset_segment( b, 1, b.size() - 2 );
}
{ // case pos = 3, len = 7
boost::dynamic_bitset<Block> b(long_string);
Tests::reset_segment(b, 3, 7);
boost::dynamic_bitset< Block > b( long_string );
Tests::reset_segment( b, 3, 7 );
}
//=====================================================================
// Test ~b
{
boost::dynamic_bitset<Block> b;
Tests::operator_flip(b);
boost::dynamic_bitset< Block > b;
Tests::operator_flip( b );
}
{
boost::dynamic_bitset<Block> b(std::string("1"));
Tests::operator_flip(b);
boost::dynamic_bitset< Block > b( std::string( "1" ) );
Tests::operator_flip( b );
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::operator_flip(b);
boost::dynamic_bitset< Block > b( long_string );
Tests::operator_flip( b );
}
//=====================================================================
// Test b.flip()
{
boost::dynamic_bitset<Block> b;
Tests::flip_all(b);
boost::dynamic_bitset< Block > b;
Tests::flip_all( b );
}
{
boost::dynamic_bitset<Block> b(std::string("1"));
Tests::flip_all(b);
boost::dynamic_bitset< Block > b( std::string( "1" ) );
Tests::flip_all( b );
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::flip_all(b);
boost::dynamic_bitset< Block > b( long_string );
Tests::flip_all( b );
}
//=====================================================================
// Test b.flip(pos)
{ // case pos >= b.size()
boost::dynamic_bitset<Block> b;
Tests::flip_one(b, 0);
boost::dynamic_bitset< Block > b;
Tests::flip_one( b, 0 );
}
{ // case pos < b.size()
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::flip_one(b, 0);
boost::dynamic_bitset< Block > b( std::string( "0" ) );
Tests::flip_one( b, 0 );
}
{ // case pos == b.size() / 2
boost::dynamic_bitset<Block> b(long_string);
Tests::flip_one(b, long_string.size()/2);
boost::dynamic_bitset< Block > 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"));
Tests::flip_segment(b, 0, 1);
boost::dynamic_bitset< Block > b( std::string( "0" ) );
Tests::flip_segment( b, 0, 1 );
}
{ // case fill the whole set
boost::dynamic_bitset<Block> b(long_string);
Tests::flip_segment(b, 0, b.size());
boost::dynamic_bitset< Block > b( long_string );
Tests::flip_segment( b, 0, b.size() );
}
{ // case pos = size / 4, len = size / 2
boost::dynamic_bitset<Block> b(long_string);
Tests::flip_segment(b, b.size() / 4, b.size() / 2);
boost::dynamic_bitset< Block > 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);
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 );
}
{ // case pos = 1, len = size - 2
boost::dynamic_bitset<Block> b(long_string);
Tests::flip_segment(b, 1, b.size() - 2);
boost::dynamic_bitset< Block > b( long_string );
Tests::flip_segment( b, 1, b.size() - 2 );
}
{ // case pos = 3, len = 7
boost::dynamic_bitset<Block> b(long_string);
Tests::flip_segment(b, 3, 7);
boost::dynamic_bitset< Block > b( long_string );
Tests::flip_segment( b, 3, 7 );
}
}
int
main()
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
run_test_cases<unsigned int>();
run_test_cases<unsigned long>();
# ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type>();
# endif
run_test_cases< unsigned char >();
run_test_cases< unsigned short >();
run_test_cases< unsigned int >();
run_test_cases< unsigned long >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type >();
#endif
return boost::report_errors();
}

File diff suppressed because it is too large Load Diff

View File

@@ -12,54 +12,49 @@
#include "boost/config.hpp"
#include "boost/config/workaround.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include <assert.h>
#include <cstddef>
#include <fstream>
#include <stdexcept>
#include <string>
#if !defined (BOOST_NO_STRINGSTREAM)
#if ! defined( BOOST_NO_STRINGSTREAM )
# include <sstream>
#endif
#if defined BOOST_NO_STD_WSTRING || defined BOOST_NO_STD_LOCALE
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
#endif
#if !defined BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
std::wstring widen_string( const std::string & str,
const std::locale & loc = std::locale() )
#if ! defined BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
std::wstring
widen_string( const std::string & str, const std::locale & loc = std::locale() )
{
std::wstring result;
const std::string::size_type len = str.length();
if(len != 0) {
typedef std::ctype<wchar_t> ct_type;
if ( len != 0 ) {
typedef std::ctype< wchar_t > ct_type;
typedef std::wstring::traits_type tr_type;
const ct_type & ct = BOOST_USE_FACET(ct_type, loc);
result.resize(len);
for (std::size_t i = 0; i < len; ++i)
tr_type::assign(result[i], ct.widen(str[i]));
const ct_type & ct = BOOST_USE_FACET( ct_type, loc );
result.resize( len );
for ( std::size_t i = 0; i < len; ++i )
tr_type::assign( result[ i ], ct.widen( str[ i ] ) );
}
return result;
}
#endif
template <typename Block>
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
template< typename Block >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
typedef boost::dynamic_bitset<Block> bitset_type;
typedef bitset_test<bitset_type> Tests;
typedef boost::dynamic_bitset< Block > bitset_type;
typedef bitset_test< bitset_type > Tests;
//=====================================================================
// Test stream operator<<
{
// The test "variables" are: the stream type and its state, the
// exception mask, the width, the fill char and the padding side (left/right)
@@ -71,87 +66,83 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
};
static std::string strings[] = {
std::string(""),
std::string("0"),
std::string("1"),
std::string("11100"),
std::string( "" ),
std::string( "0" ),
std::string( "1" ),
std::string( "11100" ),
get_long_string()
};
char fill_chars[] = { '*', 'x', ' ' };
std::size_t num_masks = sizeof(masks) / sizeof(masks[0]);
std::size_t num_strings = sizeof(strings) / sizeof(strings[0]);
std::size_t num_chars = sizeof(fill_chars) / sizeof(fill_chars[0]);
std::size_t num_masks = sizeof( masks ) / sizeof( masks[ 0 ] );
std::size_t num_strings = sizeof( strings ) / sizeof( strings[ 0 ] );
std::size_t num_chars = sizeof( fill_chars ) / sizeof( fill_chars[ 0 ] );
std::fstream not_good_stream("dynamic_bitset_tests - this file shouldn't exist",
std::ios::in);
std::fstream not_good_stream( "dynamic_bitset_tests - this file shouldn't exist", std::ios::in );
for ( std::size_t mi = 0; mi < num_masks; ++mi ) {
for ( std::size_t si = 0; si < num_strings; ++si ) {
std::streamsize slen = (std::streamsize)( strings[ si ].length() );
for (std::size_t mi = 0; mi < num_masks; ++mi) {
for (std::size_t si = 0; si < num_strings; ++si) {
std::streamsize slen = (std::streamsize)(strings[si].length());
assert( (std::numeric_limits<std::streamsize>::max)()
>=(std::streamsize)(1+slen*2) );
for (std::size_t ci = 0; ci < num_chars; ++ci) {
assert( ( std::numeric_limits< std::streamsize >::max )() >= (std::streamsize)( 1 + slen * 2 ) );
for ( std::size_t ci = 0; ci < num_chars; ++ci ) {
// note how "negative widths" are tested too
const std::streamsize widths[] = { -1 - slen/2, 0, slen/2, 1 + slen*2 };
std::size_t num_widths = sizeof(widths) / sizeof(widths[0]);
const std::streamsize widths[] = { -1 - slen / 2, 0, slen / 2, 1 + slen * 2 };
std::size_t num_widths = sizeof( widths ) / sizeof( widths[ 0 ] );
for (std::size_t wi = 0; wi < num_widths; ++wi) {
std::streamsize w = widths[wi];
for ( std::size_t wi = 0; wi < num_widths; ++wi ) {
std::streamsize w = widths[ wi ];
{
// test 0 - stream !good()
if(not_good_stream.good())
throw std::logic_error("Error in operator << tests"
" - please, double check");
bitset_type b(strings[si]);
not_good_stream.width(w);
not_good_stream.fill(fill_chars[ci]);
try { not_good_stream.exceptions(masks[mi]); } catch(...) {}
if ( not_good_stream.good() )
throw std::logic_error( "Error in operator << tests"
" - please, double check" );
bitset_type b( strings[ si ] );
not_good_stream.width( w );
not_good_stream.fill( fill_chars[ ci ] );
try {
not_good_stream.exceptions( masks[ mi ] );
} catch ( ... ) {
}
Tests::stream_inserter(b, not_good_stream, "<unused_string>");
Tests::stream_inserter( b, not_good_stream, "<unused_string>" );
}
{
// test 1a - file stream
scoped_temp_file stf;
bitset_type b(strings[si]);
std::ofstream file(stf.path().string().c_str(), std::ios::trunc);
file.width(w);
file.fill(fill_chars[ci]);
file.exceptions(masks[mi]);
Tests::stream_inserter(b, file, stf.path().string().c_str());
bitset_type b( strings[ si ] );
std::ofstream file( stf.path().string().c_str(), std::ios::trunc );
file.width( w );
file.fill( fill_chars[ ci ] );
file.exceptions( masks[ mi ] );
Tests::stream_inserter( b, file, stf.path().string().c_str() );
}
{
//NOTE: there are NO string stream tests
// NOTE: there are NO string stream tests
}
#if !defined (BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS)
#if ! defined( BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS )
{
// test 1b - wide file stream
scoped_temp_file stf;
bitset_type b(strings[si]);
std::wofstream file(stf.path().string().c_str());
file.width(w);
file.fill(fill_chars[ci]);
file.exceptions(masks[mi]);
Tests::stream_inserter(b, file, stf.path().string().c_str());
bitset_type b( strings[ si ] );
std::wofstream file( stf.path().string().c_str() );
file.width( w );
file.fill( fill_chars[ ci ] );
file.exceptions( masks[ mi ] );
Tests::stream_inserter( b, file, stf.path().string().c_str() );
}
#endif
}
}
}
} // for (; mi..)
}
//=====================================================================
// Test stream operator>>
{
// The test "variables" are: the stream type, the exception mask,
// the actual contents (and/or state) of the stream, and width.
//
@@ -168,7 +159,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
// Note how the bitset object is not initially empty. That helps checking
// that it isn't erroneously clear()ed by operator>>.
std::ios::iostate masks[] = {
std::ios::goodbit,
std::ios::eofbit,
@@ -182,25 +172,25 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
const static std::string strings[] = {
// empty string
std::string(""),
std::string( "" ),
// no bitset
spaces,
// no bitset
std::string("x"),
std::string("\t xyz"),
std::string( "x" ),
std::string( "\t xyz" ),
// bitset of size 1
std::string("0"),
std::string("1"),
std::string( "0" ),
std::string( "1" ),
std::string(" 0 "),
std::string(" 1 "),
std::string( " 0 " ),
std::string( " 1 " ),
spaces + "1",
"1" + spaces,
spaces + "1" + spaces,
std::string(" x1x "),
std::string(" 1x "),
std::string( " x1x " ),
std::string( " 1x " ),
// long bitset
long_string,
@@ -209,7 +199,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
spaces + long_string + spaces
};
//-----------------------------------------------------
std::stringstream not_good_stream;
@@ -217,109 +206,106 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
std::string sink;
not_good_stream >> sink; // now the stream should be in eof state
const std::size_t num_masks = sizeof(masks) / sizeof(masks[0]);
const std::size_t num_strings = sizeof(strings) / sizeof(strings[0]);
const std::size_t num_masks = sizeof( masks ) / sizeof( masks[ 0 ] );
const std::size_t num_strings = sizeof( strings ) / sizeof( strings[ 0 ] );
for (std::size_t mi = 0; mi < num_masks; ++mi) {
for (std::size_t si = 0; si < num_strings; ++si) {
for ( std::size_t mi = 0; mi < num_masks; ++mi ) {
for ( std::size_t si = 0; si < num_strings; ++si ) {
const std::streamsize slen = (std::streamsize)( strings[ si ].length() );
assert( ( std::numeric_limits< std::streamsize >::max )() >= (std::streamsize)( 1 + slen * 2 ) );
const std::streamsize slen = (std::streamsize)(strings[si].length());
assert((std::numeric_limits<std::streamsize>::max)() >= (std::streamsize)(1+slen*2));
std::streamsize widths[] = { -1, 0, slen / 2, slen, 1 + slen * 2 };
std::size_t num_widths = sizeof( widths ) / sizeof( widths[ 0 ] );
std::streamsize widths[] = { -1, 0, slen/2, slen, 1 + slen*2 };
std::size_t num_widths = sizeof(widths) / sizeof(widths[0]);
for(std::size_t wi = 0; wi < num_widths; ++wi) {
const std::streamsize w = widths[wi];
for ( std::size_t wi = 0; wi < num_widths; ++wi ) {
const std::streamsize w = widths[ wi ];
// test 0 - !good() stream
{
if(not_good_stream.good())
throw std::logic_error("Error in operator >> tests"
" - please, double check");
bitset_type b(1, 15ul); // note: b is not empty
not_good_stream.width(w);
try { not_good_stream.exceptions(masks[mi]); } catch(...) {}
if ( not_good_stream.good() )
throw std::logic_error( "Error in operator >> tests"
" - please, double check" );
bitset_type b( 1, 15ul ); // note: b is not empty
not_good_stream.width( w );
try {
not_good_stream.exceptions( masks[ mi ] );
} catch ( ... ) {
}
std::string irrelevant;
Tests::stream_extractor(b, not_good_stream, irrelevant);
Tests::stream_extractor( b, not_good_stream, irrelevant );
}
// test 1a - (narrow) file stream
{
scoped_temp_file stf;
bitset_type b(1, 255ul);
bitset_type b( 1, 255ul );
{
std::ofstream f(stf.path().string().c_str());
f << strings[si];
std::ofstream f( stf.path().string().c_str() );
f << strings[ si ];
}
std::ifstream f(stf.path().string().c_str());
f.width(w);
f.exceptions(masks[mi]);
Tests::stream_extractor(b, f, strings[si]);
std::ifstream f( stf.path().string().c_str() );
f.width( w );
f.exceptions( masks[ mi ] );
Tests::stream_extractor( b, f, strings[ si ] );
}
#if !defined(BOOST_NO_STRINGSTREAM)
#if ! defined( BOOST_NO_STRINGSTREAM )
// test 2a - stringstream
{
bitset_type b(1, 255ul);
std::istringstream stream(strings[si]);
stream.width(w);
stream.exceptions(masks[mi]);
Tests::stream_extractor(b, stream, strings[si]);
bitset_type b( 1, 255ul );
std::istringstream stream( strings[ si ] );
stream.width( w );
stream.exceptions( masks[ mi ] );
Tests::stream_extractor( b, stream, strings[ si ] );
}
#endif
#if !defined(BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS)
#if ! defined( BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS )
// test 1b - wchar_t file stream
{
scoped_temp_file stf;
std::wstring wstr = widen_string(strings[si]);
bitset_type b(1, 255ul);
std::wstring wstr = widen_string( strings[ si ] );
bitset_type b( 1, 255ul );
{
std::basic_ofstream<wchar_t> of(stf.path().string().c_str());
std::basic_ofstream< wchar_t > of( stf.path().string().c_str() );
of << wstr;
}
std::basic_ifstream<wchar_t> f(stf.path().string().c_str());
f.width(w);
f.exceptions(masks[mi]);
Tests::stream_extractor(b, f, wstr);
std::basic_ifstream< wchar_t > f( stf.path().string().c_str() );
f.width( w );
f.exceptions( masks[ mi ] );
Tests::stream_extractor( b, f, wstr );
}
// test 2b - wstringstream
{
bitset_type b(1, 255ul);
std::wstring wstr = widen_string(strings[si]);
bitset_type b( 1, 255ul );
std::wstring wstr = widen_string( strings[ si ] );
std::wistringstream wstream(wstr);
wstream.width(w);
wstream.exceptions(masks[mi]);
Tests::stream_extractor(b, wstream, wstr);
std::wistringstream wstream( wstr );
wstream.width( w );
wstream.exceptions( masks[ mi ] );
Tests::stream_extractor( b, wstream, wstr );
}
#endif // BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
}
}
} // for ( mi = 0; ...)
}
//=====================================================================
// << Any other tests go here >>
// .....
}
int
main()
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
run_test_cases<unsigned int>();
run_test_cases<unsigned long>();
# ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type>();
# endif
run_test_cases< unsigned char >();
run_test_cases< unsigned short >();
run_test_cases< unsigned int >();
run_test_cases< unsigned long >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type >();
#endif
return boost::report_errors();
}

View File

@@ -20,84 +20,94 @@
#include "boost/dynamic_bitset/serialization.hpp"
#include "boost/serialization/vector.hpp"
#if !defined (BOOST_NO_STRINGSTREAM)
#if ! defined( BOOST_NO_STRINGSTREAM )
# include <sstream>
#endif
#if defined BOOST_NO_STD_WSTRING || defined BOOST_NO_STD_LOCALE
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
#endif
namespace {
template <typename Block>
struct SerializableType {
boost::dynamic_bitset<Block> x;
template< typename Block >
struct SerializableType
{
boost::dynamic_bitset< Block > x;
private:
private:
friend class boost::serialization::access;
template <class Archive> void serialize(Archive &ar, unsigned int) {
ar & BOOST_SERIALIZATION_NVP(x);
}
};
template <typename Block, typename IArchive, typename OArchive>
void test_serialization( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
template< class Archive >
void
serialize( Archive & ar, unsigned int )
{
SerializableType<Block> a;
ar & BOOST_SERIALIZATION_NVP( x );
}
};
for (int i=0; i<128; ++i)
a.x.resize(11*i, i%2);
template< typename Block, typename IArchive, typename OArchive >
void
test_serialization( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
SerializableType< Block > a;
#if !defined (BOOST_NO_STRINGSTREAM)
for ( int i = 0; i < 128; ++i )
a.x.resize( 11 * i, i % 2 );
#if ! defined( BOOST_NO_STRINGSTREAM )
std::stringstream ss;
// test serialization
{
OArchive oa(ss);
oa << BOOST_SERIALIZATION_NVP(a);
OArchive oa( ss );
oa << BOOST_SERIALIZATION_NVP( a );
}
// test de-serialization
{
IArchive ia(ss);
SerializableType<Block> b;
ia >> BOOST_SERIALIZATION_NVP(b);
IArchive ia( ss );
SerializableType< Block > b;
ia >> BOOST_SERIALIZATION_NVP( b );
BOOST_TEST(a.x == b.x);
BOOST_TEST( a.x == b.x );
}
#else
# error "TODO implement file-based test path?"
#endif
}
template <typename Block>
void test_binary_archive( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) {
test_serialization<Block, boost::archive::binary_iarchive, boost::archive::binary_oarchive>();
}
template <typename Block>
void test_xml_archive( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) {
test_serialization<Block, boost::archive::xml_iarchive, boost::archive::xml_oarchive>();
}
}
template <typename Block>
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
template< typename Block >
void
test_binary_archive( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
test_binary_archive<Block>();
test_xml_archive<Block>();
test_serialization< Block, boost::archive::binary_iarchive, boost::archive::binary_oarchive >();
}
int main()
template< typename Block >
void
test_xml_archive( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
run_test_cases<unsigned int>();
run_test_cases<unsigned long>();
# ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type>();
# endif
test_serialization< Block, boost::archive::xml_iarchive, boost::archive::xml_oarchive >();
}
}
template< typename Block >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
test_binary_archive< Block >();
test_xml_archive< Block >();
}
int
main()
{
run_test_cases< unsigned char >();
run_test_cases< unsigned short >();
run_test_cases< unsigned int >();
run_test_cases< unsigned long >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type >();
#endif
return boost::report_errors();
}

View File

@@ -14,17 +14,18 @@
#include "boost/core/lightweight_test.hpp"
#include "boost/dynamic_bitset.hpp"
int main(int, char*[])
int
main( int, char *[] )
{
boost::dynamic_bitset<> x(5); // all 0's by default
x.set(1, 2);
x.set(3, 1, true);
x.set(2, 1, false);
BOOST_TEST(!x.test(0));
BOOST_TEST( x.test(1));
BOOST_TEST(!x.test(2));
BOOST_TEST( x.test(3));
BOOST_TEST(!x.test(4));
boost::dynamic_bitset<> x( 5 ); // all 0's by default
x.set( 1, 2 );
x.set( 3, 1, true );
x.set( 2, 1, false );
BOOST_TEST( ! x.test( 0 ) );
BOOST_TEST( x.test( 1 ) );
BOOST_TEST( ! x.test( 2 ) );
BOOST_TEST( x.test( 3 ) );
BOOST_TEST( ! x.test( 4 ) );
return boost::report_errors();
}

View File

@@ -16,9 +16,10 @@
#include "boost/dynamic_bitset.hpp"
#include <set>
int main(int, char*[])
int
main( int, char *[] )
{
typedef boost::dynamic_bitset<unsigned long> bitset_type;
typedef boost::dynamic_bitset< unsigned long > bitset_type;
const std::string long_string =
"01001110101110110101011010000000000011110101101111111111";
const std::string long_string_prime_begin =
@@ -26,22 +27,22 @@ int main(int, char*[])
const std::string long_string_prime_end =
"01001110101110110101011010000000000011110101101111111110";
bitset_type zeroes(long_string.size(), 0);
bitset_type stuff (long_string);
bitset_type stupb (long_string_prime_begin);
bitset_type stupe (long_string_prime_end);
bitset_type ones (long_string.size(), 1);
bitset_type zeroes( long_string.size(), 0 );
bitset_type stuff( long_string );
bitset_type stupb( long_string_prime_begin );
bitset_type stupe( long_string_prime_end );
bitset_type ones( long_string.size(), 1 );
boost::hash<bitset_type> bitset_hasher;
std::set<std::size_t> results;
results.insert(bitset_hasher(zeroes));
results.insert(bitset_hasher(stuff));
results.insert(bitset_hasher(stupb));
results.insert(bitset_hasher(stupe));
results.insert(bitset_hasher(ones));
boost::hash< bitset_type > bitset_hasher;
std::set< std::size_t > results;
results.insert( bitset_hasher( zeroes ) );
results.insert( bitset_hasher( stuff ) );
results.insert( bitset_hasher( stupb ) );
results.insert( bitset_hasher( stupe ) );
results.insert( bitset_hasher( ones ) );
// if any hash is identical to another there will be less than 5
BOOST_TEST_EQ(results.size(), 5);
BOOST_TEST_EQ( results.size(), 5 );
return boost::report_errors();
}

View File

@@ -15,14 +15,15 @@
#include "boost/cstdint.hpp"
#include "boost/dynamic_bitset/detail/lowest_bit.hpp"
int main(int, char*[])
int
main( int, char *[] )
{
for (boost::int32_t i = 1; i < 32; ++i) {
BOOST_TEST_EQ(i, boost::detail::lowest_bit(1u << i));
for ( boost::int32_t i = 1; i < 32; ++i ) {
BOOST_TEST_EQ( i, boost::detail::lowest_bit( 1u << i ) );
}
BOOST_TEST_EQ(2, boost::detail::lowest_bit(123456788));
BOOST_TEST_EQ(30, boost::detail::lowest_bit(static_cast<boost::int64_t>(1507208177123328)));
BOOST_TEST_EQ( 2, boost::detail::lowest_bit( 123456788 ) );
BOOST_TEST_EQ( 30, boost::detail::lowest_bit( static_cast< boost::int64_t >( 1507208177123328 ) ) );
return boost::report_errors();
}

View File

@@ -14,25 +14,25 @@
#include "boost/config.hpp"
#include "boost/detail/lightweight_test.hpp"
#include "boost/dynamic_bitset.hpp"
#include <unordered_set>
int main(int, char*[])
int
main( int, char *[] )
{
typedef boost::dynamic_bitset<unsigned long> bitset_type;
typedef boost::dynamic_bitset< unsigned long > bitset_type;
const std::string long_string =
"01001110101110110101011010000000000011110101101111111111";
bitset_type zeroes(long_string.size(), 0);
bitset_type stuff (long_string);
bitset_type ones (long_string.size(), 1);
bitset_type zeroes( long_string.size(), 0 );
bitset_type stuff( long_string );
bitset_type ones( long_string.size(), 1 );
std::unordered_set<bitset_type> bitsets;
bitsets.insert(zeroes);
bitsets.insert(stuff);
bitsets.insert(ones);
std::unordered_set< bitset_type > bitsets;
bitsets.insert( zeroes );
bitsets.insert( stuff );
bitsets.insert( ones );
BOOST_TEST_EQ(bitsets.size(), 3);
BOOST_TEST_EQ( bitsets.size(), 3 );
return boost::report_errors();
}