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,7 +18,8 @@
#include "boost/dynamic_bitset.hpp"
#include <iostream>
int main()
int
main()
{
boost::dynamic_bitset<> x( 5 ); // all 0's by default
x[ 0 ] = 1;

View File

@@ -13,7 +13,8 @@
#include "boost/dynamic_bitset.hpp"
#include <iostream>
int main()
int
main()
{
const boost::dynamic_bitset<> b0( 2, 0ul );
std::cout << "bits(0) = " << b0 << std::endl;

View File

@@ -19,14 +19,12 @@
// 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 );
std::cout << "mask = " << mask << std::endl;

View File

@@ -16,9 +16,16 @@
// 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 ) \

View File

@@ -27,7 +27,8 @@ namespace boost {
namespace dynamic_bitset_impl {
template< class T >
struct max_limit {
struct max_limit
{
BOOST_STATIC_CONSTEXPR T value = static_cast< T >( -1 );
};
@@ -37,7 +38,9 @@ namespace boost {
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 ) );
}
@@ -46,7 +49,9 @@ namespace boost {
template< bool value >
struct value_to_type
{
value_to_type() {}
value_to_type()
{
}
};
// Some library implementations simply return a dummy
// value such as
@@ -57,7 +62,8 @@ namespace boost {
// meaningful info.
//
template< typename T >
inline typename T::size_type vector_max_size_workaround(const T & v)
inline typename T::size_type
vector_max_size_workaround( const T & v )
BOOST_NOEXCEPT
{
typedef typename T::allocator_type allocator_type;
@@ -68,31 +74,45 @@ namespace boost {
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
struct allowed_block_type
{
enum
{
value = T( -1 ) > 0 // ensure T has no sign
};
};
template<>
struct allowed_block_type<bool> {
enum { value = false };
struct allowed_block_type< bool >
{
enum
{
value = false
};
};
template< typename T >
struct is_numeric {
enum { value = false };
struct is_numeric
{
enum
{
value = false
};
};
#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 );
@@ -130,4 +150,3 @@ namespace boost {
} // namespace boost
#endif // include guard

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>
@@ -62,21 +61,18 @@ public:
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 >;
// the one and only non-copy ctor
reference( block_type & b, block_width_type pos );
void operator&(); // left undefined
public:
// copy constructor: compiler generated
operator bool() const;
@@ -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.
//
@@ -127,22 +119,15 @@ public:
// 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());
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);
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());
dynamic_bitset( BlockInputIterator first, BlockInputIterator last, const Allocator & alloc = Allocator() );
// copy constructor
dynamic_bitset( const dynamic_bitset & b );
@@ -224,25 +209,19 @@ public:
// lexicographical comparison
template< typename B, typename A >
friend bool operator==(const dynamic_bitset<B, A>& a,
const dynamic_bitset<B, A>& b);
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);
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);
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);
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);
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 );
@@ -250,7 +229,6 @@ public:
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;
@@ -258,9 +236,7 @@ public:
private:
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;
@@ -272,40 +248,31 @@ private:
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 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_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_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_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>);
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>);
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 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_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 );
@@ -322,10 +289,10 @@ private:
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
@@ -372,58 +339,46 @@ dynamic_bitset<Block, Allocator>::ulong_width;
// comparison
template< typename Block, typename Allocator >
bool operator!=(const dynamic_bitset<Block, Allocator>& a,
const dynamic_bitset<Block, Allocator>& b);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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;
void swap( dynamic_bitset< Block, Allocator > & b1, dynamic_bitset< Block, Allocator > & b2 ) BOOST_NOEXCEPT;
template< typename Block, typename Allocator, typename stringT >
void
@@ -431,17 +386,13 @@ to_string(const dynamic_bitset<Block, Allocator>& b, stringT & s);
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 >
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

@@ -22,7 +22,9 @@ namespace boost {
{
public:
template< typename Ar >
static void serialize(Ar& ar, dynamic_bitset<Block, Allocator>& bs, unsigned) {
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 );
}
@@ -35,7 +37,9 @@ namespace boost {
namespace serialization {
template< typename Ar, typename Block, typename Allocator >
void serialize(Ar& ar, dynamic_bitset<Block, Allocator>& bs, unsigned version) {
void
serialize( Ar & ar, dynamic_bitset< Block, Allocator > & bs, unsigned version )
{
dynamic_bitset< Block, Allocator >::serialize_impl::serialize( ar, bs, version );
}
@@ -43,4 +47,3 @@ namespace boost {
} // 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

@@ -23,16 +23,23 @@
# include <cstdlib>
template< class T >
class minimal_allocator {
class minimal_allocator
{
public:
typedef T value_type;
minimal_allocator() {}
minimal_allocator()
{
}
template< typename U >
minimal_allocator(const minimal_allocator<U>&) {}
minimal_allocator( const minimal_allocator< U > & )
{
}
T* allocate(std::size_t n) {
T *
allocate( std::size_t n )
{
void * p = std::malloc( sizeof( T ) * n );
if ( ! p ) {
throw std::bad_alloc();
@@ -40,7 +47,9 @@ public:
return static_cast< T * >( p );
}
void deallocate(T* p, std::size_t) {
void
deallocate( T * p, std::size_t )
{
std::free( p );
}
};
@@ -48,20 +57,16 @@ public:
#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
# pragma parse_func_templ off
#endif
template< typename Tests, typename String >
void run_string_tests(const String& s
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tests)
)
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;
@@ -79,36 +84,31 @@ void run_string_tests(const String& s
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)
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 )();
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 ) {
// can match ctor from ulong or templated one
Tests::from_unsigned_long( sizes[ s ], numbers[ n ] );
@@ -128,15 +128,13 @@ void run_numeric_ctor_tests( BOOST_EXPLICIT_TEMPLATE_TYPE(Tests)
// can match templated ctor only (so we test dispatching)
Tests::from_unsigned_long( static_cast< T >( sizes[ s ] ), numbers[ n ] );
}
}
}
}
template< typename Block >
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
typedef boost::dynamic_bitset< Block > bitset_type;
typedef bitset_test< bitset_type > Tests;
@@ -157,8 +155,7 @@ 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 };
@@ -190,12 +187,10 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
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" ) );
@@ -216,7 +211,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
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
@@ -530,8 +524,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
}
#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 );
}

View File

@@ -14,9 +14,9 @@
#include "boost/config.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
template< typename Block >
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
typedef boost::dynamic_bitset< Block > bitset_type;
typedef bitset_test< bitset_type > Tests;
@@ -165,7 +165,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
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;
@@ -227,10 +226,8 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
}
{ // 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);
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 );
@@ -286,8 +283,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
}
{ // 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);
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 );
@@ -355,8 +351,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
}
{ // 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);
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 );

View File

@@ -17,7 +17,8 @@
#include <assert.h>
template< typename Block >
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
// a bunch of typedefs which will be handy later on
typedef boost::dynamic_bitset< Block > bitset_type;
@@ -38,8 +39,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::empty( b );
}
{
bitset_type b(bitset_type::bits_per_block
+ bitset_type::bits_per_block/2, 15ul);
bitset_type b( bitset_type::bits_per_block + bitset_type::bits_per_block / 2, 15ul );
Tests::empty( b );
}
//=====================================================================
@@ -53,8 +53,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::to_ulong( b );
}
{
boost::dynamic_bitset<Block> b(bitset_type::bits_per_block,
static_cast<unsigned long>(-1));
boost::dynamic_bitset< Block > b( bitset_type::bits_per_block, static_cast< unsigned long >( -1 ) );
Tests::to_ulong( b );
}
{
@@ -370,7 +369,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
bitset_type b( num_blocks * block_width );
typename bitset_type::size_type i = block_width - 1;
for ( ; i < b.size(); i += block_width ) {
b.set( i );
typename bitset_type::size_type first_in_block = i - ( block_width - 1 );
b.set( first_in_block );
@@ -382,7 +380,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::find_pos( b, i );
}
Tests::find_pos( b, b.npos );
}
{
// bitset with alternate 1s and 0s
@@ -400,7 +397,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::find_pos( b, i );
}
Tests::find_pos( b, b.npos );
}
//=====================================================================
// Test operator==
@@ -798,7 +794,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
}
}
int
main()
{

View File

@@ -12,7 +12,6 @@
#include "boost/config.hpp"
#include "boost/config/workaround.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include <assert.h>
#include <cstddef>
#include <fstream>
@@ -23,19 +22,17 @@
# 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() )
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;
typedef std::wstring::traits_type tr_type;
const ct_type & ct = BOOST_USE_FACET( ct_type, loc );
@@ -43,23 +40,21 @@ std::wstring widen_string( const std::string & str,
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) )
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
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)
@@ -84,20 +79,15 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
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() );
assert( (std::numeric_limits<std::streamsize>::max)()
>=(std::streamsize)(1+slen*2) );
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 ] );
@@ -112,7 +102,10 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
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(...) {}
try {
not_good_stream.exceptions( masks[ mi ] );
} catch ( ... ) {
}
Tests::stream_inserter( b, not_good_stream, "<unused_string>" );
}
@@ -145,13 +138,11 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
}
}
} // 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,
@@ -209,7 +199,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
spaces + long_string + spaces
};
//-----------------------------------------------------
std::stringstream not_good_stream;
@@ -222,7 +211,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
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 ) );
@@ -239,7 +227,10 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
" - 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(...) {}
try {
not_good_stream.exceptions( masks[ mi ] );
} catch ( ... ) {
}
std::string irrelevant;
Tests::stream_extractor( b, not_good_stream, irrelevant );
}
@@ -295,21 +286,16 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::stream_extractor( b, wstream, wstr );
}
#endif // BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
}
}
} // for ( mi = 0; ...)
}
//=====================================================================
// << Any other tests go here >>
// .....
}
int
main()
{

View File

@@ -24,25 +24,29 @@
# 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 {
struct SerializableType
{
boost::dynamic_bitset< Block > x;
private:
friend class boost::serialization::access;
template <class Archive> void serialize(Archive &ar, unsigned int) {
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) )
void
test_serialization( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
SerializableType< Block > a;
@@ -72,24 +76,30 @@ namespace {
}
template< typename Block >
void test_binary_archive( BOOST_EXPLICIT_TEMPLATE_TYPE(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) ) {
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) )
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{
test_binary_archive< Block >();
test_xml_archive< Block >();
}
int main()
int
main()
{
run_test_cases< unsigned char >();
run_test_cases< unsigned short >();

View File

@@ -14,7 +14,8 @@
#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 );

View File

@@ -16,7 +16,8 @@
#include "boost/dynamic_bitset.hpp"
#include <set>
int main(int, char*[])
int
main( int, char *[] )
{
typedef boost::dynamic_bitset< unsigned long > bitset_type;
const std::string long_string =

View File

@@ -15,7 +15,8 @@
#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 ) );

View File

@@ -14,10 +14,10 @@
#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;
const std::string long_string =