Compare commits

..

1 Commits

Author SHA1 Message Date
Beman Dawes
aaea06c805 1.36.0
[SVN r48100]
2008-08-12 12:44:50 +00:00
23 changed files with 908 additions and 1787 deletions

View File

@@ -1,3 +0,0 @@
# Empty Jamfile because the super project still expects one to appear here.
# Can be deleted once 'status/Jamfile.v2' has been updated in the super
# project.

View File

@@ -11,6 +11,4 @@ test-suite dynamic_bitset :
[ run dyn_bitset_unit_tests2.cpp ]
[ run dyn_bitset_unit_tests3.cpp ]
[ run dyn_bitset_unit_tests4.cpp ]
[ run dyn_bitset_unit_tests5.cpp /boost/serialization//boost_serialization
: : : <define>_SCL_SECURE_NO_WARNINGS=1 ]
;
;

View File

@@ -1,14 +1,14 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2014 Riccardo Marcangelo
// --------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2006.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
//
// $Id$
#ifndef BOOST_BITSET_TEST_HPP_GP_20040319
#define BOOST_BITSET_TEST_HPP_GP_20040319
@@ -110,43 +110,32 @@ bool has_flags(const Stream& s, std::ios::iostate flags)
// constructors
// default (can't do this generically)
// from unsigned long
template <typename Bitset>
struct bitset_test {
typedef typename Bitset::block_type Block;
BOOST_STATIC_CONSTANT(int, bits_per_block = Bitset::bits_per_block);
// from unsigned long
//
// Note: this is templatized so that we check that the do-the-right-thing
// constructor dispatch is working correctly.
//
template <typename NumBits, typename Value>
static void from_unsigned_long(NumBits num_bits, Value num)
static void from_unsigned_long(std::size_t sz, unsigned long num)
{
// An object of size sz = num_bits is constructed:
// - the first m bit positions are initialized to the corresponding
// bit values in num (m being the smaller of sz and ulong_width)
//
// - any remaining bit positions are initialized to zero
// An object of size N = sz is constructed:
// - the first M bit positions are initialized to the corresponding bit
// values in num (M being the smaller of N and the width of unsigned
// long)
//
// - if M < N remaining bit positions are initialized to zero
Bitset b(static_cast<typename Bitset::size_type>(num_bits), static_cast<unsigned long>(num));
// OK, we can now cast to size_type
typedef typename Bitset::size_type size_type;
const size_type sz = static_cast<size_type>(num_bits);
Bitset b(sz, num);
BOOST_CHECK(b.size() == sz);
const std::size_t ulong_width = std::numeric_limits<unsigned long>::digits;
size_type m = sz;
if (ulong_width < sz)
m = ulong_width;
size_type i = 0;
for ( ; i < m; ++i)
BOOST_CHECK(b.test(i) == nth_bit(static_cast<unsigned long>(num), i));
std::size_t m = (std::min)(sz, ulong_width);
std::size_t i;
for (i = 0; i < m; ++i)
BOOST_CHECK(b.test(i) == nth_bit(num, i));
for ( ; i < sz; ++i)
BOOST_CHECK(b.test(i) == 0);
}
@@ -269,12 +258,11 @@ struct bitset_test {
}
}
// copy assignment operator (absent from std::bitset)
static void copy_assignment_operator(const Bitset& lhs, const Bitset& rhs)
// assignment operator (absent from std::bitset)
static void assignment_operator(const Bitset& lhs, const Bitset& rhs)
{
Bitset b(lhs);
b = rhs;
b = b; // self assignment check
BOOST_CHECK(b == rhs);
// Changes to the copy do not affect the original
@@ -285,32 +273,6 @@ struct bitset_test {
}
}
static void max_size(const Bitset& b)
{
BOOST_CHECK(b.max_size() > 0);
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
// move constructor (absent from std::bitset)
static void move_constructor(const Bitset& b)
{
Bitset copy(boost::move(b));
BOOST_CHECK(b == copy);
}
// move assignment operator (absent from std::bitset)
static void move_assignment_operator(const Bitset& lhs, const Bitset& rhs)
{
Bitset b(lhs);
Bitset c(rhs);
b = boost::move(c);
b = boost::move(b); // self assignment check
BOOST_CHECK(b == rhs);
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
static void swap(const Bitset& lhs, const Bitset& rhs)
{
// bitsets must be swapped
@@ -368,20 +330,6 @@ struct bitset_test {
BOOST_CHECK(b.size() == 0);
}
static void pop_back(const Bitset& lhs)
{
Bitset b(lhs);
b.pop_back();
BOOST_CHECK(b.size() == lhs.size() - 1);
for (std::size_t i = 0; i < b.size(); ++i)
BOOST_CHECK(b[i] == lhs[i]);
b.pop_back();
BOOST_CHECK(b.size() == lhs.size() - 2);
for (std::size_t j = 0; j < b.size(); ++j)
BOOST_CHECK(b[j] == lhs[j]);
}
static void append_bit(const Bitset& lhs)
{
Bitset b(lhs);
@@ -732,82 +680,9 @@ struct bitset_test {
BOOST_CHECK(Bitset(b).set().count() == b.size());
}
static void capacity_test_one(const Bitset& lhs)
{
//empty bitset
Bitset b(lhs);
BOOST_CHECK(b.capacity() == 0);
}
static void capacity_test_two(const Bitset& lhs)
{
//bitset constructed with size "100"
Bitset b(lhs);
BOOST_CHECK(b.capacity() >= 100);
b.resize(200);
BOOST_CHECK(b.capacity() >= 200);
}
static void reserve_test_one(const Bitset& lhs)
{
//empty bitset
Bitset b(lhs);
b.reserve(16);
BOOST_CHECK(b.capacity() >= 16);
}
static void reserve_test_two(const Bitset& lhs)
{
//bitset constructed with size "100"
Bitset b(lhs);
BOOST_CHECK(b.capacity() >= 100);
b.reserve(60);
BOOST_CHECK(b.size() == 100);
BOOST_CHECK(b.capacity() >= 100);
b.reserve(160);
BOOST_CHECK(b.size() == 100);
BOOST_CHECK(b.capacity() >= 160);
}
static void shrink_to_fit_test_one(const Bitset& lhs)
{
//empty bitset
Bitset b(lhs);
b.shrink_to_fit();
BOOST_CHECK(b.size() == 0);
BOOST_CHECK(b.capacity() == 0);
}
static void shrink_to_fit_test_two(const Bitset& lhs)
{
//bitset constructed with size "100"
Bitset b(lhs);
b.shrink_to_fit();
BOOST_CHECK(b.capacity() >= 100);
BOOST_CHECK(b.size() == 100);
b.reserve(200);
BOOST_CHECK(b.capacity() >= 200);
BOOST_CHECK(b.size() == 100);
b.shrink_to_fit();
BOOST_CHECK(b.capacity() < 200);
BOOST_CHECK(b.size() == 100);
}
static void all(const Bitset& b)
{
BOOST_CHECK(b.all() == (b.count() == b.size()));
bool result = true;
for(std::size_t i = 0; i < b.size(); ++i)
if(!b[i]) {
result = false;
break;
}
BOOST_CHECK(b.all() == result);
}
static void any(const Bitset& b)
{
BOOST_CHECK(b.any() == (b.count() != 0));
//BOOST_CHECK(b.any() == (b.count() > 0));
bool result = false;
for(std::size_t i = 0; i < b.size(); ++i)
if(b[i]) {
@@ -1041,25 +916,6 @@ struct bitset_test {
}
}
static void test_set_bit(const Bitset& b, std::size_t pos, bool value)
{
Bitset lhs(b);
std::size_t N = lhs.size();
if (pos < N) {
Bitset prev(lhs);
// Stores a new value in the bit at position pos in lhs.
BOOST_CHECK(lhs.test_set(pos, value) == prev[pos]);
BOOST_CHECK(lhs[pos] == value);
// All other values of lhs remain unchanged
for (std::size_t I = 0; I < N; ++I)
if (I != pos)
BOOST_CHECK(lhs[I] == prev[I]);
} else {
// Not in range, doesn't satisfy precondition.
}
}
static void operator_shift_left(const Bitset& lhs, std::size_t pos)
{
Bitset x(lhs);
@@ -1124,7 +980,7 @@ struct bitset_test {
//-------------------------------------------------------------------------
// operator<<( [basic_]ostream,
template <typename Stream>
template<typename Stream>
static void stream_inserter(const Bitset & b,
Stream & s,
const char * file_name
@@ -1183,7 +1039,7 @@ struct bitset_test {
// This test require that os be an output _and_ input stream.
// Of course dynamic_bitset's operator << doesn't require that.
size_type total_len = w <= 0 || static_cast<size_type>(w) < b.size()? b.size() : static_cast<size_type>(w);
size_type total_len = w <= 0 || (size_type)(w) < b.size()? b.size() : w;
const string_type padding (total_len - b.size(), fill_char);
string_type expected;
boost::to_string(b, expected);
@@ -1204,7 +1060,7 @@ struct bitset_test {
}
// operator>>( [basic_]istream
template <typename Stream, typename String>
template<typename Stream, typename String>
static void stream_extractor(Bitset& b,
Stream& is,
String& str
@@ -1274,7 +1130,7 @@ struct bitset_test {
// {digits} or part of them
const typename Bitset::size_type max_digits =
w > 0 && static_cast<typename Bitset::size_type>(w) < b.max_size()
? static_cast<typename Bitset::size_type>(w) : b.max_size();
? w : b.max_size();
for( ; pos < len && (pos - after_spaces) < max_digits; ++pos) {
if(!is_one_or_zero(is, str[pos]))

View File

@@ -1 +0,0 @@
The documentation for the dynamic_bitset library is the top-level index.html file.

View File

@@ -1,17 +1,14 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2014 Riccardo Marcangelo
//
// Copyright (c) 2014 Glen Joseph Fernandes
// glenfe at live dot com
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2006.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
//
// $Id$
#include "bitset_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
@@ -20,34 +17,7 @@
#include "boost/detail/workaround.hpp"
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#include <cstdlib>
template<class T>
class minimal_allocator {
public:
typedef T value_type;
minimal_allocator() {}
template <typename U>
minimal_allocator(const minimal_allocator<U>&) {}
T* allocate(std::size_t n) {
void* p = std::malloc(sizeof(T) * n);
if (!p) {
throw std::bad_alloc();
}
return static_cast<T*>(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_OF(x) (sizeof(x)/sizeof(x[0]))
// Codewarrior 8.3 for Win fails without this.
@@ -86,56 +56,6 @@ void run_string_tests(const String& s
}
// 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) )
{
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
};
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)
};
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]);
typedef std::size_t compare_type;
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
// purposes: our sizes are anyhow < max(size_t)], which in turn could
// make the first argument of from_unsigned_long() a small negative,
// 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);
if (fits) {
// 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) )
{
@@ -149,49 +69,24 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
//=====================================================================
// Test construction from unsigned long
{
// NOTE:
//
// 1. keep this in sync with the numeric types supported
// for constructor dispatch (of course)
// 2. bool is tested separately; ugly and inelegant, but
// we don't have much time to think of a better solution
// 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
};
const bool values[] = { false, true };
typedef unsigned long source_type;
const std::size_t source_width = std::numeric_limits<source_type>::digits;
const source_type source_max =(std::numeric_limits<source_type>::max)();
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]);
source_type numbers[] = { 0, 1, 40247, source_max >> 1, source_max };
std::size_t sizes[] =
{ 0, 7 * source_width / 10, source_width, 13 * source_width / 10,
7 * bits_per_block / 10, bits_per_block, 13 * bits_per_block / 10,
3 * bits_per_block };
const std::size_t value_count = BOOST_BITSET_TEST_COUNT_OF(numbers);
const std::size_t size_count = BOOST_BITSET_TEST_COUNT_OF(sizes);
for (std::size_t v = 0; v < value_count; ++v) {
for (std::size_t s = 0; s < size_count; ++s) {
Tests::from_unsigned_long(sizes[s], numbers[v]);
}
}
run_numeric_ctor_tests<Tests, char>();
#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, 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>();
#endif
}
//=====================================================================
// Test construction from a string
@@ -269,70 +164,29 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::copy_constructor(b);
}
//=====================================================================
// Test copy assignment operator
// Test assignment operator
{
bitset_type a, b;
Tests::copy_assignment_operator(a, b);
Tests::assignment_operator(a, b);
}
{
bitset_type a(std::string("1")), b(std::string("0"));
Tests::copy_assignment_operator(a, b);
Tests::assignment_operator(a, b);
}
{
bitset_type a(long_string), b(long_string);
Tests::copy_assignment_operator(a, b);
Tests::assignment_operator(a, b);
}
{
bitset_type a;
bitset_type b(long_string); // b greater than a, a empty
Tests::copy_assignment_operator(a, b);
Tests::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);
Tests::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(std::string("0"));
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);
}
{
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;
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);
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
//=====================================================================
// Test swap
{
@@ -385,25 +239,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
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("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(long_string);
Tests::pop_back(a);
}
//=====================================================================
// Test append bit
{
boost::dynamic_bitset<Block> a;
@@ -509,14 +344,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
bit_vec[i] = long_string[n - 1 - i] == '0' ? 0 : 1;
Tests::operator_bracket(b, bit_vec);
}
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
{
typedef boost::dynamic_bitset<Block,
minimal_allocator<Block> > Bitset;
Bitset b;
bitset_test<Bitset>::max_size(b);
}
#endif
}
int

View File

@@ -1,13 +1,14 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2006.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
//
// $Id$
#include "bitset_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
@@ -195,17 +196,14 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
{ // case pos >= b.size()
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);
}
{ // 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);
}
//=====================================================================
// Test b.reset()

View File

@@ -1,14 +1,14 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2014 Riccardo Marcangelo
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2006.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
//
// $Id$
#include <assert.h>
#include "bitset_test.hpp"
@@ -123,103 +123,32 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::size(b);
}
//=====================================================================
// Test b.capacity()
{
boost::dynamic_bitset<Block> b;
Tests::capacity_test_one(b);
}
{
boost::dynamic_bitset<Block> b(100);
Tests::capacity_test_two(b);
}
//=====================================================================
// Test b.reserve()
{
boost::dynamic_bitset<Block> b;
Tests::reserve_test_one(b);
}
{
boost::dynamic_bitset<Block> b(100);
Tests::reserve_test_two(b);
}
//=====================================================================
// Test b.shrink_to_fit()
{
boost::dynamic_bitset<Block> b;
Tests::shrink_to_fit_test_one(b);
}
{
boost::dynamic_bitset<Block> b(100);
Tests::shrink_to_fit_test_two(b);
}
//=====================================================================
// Test b.all()
{
boost::dynamic_bitset<Block> b;
Tests::all(b);
Tests::all(~b);
Tests::all(b.set());
Tests::all(b.reset());
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::all(b);
Tests::all(~b);
Tests::all(b.set());
Tests::all(b.reset());
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::all(b);
Tests::all(~b);
Tests::all(b.set());
Tests::all(b.reset());
}
//=====================================================================
// Test b.any()
{
boost::dynamic_bitset<Block> b;
Tests::any(b);
Tests::any(~b);
Tests::any(b.set());
Tests::any(b.reset());
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::any(b);
Tests::any(~b);
Tests::any(b.set());
Tests::any(b.reset());
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::any(b);
Tests::any(~b);
Tests::any(b.set());
Tests::any(b.reset());
}
//=====================================================================
// Test b.none()
{
boost::dynamic_bitset<Block> b;
Tests::none(b);
Tests::none(~b);
Tests::none(b.set());
Tests::none(b.reset());
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::none(b);
Tests::none(~b);
Tests::none(b.set());
Tests::none(b.reset());
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::none(b);
Tests::none(~b);
Tests::none(b.set());
Tests::none(b.reset());
}
//=====================================================================
// Test a.is_subset_of(b)
@@ -642,23 +571,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::test_bit(b, long_string.size()/2);
}
//=====================================================================
// Test b.test_set(pos)
{ // case pos >= b.size()
boost::dynamic_bitset<Block> b;
Tests::test_set_bit(b, 0, true);
Tests::test_set_bit(b, 0, false);
}
{ // case pos < b.size()
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::test_set_bit(b, 0, true);
Tests::test_set_bit(b, 0, false);
}
{ // case pos == b.size() / 2
boost::dynamic_bitset<Block> b(long_string);
Tests::test_set_bit(b, long_string.size() / 2, true);
Tests::test_set_bit(b, long_string.size() / 2, false);
}
//=====================================================================
// Test b << pos
{ // case pos == 0
std::size_t pos = 0;

View File

@@ -1,12 +1,14 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2006.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
//
// $Id$
#include <fstream>
#include <string>

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,13 @@
// -----------------------------------------------------------
// Copyright (c) 2002 Gennaro Prota
// (C) Copyright Gennaro Prota 2002
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
// ----------------------------------------------------------
//
// $Id$
exe timing_tests
: timing_tests.cpp
;

View File

@@ -3,33 +3,23 @@
// 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
// bitset from most-significant to least-significant, since that is
// the format most people are used to reading.
//
// The output is:
//
// 11001
// 10011
// ---------------------------------------------------------------------
// Sample output:
// 1
// 1
// 0
// 0
// 1
#include <iostream>
#include <boost/dynamic_bitset.hpp>
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];
std::cout << "\n";
std::cout << x << "\n";
return 0;
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];
std::cout << "\n";
std::cout << x << "\n";
return EXIT_SUCCESS;
}

View File

@@ -3,30 +3,27 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Sample output:
//
// Sample output:
// bits(0) = 00
// bits(1) = 01
// bits(2) = 10
// bits(3) = 11
#include <iostream>
#include <boost/dynamic_bitset.hpp>
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;
return EXIT_SUCCESS;
}

View File

@@ -1,71 +1,35 @@
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2008 Gennaro Prota
// (C) Copyright Jeremy Siek 2001.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Sample run:
//
// mask = 101010101010
// x.size() = 0
// Enter a bitset in binary: x = 100100010
//
// Input number: 100100010
// x.size() is now: 9
// As unsigned long: 290
// Mask (possibly resized): 010101010
// And with mask: 000100010
// Or with mask: 110101010
// Shifted left by 1: 001000100
// Shifted right by 1: 010010001
// Sample output:
// mask = 101010101010
// Enter a 12-bit bitset in binary: 100110101101
// x = 100110101101
// As ulong: 2477
// And with mask: 100010101000
// Or with mask: 101110101111
#include "boost/dynamic_bitset.hpp"
#include <ostream>
#include <iostream>
#include <boost/dynamic_bitset.hpp>
int main()
{
boost::dynamic_bitset<> mask(12, 2730ul);
std::cout << "mask = " << mask << std::endl;
int main(int, char*[]) {
const boost::dynamic_bitset<> mask(12, 2730ul);
std::cout << "mask = " << mask << std::endl;
boost::dynamic_bitset<> x;
std::cout << "x.size() = " << x.size() << std::endl;
boost::dynamic_bitset<> x(12);
std::cout << "x.size()=" << x.size() << std::endl;
std::cout << "Enter a bitset in binary: x = " << std::flush;
if (std::cin >> x) {
const std::size_t sz = x.size();
std::cout << std::endl;
std::cout << "Input number: " << x << std::endl;
std::cout << "x.size() is now: " << sz << std::endl;
bool fits_in_ulong = true;
unsigned long ul = 0;
try {
ul = x.to_ulong();
} catch(std::overflow_error &) {
fits_in_ulong = false;
}
std::cout << "As unsigned long: ";
if(fits_in_ulong) {
std::cout << ul;
} else {
std::cout << "(overflow exception)";
}
std::cout << std::endl;
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;
}
return 0;
std::cout << "Enter a 12-bit bitset in binary: " << std::flush;
if (std::cin >> x) {
std::cout << "input number: " << x << std::endl;
std::cout << "As unsigned long: " << x.to_ulong() << std::endl;
std::cout << "And with mask: " << (x & mask) << std::endl;
std::cout << "Or with mask: " << (x | mask) << std::endl;
std::cout << "Shifted left: " << (x << 1) << std::endl;
std::cout << "Shifted right: " << (x >> 1) << std::endl;
}
return EXIT_SUCCESS;
}

View File

@@ -1,6 +1,7 @@
// -----------------------------------------------------------
//
// Copyright (c) 2003-2004 Gennaro Prota
// boost::dynamic_bitset timing tests
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -8,8 +9,6 @@
//
// -----------------------------------------------------------
// boost::dynamic_bitset timing tests
//
// NOTE:
// ~~~~~
// This is a preliminary, incomplete version.
@@ -23,14 +22,11 @@
// table in detail/dynamic_bitset.hpp and report any interesting
// discovery on the list as well.
// You might also want to try both counting methods (by_bytes vs.
// by_blocks) to see if the one that is selected automatically is
// actually the fastest on your system.
//
//
// -----------------------------------------------------------------------//
//
// $Id$
#include "boost/config.hpp"
@@ -59,9 +55,9 @@ namespace {
// see http://gcc.gnu.org/ml/gcc-bugs/1999-03n/msg00884.html
//
class boost_version {
int m_major;
int m_minor;
int m_subminor;
const int m_major;
const int m_minor;
const int m_subminor;
public:
boost_version(unsigned long v = BOOST_VERSION):
@@ -95,11 +91,11 @@ template <typename T>
void timing_test(T* = 0) // dummy parameter to workaround VC6
{
const unsigned long num = 30 * 100000;
const unsigned long num = 100000;
// This variable is printed at the end of the test,
// to prevent the optimizer from removing the call to
// to prevent the optimizer eliminating the call to
// count() in the loop below.
typename boost::dynamic_bitset<T>::size_type dummy = 0;
@@ -127,6 +123,7 @@ void timing_test(T* = 0) // dummy parameter to workaround VC6
int main()
{
prologue();
timing_test<unsigned char>();

View File

@@ -1,10 +1,7 @@
// -----------------------------------------------------------
// --------------------------------------------------
//
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
//
// Copyright (c) 2014 Glen Joseph Fernandes
// glenfe at live dot com
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2006.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -12,11 +9,14 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset/ for documentation.
//
// $Revision$ $Date$ - $Name$
#ifndef BOOST_DETAIL_DYNAMIC_BITSET_HPP
#define BOOST_DETAIL_DYNAMIC_BITSET_HPP
#include <memory>
#include <cstddef>
#include <cstddef> // for std::size_t
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
@@ -24,7 +24,6 @@
namespace boost {
namespace detail {
namespace dynamic_bitset_impl {
// Gives (read-)access to the object representation
// of an object of type T (3.9p4). CANNOT be used
@@ -47,30 +46,13 @@ namespace boost {
// ------- count function implementation --------------
namespace dynamic_bitset_count_impl {
typedef unsigned char byte_type;
// These two entities
//
// enum mode { access_by_bytes, access_by_blocks };
// template <mode> struct mode_to_type {};
//
// were removed, since the regression logs (as of 24 Aug 2008)
// showed that several compilers had troubles with recognizing
//
// const mode m = access_by_bytes
//
// as a constant expression
//
// * So, we'll use bool, instead of enum *.
//
template <bool value>
struct value_to_type
{
value_to_type() {}
};
const bool access_by_bytes = true;
const bool access_by_blocks = false;
enum mode { access_by_bytes, access_by_blocks };
template <mode> struct mode_to_type {};
// the table: wrapped in a class template, so
// that it is only instantiated if/when needed
@@ -105,7 +87,7 @@ namespace boost {
template <typename Iterator>
inline std::size_t do_count(Iterator first, std::size_t length,
int /*dummy param*/,
value_to_type<access_by_bytes>* )
mode_to_type<access_by_bytes>* )
{
std::size_t num = 0;
if (length)
@@ -129,7 +111,7 @@ namespace boost {
//
template <typename Iterator, typename ValueType>
inline std::size_t do_count(Iterator first, std::size_t length, ValueType,
value_to_type<access_by_blocks>*)
mode_to_type<access_by_blocks>*)
{
std::size_t num = 0;
while (length){
@@ -147,6 +129,8 @@ namespace boost {
return num;
}
} // dynamic_bitset_count_impl
// -------------------------------------------------------
@@ -155,84 +139,35 @@ namespace boost {
//
// size_type(-1) / sizeof(T)
//
// from vector<>::max_size. This tries to get more
// from vector<>::max_size. This tries to get out 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;
typename T::size_type vector_max_size_workaround(const T & v) {
const allocator_type& alloc = v.get_allocator();
typedef typename T::allocator_type allocator_type;
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
typedef std::allocator_traits<allocator_type> allocator_traits;
const typename allocator_type::size_type alloc_max =
v.get_allocator().max_size();
const typename T::size_type container_max = v.max_size();
const typename allocator_traits::size_type alloc_max =
allocator_traits::max_size(alloc);
#else
const typename allocator_type::size_type alloc_max = alloc.max_size();
#endif
const typename T::size_type container_max = v.max_size();
return alloc_max < container_max ? alloc_max : container_max;
return alloc_max < container_max?
alloc_max :
container_max;
}
// for static_asserts
template <typename T>
struct allowed_block_type {
struct dynamic_bitset_allowed_block_type {
enum { value = T(-1) > 0 }; // ensure T has no sign
};
template <>
struct allowed_block_type<bool> {
struct dynamic_bitset_allowed_block_type<bool> {
enum { value = false };
};
template <typename T>
struct is_numeric {
enum { value = false };
};
# define BOOST_dynamic_bitset_is_numeric(x) \
template<> \
struct is_numeric< x > { \
enum { value = true }; \
} /**/
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);
#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(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);
#endif
// 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
} // namespace boost

View File

@@ -1,7 +1,7 @@
// -----------------------------------------------------------
// --------------------------------------------------
//
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2004, 2008 Gennaro Prota
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,6 +9,10 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset/ for documentation.
//
// $Revision$ $Date$ - $Name$
#ifndef BOOST_DYNAMIC_BITSET_HPP
#define BOOST_DYNAMIC_BITSET_HPP

View File

@@ -1,7 +1,7 @@
// -----------------------------------------------------------
// --------------------------------------------------
//
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2006.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,6 +9,10 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset/ for documentation.
//
// $Revision$ $Date$ - $Name$
#ifndef BOOST_DYNAMIC_BITSET_CONFIG_HPP_GP_20040424
#define BOOST_DYNAMIC_BITSET_CONFIG_HPP_GP_20040424
@@ -20,13 +24,19 @@
# define BOOST_OLD_IOSTREAMS
#endif
// this should be in the config system some day
// see http://lists.boost.org/MailArchives/boost/msg62291.php
#define BOOST_DYNAMIC_BITSET_GNUC_VERSION ( __GNUC__ * 100 * 100 \
+ __GNUC_MINOR__ * 100)
// no-op function to workaround gcc bug c++/8419
//
namespace boost { namespace detail {
template <typename T> T make_non_const(T t) { return t; }
}}
#if defined(__GNUC__)
#if defined(__GNUC__) && BOOST_WORKAROUND(BOOST_DYNAMIC_BITSET_GNUC_VERSION, \
BOOST_TESTED_AT(30300))
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(expr) \
(boost::detail::make_non_const(expr))
#else

View File

@@ -1,12 +1,7 @@
// -----------------------------------------------------------
// --------------------------------------------------
//
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
//
// Copyright (c) 2014 Glen Joseph Fernandes
// glenfe at live dot com
// Copyright (c) 2014 Riccardo Marcangelo
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2006.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -14,13 +9,18 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset/ for documentation.
//
// $Revision$ $Date$ - $Name$
#ifndef BOOST_DYNAMIC_BITSET_DYNAMIC_BITSET_HPP
#define BOOST_DYNAMIC_BITSET_DYNAMIC_BITSET_HPP
#include <assert.h>
#include <string>
#include <stdexcept>
#include <algorithm>
#include <stdexcept> // for std::overflow_error
#include <algorithm> // for std::swap, min, copy, fill
#include <vector>
#include <climits> // for CHAR_BIT
@@ -41,36 +41,35 @@
#include "boost/dynamic_bitset_fwd.hpp"
#include "boost/detail/dynamic_bitset.hpp"
#include "boost/detail/iterator.hpp" // used to implement append(Iter, Iter)
#include "boost/move/move.hpp"
#include "boost/limits.hpp"
#include "boost/pending/lowest_bit.hpp"
#include "boost/static_assert.hpp"
#include "boost/utility/addressof.hpp"
#include "boost/detail/no_exceptions_support.hpp"
#include "boost/throw_exception.hpp"
#include "boost/limits.hpp"
#include "boost/pending/lowest_bit.hpp" // used by find_first/next
namespace boost {
template <typename Block, typename Allocator>
template
#if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, <= 1300) // 1300 == VC++ 7.0
// VC++ (up to 7.0) wants the default arguments again
<typename Block = unsigned long, typename Allocator = std::allocator<Block> >
# else
<typename Block, typename Allocator>
# endif
class dynamic_bitset
{
// Portability note: member function templates are defined inside
// this class definition to avoid problems with VC++. Similarly,
// with the member functions of nested classes.
//
// [October 2008: the note above is mostly historical; new versions
// of VC++ are likely able to digest a more drinking form of the
// code; but changing it now is probably not worth the risks...]
// Portability note: member function templates are defined inside
// this class definition to avoid problems with VC++. Similarly,
// with the member functions of nested classes.
BOOST_STATIC_ASSERT((bool)detail::dynamic_bitset_impl::allowed_block_type<Block>::value);
typedef std::vector<Block, Allocator> buffer_type;
BOOST_STATIC_ASSERT(detail::dynamic_bitset_allowed_block_type<Block>::value);
public:
typedef Block block_type;
typedef Allocator allocator_type;
typedef std::size_t size_type;
typedef typename buffer_type::size_type block_width_type;
typedef int 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));
@@ -86,12 +85,9 @@ public:
// the one and only non-copy ctor
reference(block_type & b, block_type pos)
:m_block(b),
m_mask( (assert(pos < bits_per_block),
block_type(1) << pos )
)
{ }
reference(block_type & b, int pos)
:m_block(b), m_mask(block_type(1) << pos)
{ assert(pos >= 0 && pos < bits_per_block); }
void operator&(); // left undefined
@@ -175,39 +171,10 @@ public:
dynamic_bitset(BlockInputIterator first, BlockInputIterator last,
const Allocator& alloc = Allocator())
:m_bits(alloc),
m_num_bits(0)
{
using boost::detail::dynamic_bitset_impl::value_to_type;
using boost::detail::dynamic_bitset_impl::is_numeric;
:m_bits(first, last, alloc),
m_num_bits(m_bits.size() * bits_per_block)
{}
const value_to_type<
is_numeric<BlockInputIterator>::value> selector;
dispatch_init(first, last, selector);
}
template <typename T>
void dispatch_init(T num_bits, unsigned long value,
detail::dynamic_bitset_impl::value_to_type<true>)
{
init_from_unsigned_long(static_cast<size_type>(num_bits), value);
}
template <typename T>
void dispatch_init(T first, T last,
detail::dynamic_bitset_impl::value_to_type<false>)
{
init_from_block_range(first, last);
}
template <typename BlockIter>
void init_from_block_range(BlockIter first, BlockIter last)
{
assert(m_bits.size() == 0);
m_bits.insert(m_bits.end(), first, last);
m_num_bits = m_bits.size() * bits_per_block;
}
// copy constructor
dynamic_bitset(const dynamic_bitset& b);
@@ -217,18 +184,12 @@ public:
void swap(dynamic_bitset& b);
dynamic_bitset& operator=(const dynamic_bitset& b);
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
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 clear();
void push_back(bool bit);
void pop_back();
void append(Block block);
template <typename BlockInputIterator>
@@ -286,12 +247,10 @@ public:
dynamic_bitset& flip(size_type n);
dynamic_bitset& flip();
bool test(size_type n) const;
bool test_set(size_type n, bool val = true);
bool all() const;
bool any() const;
bool none() const;
dynamic_bitset operator~() const;
size_type count() const BOOST_NOEXCEPT;
size_type count() const;
// subscript
reference operator[](size_type pos) {
@@ -301,13 +260,10 @@ public:
unsigned long to_ulong() const;
size_type size() const BOOST_NOEXCEPT;
size_type num_blocks() const BOOST_NOEXCEPT;
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 shrink_to_fit();
size_type size() const;
size_type num_blocks() const;
size_type max_size() const;
bool empty() const;
bool is_subset_of(const dynamic_bitset& a) const;
bool is_proper_subset_of(const dynamic_bitset& a) const;
@@ -348,23 +304,20 @@ public:
#endif
public:
// 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);
typedef std::vector<block_type, allocator_type> buffer_type;
void m_zero_unused_bits();
bool m_check_invariants() const;
size_type m_do_find_from(size_type first_block) const;
block_width_type count_extra_bits() const BOOST_NOEXCEPT { return bit_index(size()); }
static size_type block_index(size_type pos) BOOST_NOEXCEPT { return pos / bits_per_block; }
static block_width_type bit_index(size_type pos) BOOST_NOEXCEPT { return static_cast<block_width_type>(pos % bits_per_block); }
static Block bit_mask(size_type pos) BOOST_NOEXCEPT { return Block(1) << bit_index(pos); }
block_width_type count_extra_bits() const { return bit_index(size()); }
static size_type block_index(size_type pos) { return pos / bits_per_block; }
static block_width_type bit_index(size_type pos) { return static_cast<int>(pos % bits_per_block); }
static Block bit_mask(size_type pos) { return Block(1) << bit_index(pos); }
template <typename CharT, typename Traits, typename Alloc>
void init_from_string(const std::basic_string<CharT, Traits, Alloc>& s,
@@ -402,39 +355,6 @@ private:
}
void init_from_unsigned_long(size_type num_bits,
unsigned long value/*,
const Allocator& alloc*/)
{
assert(m_bits.size() == 0);
m_bits.resize(calc_num_blocks(num_bits));
m_num_bits = num_bits;
typedef unsigned long num_type;
typedef boost::detail::dynamic_bitset_impl
::shifter<num_type, bits_per_block, ulong_width> shifter;
//if (num_bits == 0)
// return;
// zero out all bits at pos >= num_bits, if any;
// note that: num_bits == 0 implies value == 0
if (num_bits < static_cast<size_type>(ulong_width)) {
const num_type mask = (num_type(1) << num_bits) - 1;
value &= mask;
}
typename buffer_type::iterator it = m_bits.begin();
for( ; value; shifter::left_shift(value), ++it) {
*it = static_cast<block_type>(value);
}
}
BOOST_DYNAMIC_BITSET_PRIVATE:
bool m_unchecked_test(size_type pos) const;
@@ -463,11 +383,6 @@ BOOST_DYNAMIC_BITSET_PRIVATE:
size_type n;
Block mask;
Block * current;
// not implemented
bit_appender(const bit_appender &);
bit_appender & operator=(const bit_appender &);
public:
bit_appender(dynamic_bitset & r) : bs(r), n(0), mask(0), current(0) {}
~bit_appender() {
@@ -500,18 +415,24 @@ BOOST_DYNAMIC_BITSET_PRIVATE:
};
#if !defined BOOST_NO_INCLASS_MEMBER_INITIALIZATION
#if defined(__IBMCPP__) && BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))
template <typename Block, typename Allocator>
const typename dynamic_bitset<Block, Allocator>::block_width_type
// Workaround for IBM's AIX platform.
// See http://comments.gmane.org/gmane.comp.lib.boost.user/15331
//
// NOTE:
// The compiler is actually right, until core issue 454 will be settled:
// http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_active.html#454
//
// It's arguable whether we want to mark this with BOOST_WORKAROUND or not.
template<typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>::block_width_type const
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>::block_width_type
template<typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>::block_width_type const
dynamic_bitset<Block, Allocator>::ulong_width;
#endif
@@ -618,10 +539,28 @@ dynamic_bitset<Block, Allocator>::dynamic_bitset(const Allocator& alloc)
template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>::
dynamic_bitset(size_type num_bits, unsigned long value, const Allocator& alloc)
: m_bits(alloc),
m_num_bits(0)
: m_bits(calc_num_blocks(num_bits), Block(0), alloc),
m_num_bits(num_bits)
{
init_from_unsigned_long(num_bits, value);
typedef unsigned long num_type;
typedef boost::detail::shifter<num_type, bits_per_block, ulong_width> shifter;
//if (num_bits == 0)
// return;
// zero out all bits at pos >= num_bits, if any;
// note that: num_bits == 0 implies value == 0
if (num_bits < static_cast<size_type>(ulong_width)) {
const num_type mask = (num_type(1) << num_bits) - 1;
value &= mask;
}
typename buffer_type::iterator it = m_bits.begin();
for( ; value; shifter::left_shift(value), ++it) {
*it = static_cast<block_type>(value);
}
}
// copy constructor
@@ -657,34 +596,6 @@ operator=(const dynamic_bitset<Block, Allocator>& b)
return *this;
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename Block, typename Allocator>
inline dynamic_bitset<Block, Allocator>::
dynamic_bitset(dynamic_bitset<Block, Allocator>&& b)
: m_bits(boost::move(b.m_bits)), m_num_bits(boost::move(b.m_num_bits))
{
// Required so that assert(m_check_invariants()); works.
assert((b.m_bits = buffer_type()).empty());
b.m_num_bits = 0;
}
template <typename Block, typename Allocator>
inline dynamic_bitset<Block, Allocator>& dynamic_bitset<Block, Allocator>::
operator=(dynamic_bitset<Block, Allocator>&& b)
{
if (boost::addressof(b) == this) { return *this; }
m_bits = boost::move(b.m_bits);
m_num_bits = boost::move(b.m_num_bits);
// Required so that assert(m_check_invariants()); works.
assert((b.m_bits = buffer_type()).empty());
b.m_num_bits = 0;
return *this;
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::allocator_type
dynamic_bitset<Block, Allocator>::get_allocator() const
@@ -722,7 +633,7 @@ resize(size_type num_bits, bool value) // strong guarantee
if (value && (num_bits > m_num_bits)) {
const block_width_type extra_bits = count_extra_bits();
const size_type extra_bits = count_extra_bits();
if (extra_bits) {
assert(old_num_blocks >= 1 && old_num_blocks <= m_bits.size());
@@ -755,22 +666,6 @@ push_back(bool bit)
set(sz, bit);
}
template <typename Block, typename Allocator>
void dynamic_bitset<Block, Allocator>::
pop_back()
{
const size_type old_num_blocks = num_blocks();
const size_type required_blocks = calc_num_blocks(m_num_bits - 1);
if (required_blocks != old_num_blocks) {
m_bits.pop_back();
}
--m_num_bits;
m_zero_unused_bits();
}
template <typename Block, typename Allocator>
void dynamic_bitset<Block, Allocator>::
append(Block value) // strong guarantee
@@ -874,12 +769,27 @@ dynamic_bitset<Block, Allocator>::operator<<=(size_type n)
b[div] = b[0];
}
// disable std::fill_n deprecated warning in MSVC++ 8.0 (warning C4996)
// This will only work in MSVC++ 8.0 SP1, which brings up the warning
// in the line of user code; otherwise, the warning will come up
// in the line in the header itself, so if the user includes stdlib
// headers before dynamic_bitset, he will still get the warning.
#if defined(_MSC_VER) && _MSC_VER >= 1400
#pragma warning(push)
#pragma warning(disable:4996)
#endif
// zero out div blocks at the less significant end
std::fill_n(m_bits.begin(), div, static_cast<block_type>(0));
std::fill_n(b, div, static_cast<block_type>(0));
#if defined(_MSC_VER) && _MSC_VER >= 1400
#pragma warning(pop)
#endif
// zero out any 1 bit that flowed into the unused part
m_zero_unused_bits(); // thanks to Lester Gong
}
return *this;
@@ -928,7 +838,7 @@ dynamic_bitset<B, A> & dynamic_bitset<B, A>::operator>>=(size_type n) {
// div blocks are zero filled at the most significant end
std::fill_n(m_bits.begin() + (num_blocks()-div), div, static_cast<block_type>(0));
std::fill_n(b + (num_blocks()-div), div, static_cast<block_type>(0));
}
return *this;
@@ -1034,46 +944,6 @@ bool dynamic_bitset<Block, Allocator>::test(size_type pos) const
return m_unchecked_test(pos);
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::test_set(size_type pos, bool val)
{
bool const b = test(pos);
if (b != val) {
set(pos, val);
}
return b;
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::all() const
{
if (empty()) {
return true;
}
const block_width_type extra_bits = count_extra_bits();
block_type const all_ones = ~static_cast<Block>(0);
if (extra_bits == 0) {
for (size_type i = 0, e = num_blocks(); i < e; ++i) {
if (m_bits[i] != all_ones) {
return false;
}
}
} else {
for (size_type i = 0, e = num_blocks() - 1; i < e; ++i) {
if (m_bits[i] != all_ones) {
return false;
}
}
block_type const mask = ~(~static_cast<Block>(0) << extra_bits);
if (m_highest_block() != mask) {
return false;
}
}
return true;
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::any() const
{
@@ -1098,35 +968,21 @@ dynamic_bitset<Block, Allocator>::operator~() const
return b;
}
template <typename Block, typename Allocator>
typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::count() const BOOST_NOEXCEPT
dynamic_bitset<Block, Allocator>::count() const
{
using detail::dynamic_bitset_impl::table_width;
using detail::dynamic_bitset_impl::access_by_bytes;
using detail::dynamic_bitset_impl::access_by_blocks;
using detail::dynamic_bitset_impl::value_to_type;
using namespace detail::dynamic_bitset_count_impl;
#if BOOST_WORKAROUND(__GNUC__, == 4) && (__GNUC_MINOR__ == 3) && (__GNUC_PATCHLEVEL__ == 3)
// NOTE: Explicit qualification of "bits_per_block"
// breaks compilation on gcc 4.3.3
enum { no_padding = bits_per_block == CHAR_BIT * sizeof(Block) };
#else
// NOTE: Explicitly qualifying "bits_per_block" to workaround
// regressions of gcc 3.4.x
enum { no_padding =
dynamic_bitset<Block, Allocator>::bits_per_block
== CHAR_BIT * sizeof(Block) };
#endif
const bool no_padding = bits_per_block == CHAR_BIT * sizeof(Block);
const bool enough_table_width = table_width >= CHAR_BIT;
enum { enough_table_width = table_width >= CHAR_BIT };
typedef mode_to_type< (no_padding && enough_table_width ?
access_by_bytes : access_by_blocks) > m;
enum { mode = (no_padding && enough_table_width)
? access_by_bytes
: access_by_blocks };
return do_count(m_bits.begin(), num_blocks(), Block(0), static_cast<m*>(0));
return do_count(m_bits.begin(), num_blocks(), Block(0),
static_cast<value_to_type<(bool)mode> *>(0));
}
@@ -1209,46 +1065,53 @@ to_ulong() const
// Check for overflows. This may be a performance burden on very
// large bitsets but is required by the specification, sorry
if (find_next(ulong_width - 1) != npos)
BOOST_THROW_EXCEPTION(std::overflow_error("boost::dynamic_bitset::to_ulong overflow"));
throw std::overflow_error("boost::dynamic_bitset::to_ulong overflow");
// Ok, from now on we can be sure there's no "on" bit
// beyond the "allowed" positions
typedef unsigned long result_type;
const size_type maximum_size =
(std::min)(m_num_bits, static_cast<size_type>(ulong_width));
/*
if find_next() did its job correctly we don't need the if
below, because all bits we care about are in the first block
const size_type last_block = block_index( maximum_size - 1 );
assert((last_block * bits_per_block) < static_cast<size_type>(ulong_width));
if (bits_per_block >= ulong_width)
return static_cast<result_type>(m_bits[0]);
*/
size_type last_block = block_index(
(std::min)( m_num_bits, (size_type)ulong_width ) - 1 );
result_type result = 0;
for (size_type i = 0; i <= last_block; ++i) {
const size_type offset = i * bits_per_block;
result |= (static_cast<result_type>(m_bits[i]) << offset);
assert((size_type)bits_per_block * i < (size_type)ulong_width);
unsigned long piece = m_bits[i];
result |= (piece << (bits_per_block * i));
}
return result;
}
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::size() const BOOST_NOEXCEPT
dynamic_bitset<Block, Allocator>::size() const
{
return m_num_bits;
}
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::num_blocks() const BOOST_NOEXCEPT
dynamic_bitset<Block, Allocator>::num_blocks() const
{
return m_bits.size();
}
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::max_size() const BOOST_NOEXCEPT
dynamic_bitset<Block, Allocator>::max_size() const
{
// Semantics of vector<>::max_size() aren't very clear
// (see lib issue 197) and many library implementations
@@ -1260,8 +1123,7 @@ dynamic_bitset<Block, Allocator>::max_size() const BOOST_NOEXCEPT
// his own allocator.
//
const size_type m = detail::dynamic_bitset_impl::
vector_max_size_workaround(m_bits);
const size_type m = detail::vector_max_size_workaround(m_bits);
return m <= (size_type(-1)/bits_per_block) ?
m * bits_per_block :
@@ -1269,32 +1131,11 @@ dynamic_bitset<Block, Allocator>::max_size() const BOOST_NOEXCEPT
}
template <typename Block, typename Allocator>
inline bool dynamic_bitset<Block, Allocator>::empty() const BOOST_NOEXCEPT
inline bool dynamic_bitset<Block, Allocator>::empty() const
{
return size() == 0;
}
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::capacity() const BOOST_NOEXCEPT
{
return m_bits.capacity() * bits_per_block;
}
template <typename Block, typename Allocator>
inline void dynamic_bitset<Block, Allocator>::reserve(size_type num_bits)
{
m_bits.reserve(calc_num_blocks(num_bits));
}
template <typename Block, typename Allocator>
void dynamic_bitset<Block, Allocator>::shrink_to_fit()
{
if (m_bits.size() < m_bits.capacity()) {
buffer_type(m_bits).swap(m_bits);
}
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::
is_subset_of(const dynamic_bitset<Block, Allocator>& a) const
@@ -1359,7 +1200,7 @@ dynamic_bitset<Block, Allocator>::m_do_find_from(size_type first_block) const
if (i >= num_blocks())
return npos; // not found
return i * bits_per_block + static_cast<size_type>(boost::lowest_bit(m_bits[i]));
return i * bits_per_block + boost::lowest_bit(m_bits[i]);
}
@@ -1386,11 +1227,11 @@ dynamic_bitset<Block, Allocator>::find_next(size_type pos) const
const size_type blk = block_index(pos);
const block_width_type ind = bit_index(pos);
// shift bits upto one immediately after current
const Block fore = m_bits[blk] >> ind;
// mask out bits before pos
const Block fore = m_bits[blk] & ( ~Block(0) << ind );
return fore?
pos + static_cast<size_type>(lowest_bit(fore))
blk * bits_per_block + lowest_bit(fore)
:
m_do_find_from(blk + 1);
@@ -1551,20 +1392,19 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
const Ch zero = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '0');
const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1');
BOOST_TRY {
try {
typedef typename dynamic_bitset<Block, Alloc>::size_type bitset_size_type;
typedef typename dynamic_bitset<Block, Alloc>::size_type bitsetsize_type;
typedef basic_streambuf<Ch, Tr> buffer_type;
buffer_type * buf = os.rdbuf();
// careful: os.width() is signed (and can be < 0)
const bitset_size_type width = (os.width() <= 0) ? 0 : static_cast<bitset_size_type>(os.width());
streamsize npad = (width <= b.size()) ? 0 : width - b.size();
size_t npad = os.width() <= 0 // careful: os.width() is signed (and can be < 0)
|| (bitsetsize_type) os.width() <= b.size()? 0 : os.width() - b.size();
const Ch fill_char = os.fill();
const ios_base::fmtflags adjustfield = os.flags() & ios_base::adjustfield;
// if needed fill at left; pad is decreased along the way
// if needed fill at left; pad is decresed along the way
if (adjustfield != ios_base::left) {
for (; 0 < npad; --npad)
if (Tr::eq_int_type(Tr::eof(), buf->sputc(fill_char))) {
@@ -1575,7 +1415,7 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
if (err == ok) {
// output the bitset
for (bitset_size_type i = b.size(); 0 < i; --i) {
for (bitsetsize_type i = b.size(); 0 < i; --i) {
typename buffer_type::int_type
ret = buf->sputc(b.test(i-1)? one : zero);
if (Tr::eq_int_type(Tr::eof(), ret)) {
@@ -1598,14 +1438,13 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
os.width(0);
} BOOST_CATCH (...) { // see std 27.6.1.1/4
} catch (...) { // see std 27.6.1.1/4
bool rethrow = false;
BOOST_TRY { os.setstate(ios_base::failbit); } BOOST_CATCH (...) { rethrow = true; } BOOST_CATCH_END
try { os.setstate(ios_base::failbit); } catch (...) { rethrow = true; }
if (rethrow)
BOOST_RETHROW;
throw;
}
BOOST_CATCH_END
}
if(err != ok)
@@ -1651,7 +1490,7 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
const std::streamsize w = is.width();
const size_type limit = w > 0 && static_cast<size_type>(w) < b.max_size()
? static_cast<size_type>(w) : b.max_size();
? w : b.max_size();
typename bitset_type::bit_appender appender(b);
std::streambuf * buf = is.rdbuf();
for(int c = buf->sgetc(); appender.get_count() < limit; c = buf->snextc() ) {
@@ -1664,14 +1503,13 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
break; // non digit character
else {
BOOST_TRY {
try {
appender.do_append(char(c) == '1');
}
BOOST_CATCH(...) {
catch(...) {
is.setstate(std::ios::failbit); // assume this can't throw
BOOST_RETHROW;
throw;
}
BOOST_CATCH_END
}
} // for
@@ -1700,7 +1538,7 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
const streamsize w = is.width();
const size_type limit = 0 < w && static_cast<size_type>(w) < b.max_size()?
static_cast<size_type>(w) : b.max_size();
w : b.max_size();
ios_base::iostate err = ios_base::goodbit;
typename basic_istream<Ch, Tr>::sentry cerberos(is); // skips whitespaces
@@ -1712,7 +1550,7 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1');
b.clear();
BOOST_TRY {
try {
typename bitset_type::bit_appender appender(b);
basic_streambuf <Ch, Tr> * buf = is.rdbuf();
typename Tr::int_type c = buf->sgetc();
@@ -1735,7 +1573,7 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
} // for
}
BOOST_CATCH (...) {
catch (...) {
// catches from stream buf, or from vector:
//
// bits_stored bits have been extracted and stored, and
@@ -1743,15 +1581,13 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
// append to the underlying vector (out of memory)
bool rethrow = false; // see std 27.6.1.1/4
BOOST_TRY { is.setstate(ios_base::badbit); }
BOOST_CATCH(...) { rethrow = true; }
BOOST_CATCH_END
try { is.setstate(ios_base::badbit); }
catch(...) { rethrow = true; }
if (rethrow)
BOOST_RETHROW;
throw;
}
BOOST_CATCH_END
}
is.width(0);
@@ -1828,7 +1664,7 @@ inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::calc_num_blocks(size_type num_bits)
{
return num_bits / bits_per_block
+ static_cast<size_type>( num_bits % bits_per_block != 0 );
+ static_cast<int>( num_bits % bits_per_block != 0 );
}
// gives a reference to the highest block

View File

@@ -1,46 +0,0 @@
// -----------------------------------------------------------
//
// Copyright (c) 2015 Seth Heeren
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
#ifndef BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
#define BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include <boost/serialization/vector.hpp>
namespace boost {
// 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) {
ar & serialization::make_nvp("m_num_bits", bs.m_num_bits)
& serialization::make_nvp("m_bits", bs.m_bits);
}
};
}
// ADL hook to Boost Serialization library
namespace boost {
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);
}
} // namespace serialization
} // namespace boost
#endif // include guard

View File

@@ -1,7 +1,7 @@
// -----------------------------------------------------------
// --------------------------------------------------
//
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2004 Gennaro Prota
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,6 +9,10 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset/ for documentation.
//
// $Revision$ $Date$ - $Name$
#ifndef BOOST_DYNAMIC_BITSET_FWD_HPP
#define BOOST_DYNAMIC_BITSET_FWD_HPP
@@ -20,6 +24,6 @@ template <typename Block = unsigned long,
typename Allocator = std::allocator<Block> >
class dynamic_bitset;
}
} // namespace boost
#endif // include guard

View File

@@ -1,15 +1,17 @@
// -----------------------------------------------------------
// -------------------------------------
// lowest_bit.hpp
//
// Position of the lowest bit 'on'
//
// Copyright (c) 2003-2004, 2008 Gennaro Prota
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
// ------------------------------------------------------
//
// $Id$
#ifndef BOOST_LOWEST_BIT_HPP_GP_20030301
#define BOOST_LOWEST_BIT_HPP_GP_20030301

View File

@@ -1,16 +0,0 @@
{
"key": "dynamic_bitset",
"name": "Dynamic Bitset",
"authors": [
"Jeremy Siek",
"Chuck Allison"
],
"description": "The dynamic_bitset class represents a set of bits. It provides accesses to the value of individual bits via an operator[] and provides all of the bitwise operators that one can apply to builtin integers, such as operator& and operator<<. The number of bits in the set is specified at runtime via a parameter to the constructor of the dynamic_bitset.",
"documentation": "dynamic_bitset.html",
"category": [
"Containers"
],
"maintainers": [
"Jeremy Siek <jeremy.siek -at- gmail.com>"
]
}

View File

@@ -1,111 +0,0 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
//
// Copyright (c) 2015 Seth Heeren
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
#include "boost/config.hpp"
#if !defined (BOOST_NO_STRINGSTREAM)
# include <sstream>
#endif
#include "bitset_test.hpp"
#include "boost/dynamic_bitset/serialization.hpp"
#include "boost/detail/workaround.hpp"
// 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
#if defined BOOST_NO_STD_WSTRING || defined BOOST_NO_STD_LOCALE
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
#endif
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <sstream>
namespace {
template <typename Block>
struct SerializableType {
boost::dynamic_bitset<Block> x;
private:
friend class boost::serialization::access;
template <class Archive> void serialize(Archive &ar, const unsigned int) {
ar & BOOST_SERIALIZATION_NVP(x);
}
};
template <typename Block, typename IArchive, typename OArchive>
void test_serialization( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
{
SerializableType<Block> a;
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);
}
// test de-serialization
{
IArchive ia(ss);
SerializableType<Block> b;
ia >> BOOST_SERIALIZATION_NVP(b);
assert(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) )
{
test_binary_archive<Block>();
test_xml_archive<Block>();
}
int test_main(int, char*[])
{
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 0;
}