Compare commits

..

1 Commits

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

View File

@@ -1,12 +1,14 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006, 2008 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$
#ifndef BOOST_BITSET_TEST_HPP_GP_20040319
#define BOOST_BITSET_TEST_HPP_GP_20040319
@@ -108,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(num_bits, 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);
}
@@ -989,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
@@ -1069,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

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 "bitset_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
@@ -15,7 +17,7 @@
#include "boost/detail/workaround.hpp"
#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.
@@ -54,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), mi/2, mi,
0, 1, 3, 8, 15, ma/2, 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) )
{
@@ -117,52 +69,24 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
//=====================================================================
// Test construction from unsigned long
{
typedef typename bitset_type::size_type size_type;
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)();
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 };
// 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 };
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 s = 0; s < BOOST_BITSET_TEST_COUNT(sizes); ++s) {
for (std::size_t v = 0; v < BOOST_BITSET_TEST_COUNT(values); ++v) {
Tests::from_unsigned_long(sizes[s], values[v]);
Tests::from_unsigned_long(sizes[s] != 0, values[v]);
for (std::size_t 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

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 "bitset_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"

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 <assert.h>
#include "bitset_test.hpp"

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.
@@ -26,7 +25,8 @@
//
//
// -----------------------------------------------------------------------//
//
// $Id$
#include "boost/config.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,10 +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 <cstddef>
#include <cstddef> // for std::size_t
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
@@ -20,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
@@ -43,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
@@ -101,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)
@@ -125,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){
@@ -143,6 +129,8 @@ namespace boost {
return num;
}
} // dynamic_bitset_count_impl
// -------------------------------------------------------
@@ -151,7 +139,7 @@ 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>
@@ -170,57 +158,16 @@ namespace boost {
// 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,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,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
@@ -38,29 +43,33 @@
#include "boost/detail/iterator.hpp" // used to implement append(Iter, Iter)
#include "boost/static_assert.hpp"
#include "boost/limits.hpp"
#include "boost/pending/lowest_bit.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...]
BOOST_STATIC_ASSERT(detail::dynamic_bitset_impl::allowed_block_type<Block>::value);
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 block_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));
@@ -76,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
@@ -165,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);
@@ -339,7 +316,7 @@ private:
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<block_width_type>(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>
@@ -378,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;
@@ -439,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() {
@@ -476,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
@@ -594,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
@@ -806,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(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;
@@ -990,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
{
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));
}
@@ -1108,22 +1072,29 @@ to_ulong() const
// beyond the "allowed" positions
typedef unsigned long result_type;
const size_type max_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( max_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
@@ -1152,8 +1123,7 @@ dynamic_bitset<Block, Allocator>::max_size() const
// 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 :

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