Compare commits

..

15 Commits

Author SHA1 Message Date
Marshall Clow
c803e3d367 Release 1.53.0
[SVN r82734]
2013-02-04 18:11:49 +00:00
Marshall Clow
f44fbae9ba Merge fixes to release; Fixes #5439
[SVN r72331]
2011-06-01 15:59:04 +00:00
Steven Watanabe
e6fc8e8ec9 Merge dynamic_bitset from the trunk
[SVN r67617]
2011-01-03 16:38:46 +00:00
Troy D. Straszheim
d77a2c4afa rm cmake from the release branch before it goes out broken. Policy dictates that you never commit to release, you commit to trunk and merge to release.
[SVN r56941]
2009-10-17 01:10:45 +00:00
Troy D. Straszheim
e3a2ca7276 Add basic copyright/license to keep cmake out of the inspection report
[SVN r55095]
2009-07-22 21:51:01 +00:00
Daniel James
38819630fd Merge dynamic bitset fixes for gcc 4.3.3.
Merged revisions 52879-52881,53050 via svnmerge from 
https://svn.boost.org/svn/boost/trunk

........
  r52879 | hkaiser | 2009-05-10 17:52:14 +0100 (Sun, 10 May 2009) | 1 line
  
  Applying patch fixing problem on certain patch levels for gcc.4.3.3/Ubuntu
........
  r52880 | hkaiser | 2009-05-10 17:55:07 +0100 (Sun, 10 May 2009) | 1 line
  
  Fixing the fix by taking into account __GNUC_PATCHLEVEL__ as well
........
  r52881 | hkaiser | 2009-05-10 17:59:27 +0100 (Sun, 10 May 2009) | 1 line
  
  Minor comment edit
........
  r53050 | danieljames | 2009-05-16 15:58:33 +0100 (Sat, 16 May 2009) | 13 lines
  
  Merge dynamic bitset from release.
  
  I think the recent changes in trunk and release were for the same problem. But
  I'm not sure so I've merged them together. Hopefully, the release branch might
  fix the Intel C++ errors as well.
  
  ------------------------------------------------------------------------
  r52960 | dgregor | 2009-05-13 07:11:03 +0100 (Wed, 13 May 2009) | 1 line
  
  Use enum constants rather than local variables for integral constants. Should fix dynamic_bitset failures on GCC 4.3.x
  ------------------------------------------------------------------------
........


[SVN r53259]
2009-05-25 20:26:02 +00:00
Douglas Gregor
6d0f9801f5 Use enum constants rather than local variables for integral constants. Should fix dynamic_bitset failures on GCC 4.3.x
[SVN r52960]
2009-05-13 06:11:03 +00:00
Troy D. Straszheim
b7eedd0f46 merge of cmake build files from trunk per beman
[SVN r50756]
2009-01-24 18:57:20 +00:00
Gennaro Prota
16ca9cbb3c dynamic_bitset: ported revisions 49433, 49586 from trunk
[SVN r50470]
2009-01-04 23:03:28 +00:00
Gennaro Prota
4efeaee302 dynamic_bitset: full (recursive) sync with trunk for libs/dynamic_bitset/
[SVN r49423]
2008-10-21 17:57:39 +00:00
Gennaro Prota
066e7dcf71 dynamic_bitset:
ported revisions 49345-49346 (roughly: workaround for VC++ <= 7.0 removal, comment and documentation improvements) from trunk

[SVN r49378]
2008-10-18 11:04:39 +00:00
Gennaro Prota
6b0d9627a8 Ported *all* my trunk changes not yet merged so far, i.e. revisions 48251-48252,48280,48290,48350,48478,48496,48663-48664,48695,48729-48730; besides dynamic_bitset, these include fixes to setup_boostbook.sh and setup_boostbook.py, and changes to config/suffix.hpp [So: the affected "elements" are: a) the two setup_boostbook scripts, config/suffix.hpp and dynamic_bitset --note: yes, the list is exhaustive: all and only]
[SVN r48773]
2008-09-14 10:46:28 +00:00
Gennaro Prota
bddf77e5a4 boost/pending/: ported revision 48251 ("integer_log2.hpp and lowest_bit.hpp, in boost/pending/: little comment cleanup (svn anchors, etc.); added a static_cast<> to silence (harmless) MSVC++ warnings") from trunk
[SVN r48353]
2008-08-24 18:16:24 +00:00
Gennaro Prota
357e434387 dynamic_bitset.hpp: (minor) removed tab characters introduced with revision 35066 on trunk
[SVN r47666]
2008-07-21 23:46:39 +00:00
Gennaro Prota
d8b2330d42 dynamic_bitset.html: Documentation: dropped all sentences of the kind "note that the expression... is equivalent to creating a temporary copy and then...". They seem to be just a sort of performance warning and carry no useful information. This fixes issue #1591.
[SVN r47328]
2008-07-11 21:21:14 +00:00
17 changed files with 927 additions and 849 deletions

View File

@@ -1,14 +1,12 @@
// --------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2006.
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
//
// 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,32 +108,43 @@ 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);
static void from_unsigned_long(std::size_t sz, unsigned long num)
// 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)
{
// 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)
// 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
//
// - if M < N remaining bit positions are initialized to zero
Bitset b(sz, num);
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);
BOOST_CHECK(b.size() == sz);
const std::size_t ulong_width = std::numeric_limits<unsigned long>::digits;
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));
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));
for ( ; i < sz; ++i)
BOOST_CHECK(b.test(i) == 0);
}
@@ -980,7 +989,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
@@ -1060,7 +1069,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,14 +1,12 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2006.
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
//
// 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"
@@ -17,7 +15,7 @@
#include "boost/detail/workaround.hpp"
#define BOOST_BITSET_TEST_COUNT_OF(x) (sizeof(x)/sizeof(x[0]))
#define BOOST_BITSET_TEST_COUNT(x) (sizeof(x)/sizeof(x[0]))
// Codewarrior 8.3 for Win fails without this.
@@ -56,6 +54,56 @@ 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) )
{
@@ -69,24 +117,52 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
//=====================================================================
// Test construction from unsigned long
{
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)();
typedef typename bitset_type::size_type size_type;
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);
// 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 };
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]);
for (std::size_t s = 0; s < BOOST_BITSET_TEST_COUNT(sizes); ++s) {
for (std::size_t v = 0; v < BOOST_BITSET_TEST_COUNT(values); ++v) {
Tests::from_unsigned_long(sizes[s], values[v]);
Tests::from_unsigned_long(sizes[s] != 0, values[v]);
}
}
run_numeric_ctor_tests<Tests, char>();
#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,14 +1,12 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2006.
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
//
// 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,14 +1,12 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2006.
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
//
// 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,14 +1,12 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2006.
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
//
// 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,13 +1,11 @@
// (C) Copyright Gennaro Prota 2002
// -----------------------------------------------------------
// Copyright (c) 2002 Gennaro Prota
//
// 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,23 +3,33 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Sample output:
// 1
// 1
// 0
// 0
// 1
// 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
// ---------------------------------------------------------------------
#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 EXIT_SUCCESS;
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;
}

View File

@@ -3,27 +3,30 @@
// 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 EXIT_SUCCESS;
return 0;
}

View File

@@ -1,35 +1,71 @@
// (C) Copyright Jeremy Siek 2001.
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2008 Gennaro Prota
// 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 output:
// mask = 101010101010
// Enter a 12-bit bitset in binary: 100110101101
// x = 100110101101
// As ulong: 2477
// And with mask: 100010101000
// Or with mask: 101110101111
// 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
#include "boost/dynamic_bitset.hpp"
#include <ostream>
#include <iostream>
#include <boost/dynamic_bitset.hpp>
int main(int, char*[]) {
const boost::dynamic_bitset<> mask(12, 2730ul);
std::cout << "mask = " << mask << std::endl;
int main()
{
boost::dynamic_bitset<> mask(12, 2730ul);
std::cout << "mask = " << mask << std::endl;
boost::dynamic_bitset<> x(12);
std::cout << "x.size()=" << x.size() << std::endl;
boost::dynamic_bitset<> x;
std::cout << "x.size() = " << x.size() << std::endl;
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;
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;
}

View File

@@ -1,7 +1,6 @@
// -----------------------------------------------------------
// boost::dynamic_bitset timing tests
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Copyright (c) 2003-2004 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,6 +8,8 @@
//
// -----------------------------------------------------------
// boost::dynamic_bitset timing tests
//
// NOTE:
// ~~~~~
// This is a preliminary, incomplete version.
@@ -25,8 +26,7 @@
//
//
// -----------------------------------------------------------------------//
//
// $Id$
#include "boost/config.hpp"

View File

@@ -1,7 +1,7 @@
// --------------------------------------------------
// -----------------------------------------------------------
//
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2006.
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,14 +9,10 @@
//
// -----------------------------------------------------------
// 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> // for std::size_t
#include <cstddef>
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
@@ -24,6 +20,7 @@
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
@@ -46,13 +43,30 @@ namespace boost {
// ------- count function implementation --------------
namespace dynamic_bitset_count_impl {
typedef unsigned char byte_type;
enum mode { access_by_bytes, access_by_blocks };
// 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;
template <mode> struct mode_to_type {};
// the table: wrapped in a class template, so
// that it is only instantiated if/when needed
@@ -87,7 +101,7 @@ namespace boost {
template <typename Iterator>
inline std::size_t do_count(Iterator first, std::size_t length,
int /*dummy param*/,
mode_to_type<access_by_bytes>* )
value_to_type<access_by_bytes>* )
{
std::size_t num = 0;
if (length)
@@ -111,7 +125,7 @@ namespace boost {
//
template <typename Iterator, typename ValueType>
inline std::size_t do_count(Iterator first, std::size_t length, ValueType,
mode_to_type<access_by_blocks>*)
value_to_type<access_by_blocks>*)
{
std::size_t num = 0;
while (length){
@@ -129,8 +143,6 @@ namespace boost {
return num;
}
} // dynamic_bitset_count_impl
// -------------------------------------------------------
@@ -139,7 +151,7 @@ namespace boost {
//
// size_type(-1) / sizeof(T)
//
// from vector<>::max_size. This tries to get out more
// from vector<>::max_size. This tries to get more
// meaningful info.
//
template <typename T>
@@ -158,16 +170,57 @@ namespace boost {
// for static_asserts
template <typename T>
struct dynamic_bitset_allowed_block_type {
struct allowed_block_type {
enum { value = T(-1) > 0 }; // ensure T has no sign
};
template <>
struct dynamic_bitset_allowed_block_type<bool> {
struct 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 @@
// --------------------------------------------------
// -----------------------------------------------------------
//
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2004.
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2004, 2008 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,10 +9,6 @@
//
// -----------------------------------------------------------
// 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 @@
// --------------------------------------------------
// -----------------------------------------------------------
//
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2006.
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,10 +9,6 @@
//
// -----------------------------------------------------------
// 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
@@ -24,19 +20,13 @@
# 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__) && BOOST_WORKAROUND(BOOST_DYNAMIC_BITSET_GNUC_VERSION, \
BOOST_TESTED_AT(30300))
#if defined(__GNUC__)
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(expr) \
(boost::detail::make_non_const(expr))
#else

View File

@@ -1,7 +1,7 @@
// --------------------------------------------------
// -----------------------------------------------------------
//
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2006.
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,18 +9,13 @@
//
// -----------------------------------------------------------
// 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> // for std::overflow_error
#include <algorithm> // for std::swap, min, copy, fill
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <climits> // for CHAR_BIT
@@ -43,33 +38,29 @@
#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" // used by find_first/next
#include "boost/pending/lowest_bit.hpp"
namespace boost {
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
template <typename Block, typename Allocator>
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_allowed_block_type<Block>::value);
BOOST_STATIC_ASSERT((bool)detail::dynamic_bitset_impl::allowed_block_type<Block>::value);
public:
typedef Block block_type;
typedef Allocator allocator_type;
typedef std::size_t size_type;
typedef int block_width_type;
typedef block_type block_width_type;
BOOST_STATIC_CONSTANT(block_width_type, bits_per_block = (std::numeric_limits<Block>::digits));
BOOST_STATIC_CONSTANT(size_type, npos = static_cast<size_type>(-1));
@@ -85,9 +76,12 @@ public:
// the one and only non-copy ctor
reference(block_type & b, int pos)
:m_block(b), m_mask(block_type(1) << pos)
{ assert(pos >= 0 && pos < bits_per_block); }
reference(block_type & b, block_type pos)
:m_block(b),
m_mask( (assert(pos < bits_per_block),
block_type(1) << pos )
)
{ }
void operator&(); // left undefined
@@ -171,10 +165,39 @@ public:
dynamic_bitset(BlockInputIterator first, BlockInputIterator last,
const Allocator& alloc = Allocator())
:m_bits(first, last, alloc),
m_num_bits(m_bits.size() * bits_per_block)
{}
:m_bits(alloc),
m_num_bits(0)
{
using boost::detail::dynamic_bitset_impl::value_to_type;
using boost::detail::dynamic_bitset_impl::is_numeric;
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);
@@ -316,7 +339,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<int>(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 bit_mask(size_type pos) { return Block(1) << bit_index(pos); }
template <typename CharT, typename Traits, typename Alloc>
@@ -355,6 +378,39 @@ 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;
@@ -383,6 +439,11 @@ 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() {
@@ -415,24 +476,18 @@ BOOST_DYNAMIC_BITSET_PRIVATE:
};
#if defined(__IBMCPP__) && BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))
#if !defined BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// 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
template <typename Block, typename Allocator>
const typename dynamic_bitset<Block, Allocator>::block_width_type
dynamic_bitset<Block, Allocator>::bits_per_block;
template<typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>::block_width_type const
template <typename Block, typename Allocator>
const typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::npos;
template <typename Block, typename Allocator>
const typename dynamic_bitset<Block, Allocator>::block_width_type
dynamic_bitset<Block, Allocator>::ulong_width;
#endif
@@ -539,28 +594,10 @@ 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(calc_num_blocks(num_bits), Block(0), alloc),
m_num_bits(num_bits)
: m_bits(alloc),
m_num_bits(0)
{
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);
}
init_from_unsigned_long(num_bits, value);
}
// copy constructor
@@ -633,7 +670,7 @@ resize(size_type num_bits, bool value) // strong guarantee
if (value && (num_bits > m_num_bits)) {
const size_type extra_bits = count_extra_bits();
const block_width_type extra_bits = count_extra_bits();
if (extra_bits) {
assert(old_num_blocks >= 1 && old_num_blocks <= m_bits.size());
@@ -769,27 +806,12 @@ 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;
@@ -968,21 +990,35 @@ 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 namespace detail::dynamic_bitset_count_impl;
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;
const bool no_padding = bits_per_block == CHAR_BIT * sizeof(Block);
const bool enough_table_width = table_width >= CHAR_BIT;
#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
typedef mode_to_type< (no_padding && enough_table_width ?
access_by_bytes : access_by_blocks) > m;
enum { enough_table_width = table_width >= CHAR_BIT };
return do_count(m_bits.begin(), num_blocks(), Block(0), static_cast<m*>(0));
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<value_to_type<(bool)mode> *>(0));
}
@@ -1072,29 +1108,22 @@ to_ulong() const
// beyond the "allowed" positions
typedef unsigned long result_type;
/*
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 maximum_size =
(std::min)(m_num_bits, static_cast<size_type>(ulong_width));
if (bits_per_block >= ulong_width)
return static_cast<result_type>(m_bits[0]);
*/
const size_type last_block = block_index( maximum_size - 1 );
assert((last_block * bits_per_block) < static_cast<size_type>(ulong_width));
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) {
assert((size_type)bits_per_block * i < (size_type)ulong_width);
unsigned long piece = m_bits[i];
result |= (piece << (bits_per_block * i));
const size_type offset = i * bits_per_block;
result |= (static_cast<result_type>(m_bits[i]) << offset);
}
return result;
}
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::size() const
@@ -1123,7 +1152,8 @@ dynamic_bitset<Block, Allocator>::max_size() const
// his own allocator.
//
const size_type m = detail::vector_max_size_workaround(m_bits);
const size_type m = detail::dynamic_bitset_impl::
vector_max_size_workaround(m_bits);
return m <= (size_type(-1)/bits_per_block) ?
m * bits_per_block :

View File

@@ -1,7 +1,7 @@
// --------------------------------------------------
// -----------------------------------------------------------
//
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2004.
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2004 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,10 +9,6 @@
//
// -----------------------------------------------------------
// 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
@@ -24,6 +20,6 @@ template <typename Block = unsigned long,
typename Allocator = std::allocator<Block> >
class dynamic_bitset;
} // namespace boost
}
#endif // include guard

View File

@@ -1,17 +1,15 @@
// -------------------------------------
// -----------------------------------------------------------
// lowest_bit.hpp
//
// Position of the lowest bit 'on'
//
// (C) Copyright Gennaro Prota 2003 - 2004.
// Copyright (c) 2003-2004, 2008 Gennaro Prota
//
// 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