Compare commits

...

31 Commits

Author SHA1 Message Date
Beman Dawes
1b241db6ec Release 1.46.0
[SVN r69125]
2011-02-21 18:42:22 +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
Daniel James
61702fef06 Merged revisions 43206,43208-43213 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r43206 | danieljames | 2008-02-10 09:55:03 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Fix some broken links.
........
  r43209 | danieljames | 2008-02-10 14:56:22 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Link to people pages on the website, as they've been removed from the download.
........
  r43210 | danieljames | 2008-02-10 15:02:17 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Point links to the pages that used to be in 'more' to the site.
........
  r43212 | danieljames | 2008-02-10 16:10:16 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Fix links on the home page as well.
........
  r43213 | danieljames | 2008-02-10 16:21:22 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Generated documentation which is no longer generated.
........


[SVN r43214]
2008-02-10 16:39:38 +00:00
Boris Gubenko
6bf10f4ef0 merge change in trunk (changeset/41778) to release branch
[SVN r41959]
2007-12-10 18:51:19 +00:00
Beman Dawes
0999a9b907 Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41370]
2007-11-25 18:38:02 +00:00
Beman Dawes
4ae778ba4a Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41369]
2007-11-25 18:07:19 +00:00
Beman Dawes
c9dcc1de64 config, detail, filesystem, system, tools, at 41278.
[SVN r41316]
2007-11-23 17:03:14 +00:00
Beman Dawes
cc9b262cb9 Starting point for releases
[SVN r39706]
2007-10-05 14:25:06 +00:00
nobody
ba7ccc50ae This commit was manufactured by cvs2svn to create tag
'Version_1_34_1'.

[SVN r38286]
2007-07-24 19:28:14 +00:00
Rene Rivera
3e03a8d947 Remove obsolete Boost.Build v1 files.
[SVN r35880]
2006-11-06 17:10:46 +00:00
Gennaro Prota
a0d66fd920 prevented spurious Digital Mars warning
[SVN r34645]
2006-07-20 22:55:07 +00:00
Gennaro Prota
3e3d36c571 added extra parentheses to workaround Digital Mars
[SVN r34644]
2006-07-20 22:52:21 +00:00
Gennaro Prota
3be249a20e workarounded absurd Digital Mars behavior
[SVN r34643]
2006-07-20 22:50:11 +00:00
Gennaro Prota
5f1c39cb6c added copyright/license notes
[SVN r34570]
2006-07-17 02:14:22 +00:00
Gennaro Prota
7c48bf04c2 added copyright/license notes; validated (XHTML 1.0 Strict)
[SVN r34569]
2006-07-17 02:09:49 +00:00
nobody
5e260f4364 This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r33417]
2006-03-21 02:26:31 +00:00
Markus Schöpflin
896a792bec Workaround for IBM's compiler on AIX.
[SVN r32101]
2005-12-19 10:00:51 +00:00
Douglas Gregor
39f11e7cc0 Workaround for CodeWarrior 9.4/9.5, I think
[SVN r28956]
2005-05-16 14:22:35 +00:00
Aleksey Gurtovoy
b18fc5cd99 merge RC_1_32_0 fixes
[SVN r26328]
2004-11-28 03:35:12 +00:00
20 changed files with 1239 additions and 1181 deletions

21
Jamfile
View File

@@ -1,21 +0,0 @@
subproject libs/dynamic_bitset ;
unit-test dyn_bitset_unit_tests1
: dyn_bitset_unit_tests1.cpp
: <include>$(BOOST_ROOT)
;
unit-test dyn_bitset_unit_tests2
: dyn_bitset_unit_tests2.cpp
: <include>$(BOOST_ROOT)
;
unit-test dyn_bitset_unit_tests3
: dyn_bitset_unit_tests3.cpp
: <include>$(BOOST_ROOT)
;
unit-test dyn_bitset_unit_tests4
: dyn_bitset_unit_tests4.cpp
: <include>$(BOOST_ROOT)
;

View File

@@ -1,3 +1,9 @@
#
# Copyright Vladimir Prus 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)
test-suite dynamic_bitset :

View File

@@ -1,6 +1,6 @@
// --------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2004.
// -----------------------------------------------------------
// 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
@@ -8,7 +8,6 @@
//
// -----------------------------------------------------------
#ifndef BOOST_BITSET_TEST_HPP_GP_20040319
#define BOOST_BITSET_TEST_HPP_GP_20040319
@@ -18,13 +17,13 @@
#endif
#include <vector>
#include <fstream> // used for operator<< :( - gps
#include <fstream> // used for operator<<
#include <string> // for (basic_string and) getline()
#include <algorithm> // for std::min
#include <cassert>
#include <assert.h> // <cassert> is sometimes macro-guarded :-(
#include "boost/limits.hpp"
#include "boost/dynamic_bitset.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/test/minimal.hpp"
@@ -33,7 +32,9 @@ inline bool nth_bit(Block num, std::size_t n)
{
#ifdef __BORLANDC__
// Borland deduces Block as a const qualified type,
// and finds numeric_limits<Block> to be zero :(
// and thus finds numeric_limits<Block> to be zero :(
// (though not directly relevant here, see also
// lib issue 559)
int block_width = sizeof(Block) * CHAR_BIT;
#else
int block_width = std::numeric_limits<Block>::digits;
@@ -77,20 +78,20 @@ bool is_white_space(const Stream & /*s*/, char c)
}
#else
template <typename Stream, typename Ch>
bool is_one_or_zero(const Stream& s, Ch c) // gps
bool is_one_or_zero(const Stream& s, Ch c)
{
typedef typename Stream::traits_type Tr;
const Ch zero = s.widen('0');
const Ch one = s.widen('1');
return Tr::eq(c, one) || Tr::eq(c, zero) ;
return Tr::eq(c, one) || Tr::eq(c, zero);
}
template <typename Stream, typename Ch>
bool is_white_space(const Stream & s, Ch c)
{
// NOTE: the using directive is to satisfy Borland 5.6.4
// with its own library (STLport), which chokes
// on std::isspace(c, loc) - gps
// with its own library (STLport), which doesn't
// like std::isspace(c, loc)
using namespace std;
return isspace(c, s.getloc());
}
@@ -107,30 +108,45 @@ 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 {
static void from_unsigned_long(std::size_t N, unsigned long num)
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)
{
// initializes the first M bit position to the cooresponding bit
// values in val. M is 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
//
// missing from the std?
// if M < N then the remaining bit positions are initialized to zero
Bitset b(num_bits, num);
Bitset b(N, num);
BOOST_CHECK(b.size() == N);
// 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)(N, ulong_width);
std::size_t I;
for (I = 0; I < M; ++I)
BOOST_CHECK(b[I] == nth_bit(num, I));
for (; I < N; ++I)
BOOST_CHECK(b[I] == 0);
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);
}
// from string
@@ -150,7 +166,7 @@ struct bitset_test {
std::size_t num_bits = (std::size_t)(-1))
{
std::size_t rlen = (std::min)(max_char, str.size() - pos); // [gps]
std::size_t rlen = (std::min)(max_char, str.size() - pos);
// The resulting size N of the bitset is num_bits, if
// that is different from the default arg, rlen otherwise.
@@ -169,7 +185,7 @@ struct bitset_test {
std::size_t m = (std::min)(num_bits, rlen);
std::size_t j;
for (j = 0; j < m; ++j)
BOOST_CHECK(b[j] == (str[pos + m - 1 - j] == '1')); // [gps]
BOOST_CHECK(b[j] == (str[pos + m - 1 - j] == '1'));
// If M < N, remaining bit positions are zero
for (; j < actual_size; ++j)
BOOST_CHECK(b[j] == 0);
@@ -177,9 +193,6 @@ struct bitset_test {
}
typedef typename Bitset::block_type Block;
BOOST_STATIC_CONSTANT(int, bits_per_block = Bitset::bits_per_block);
static void to_block_range(const Bitset & b /*, BlockOutputIterator result*/)
{
typedef typename Bitset::size_type size_type;
@@ -208,7 +221,7 @@ struct bitset_test {
}
}
// gps - TODO from_block_range (below) should be splitted
// TODO from_block_range (below) should be splitted
// PRE: std::equal(first1, last1, first2) == true
static void from_block_range(const std::vector<Block>& blocks)
@@ -236,7 +249,7 @@ struct bitset_test {
BOOST_CHECK(bset[bit] == nth_bit(blocks[b], i));
}
}
BOOST_CHECK(n <= bset.num_blocks()); // gps - ok? ask on the list
BOOST_CHECK(n <= bset.num_blocks());
}
}
@@ -272,15 +285,17 @@ struct bitset_test {
static void swap(const Bitset& lhs, const Bitset& rhs)
{
// bitsets must be swapped
Bitset b1(lhs);
Bitset b2(rhs);
b1.swap(b2);
Bitset copy1(lhs);
Bitset copy2(rhs);
copy1.swap(copy2);
BOOST_CHECK(b1 == rhs);
BOOST_CHECK(b2 == lhs);
BOOST_CHECK(copy1 == rhs);
BOOST_CHECK(copy2 == lhs);
// references must be stable under a swap
for(typename Bitset::size_type i = 0; i < b1.size(); ++i) {
for(typename Bitset::size_type i = 0; i < lhs.size(); ++i) {
Bitset b1(lhs);
Bitset b2(rhs);
typename Bitset::reference ref = b1[i];
bool x = ref;
if (i < b2.size())
@@ -288,7 +303,8 @@ struct bitset_test {
b1.swap(b2);
BOOST_CHECK(b2[i] == x); // now it must be equal..
b2.flip(i);
BOOST_CHECK(ref == !x); // .. and ref must be into b2
BOOST_CHECK(ref == b2[i]); // .. and ref must be into b2
BOOST_CHECK(ref == !x);
}
}
@@ -343,7 +359,7 @@ struct bitset_test {
static void append_block(const Bitset& lhs)
{
Bitset b(lhs);
Block value(128); // gps
Block value(128);
b.append(value);
BOOST_CHECK(b.size() == lhs.size() + bits_per_block);
for (typename Bitset::block_width_type i = 0; i < bits_per_block; ++i)
@@ -615,29 +631,35 @@ struct bitset_test {
// to_ulong()
static void to_ulong(const Bitset& lhs)
{
std::size_t N = lhs.size();
std::size_t n = std::numeric_limits<unsigned long>::digits;
typedef unsigned long result_type;
std::size_t n = std::numeric_limits<result_type>::digits;
std::size_t sz = lhs.size();
bool will_overflow = false;
for (std::size_t I = n; I < N; ++I)
if (lhs[I] != 0)
for (std::size_t i = n; i < sz; ++i) {
if (lhs.test(i) != 0) {
will_overflow = true;
break;
}
}
if (will_overflow) {
try {
(void)lhs.to_ulong();
BOOST_CHECK(false); // It should have thrown an exception
} catch (std::overflow_error) {
} catch (std::overflow_error & ex) {
// Good!
BOOST_CHECK(!!ex.what());
} catch (...) {
BOOST_CHECK(false); // threw the wrong exception
}
} else {
unsigned long num = lhs.to_ulong();
// Make sure the number is right
if (N == 0)
result_type num = lhs.to_ulong();
// Be sure the number is right
if (sz == 0)
BOOST_CHECK(num == 0);
else {
for (std::size_t I = 0; I < N; ++I)
BOOST_CHECK(lhs[I] == (I < n ? nth_bit(num, I) : 0)); //G.P.S. bugfix
for (std::size_t i = 0; i < sz; ++i)
BOOST_CHECK(lhs[i] == (i < n ? nth_bit(num, i) : 0));
}
}
}
@@ -645,29 +667,21 @@ struct bitset_test {
// to_string()
static void to_string(const Bitset& b)
{
// Construct a string object of the appropriate type and initializes
// it to a string of length N characters. Each character is determined
// by the value of its corresponding bit position in b. Character
// position N - 1 corresponds to bit position zero. Sebsequent
// decreasing character positions correspond to increasing bit
// positions. Bit value zero becomes the charactet 0, bit value one
// becomes the character 1.
std::string str;
boost::to_string(b, str);
std::size_t N = b.size();
BOOST_CHECK(str.size() == b.size());
for (std::size_t I = 0; I < b.size(); ++I)
BOOST_CHECK(b[I] == 0 ? (str[N - 1 - I] == '0') : (str[N - 1 - I] == '1'));
for (std::size_t i = 0; i < b.size(); ++i)
BOOST_CHECK(str[b.size() - 1 - i] ==(b.test(i)? '1':'0'));
}
static void count(const Bitset& b)
{
std::size_t c = b.count();
std::size_t c_real = 0;
for (std::size_t I = 0; I < b.size(); ++I)
if (b[I])
++c_real;
BOOST_CHECK(c == c_real);
std::size_t actual = 0;
for (std::size_t i = 0; i < b.size(); ++i)
if (b[i])
++actual;
BOOST_CHECK(c == actual);
}
static void size(const Bitset& b)
@@ -677,47 +691,82 @@ struct bitset_test {
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]) {
result = true;
break;
}
BOOST_CHECK(b.any() == result);
}
static void none(const Bitset& b)
{
bool result = true;
for(std::size_t i = 0; i < b.size(); ++i) {
if(b[i]) {
result = false;
break;
}
}
BOOST_CHECK(b.none() == result);
// sanity
BOOST_CHECK(b.none() == !b.any());
BOOST_CHECK(b.none() == (b.count() == 0));
}
static void subset(const Bitset& a, const Bitset& b)
{
if (a.is_subset_of(b)) {
for (std::size_t I = 0; I < a.size(); ++I)
if (a[I])
BOOST_CHECK(b[I]);
} else {
bool is_subset = true;
for (std::size_t I = 0; I < a.size(); ++I)
if (a[I] && !b[I]) {
BOOST_CHECK(a.size() == b.size()); // PRE
bool is_subset = true;
if (b.size()) { // could use b.any() but let's be safe
for(std::size_t i = 0; i < a.size(); ++i) {
if(a.test(i) && !b.test(i)) {
is_subset = false;
break;
}
BOOST_CHECK(is_subset == false);
}
}
else {
// sanity
BOOST_CHECK(a.count() == 0);
BOOST_CHECK(a.any() == false);
//is_subset = (a.any() == false);
}
BOOST_CHECK(a.is_subset_of(b) == is_subset);
}
static void proper_subset(const Bitset& a, const Bitset& b)
{
if (a.is_proper_subset_of(b)) {
for (std::size_t I = 0; I < a.size(); ++I)
if (a[I])
BOOST_CHECK(b[I]);
BOOST_CHECK(a.count() < b.count());
} else {
bool is_subset = true;
for (std::size_t I = 0; I < a.size(); ++I)
if (a[I] && !b[I]) {
is_subset = false;
break;
// PRE: a.size() == b.size()
BOOST_CHECK(a.size() == b.size());
bool is_proper = false;
if (b.size() != 0) {
// check it's a subset
subset(a, b);
// is it proper?
for (std::size_t i = 0; i < a.size(); ++i) {
if (!a.test(i) && b.test(i)) {
is_proper = true;
// sanity
BOOST_CHECK(a.count() < b.count());
BOOST_CHECK(b.any());
}
BOOST_CHECK(is_subset == false || a.count() >= b.count());
}
}
BOOST_CHECK(a.is_proper_subset_of(b) == is_proper);
if (is_proper)
BOOST_CHECK(b.is_proper_subset_of(a) != is_proper);// antisymmetry
}
static void intersects(const Bitset& a, const Bitset& b)
@@ -730,7 +779,7 @@ struct bitset_test {
have_intersection = true;
BOOST_CHECK(a.intersects(b) == have_intersection);
// also check it is commutative
// also check commutativity
BOOST_CHECK(b.intersects(a) == have_intersection);
}
@@ -940,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
@@ -981,14 +1030,14 @@ struct bitset_test {
}
#endif
BOOST_CHECK(did_throw || !stream_was_good || (s.width() == 0)); // gps
BOOST_CHECK(did_throw || !stream_was_good || (s.width() == 0));
if (!stream_was_good) { // gps
if (!stream_was_good) {
BOOST_CHECK(s.good() == false);
// this should actually be oldstate == s.rdstate()
// but some implementations add badbit in the
// sentry constructor - gps
// sentry constructor
//
BOOST_CHECK((oldstate & s.rdstate()) == oldstate);
BOOST_CHECK(s.width() == w);
@@ -1000,7 +1049,7 @@ struct bitset_test {
// Of course dynamic_bitset's operator << doesn't require that.
size_type total_len = w <= 0 || (size_type)(w) < b.size()? b.size() : w;
const string_type padding (total_len - b.size(), fill_char); // gps
const string_type padding (total_len - b.size(), fill_char);
string_type expected;
boost::to_string(b, expected);
if ((s.flags() & std::ios::adjustfield) != std::ios::left)
@@ -1014,13 +1063,13 @@ struct bitset_test {
s.close();
corresponding_input_stream_type is(file_name);
string_type contents;
std::getline(is, contents, char_type()); // gps
std::getline(is, contents, char_type());
BOOST_CHECK(contents == expected);
}
}
// operator>>( [basic_]istream
template<typename Stream, typename String>
template <typename Stream, typename String>
static void stream_extractor(Bitset& b,
Stream& is,
String& str
@@ -1045,7 +1094,7 @@ struct bitset_test {
}
catch(const std::ios::failure &) {
did_throw = true;
}// catch bad alloc?? - gps
}
// postconditions
BOOST_CHECK(except == is.exceptions()); // paranoid
@@ -1101,7 +1150,7 @@ struct bitset_test {
// eofbit
if((after_digits == len && max_digits > num_digits ))
BOOST_CHECK(has_flags(is, std::ios::eofbit)); // gps
BOOST_CHECK(has_flags(is, std::ios::eofbit));
else
BOOST_CHECK(!has_flags(is, std::ios::eofbit));
@@ -1144,16 +1193,16 @@ struct bitset_test {
// bitset though there's nothing in the file to be extracted.
// Note that the dynamic_bitset docs say a sentry object is
// constructed and then converted to bool, thus we rely on
// what the underlying library does. - gps
// what the underlying library does.
//
#if !defined(BOOST_DINKUMWARE_STDLIB) || (BOOST_DINKUMWARE_STDLIB >= 306) // what about STLPORT? - gps
#if !defined(BOOST_DINKUMWARE_STDLIB) || (BOOST_DINKUMWARE_STDLIB >= 306)
BOOST_CHECK(b == a_copy);
#else
BOOST_CHECK(b.empty() == true);
#endif
}
else {
String sub = str.substr(after_spaces, num_digits); // gps
String sub = str.substr(after_spaces, num_digits);
BOOST_CHECK(b == Bitset(sub));
}
@@ -1166,7 +1215,7 @@ struct bitset_test {
// clear the stream to allow further reading then
// retrieve any remaining chars with a single getline()
is.exceptions(std::ios::goodbit);
is.clear(); // gps
is.clear();
String remainder;
std::getline(is, remainder, Ch());
if(stream_was_good)

View File

@@ -1,6 +1,6 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2004.
// -----------------------------------------------------------
// 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
@@ -8,17 +8,20 @@
//
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/dynamic_bitset.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/limits.hpp"
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
#define BOOST_BITSET_TEST_COUNT(x) (sizeof(x)/sizeof(x[0]))
// Codewarrior 8.3 for Win fails without this.
// Thanks Howard Hinnant ;)
#if BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
#pragma parse_func_templ off
#if defined __MWERKS__ && BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
# pragma parse_func_templ off
#endif
@@ -51,50 +54,115 @@ 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) )
{
typedef boost::dynamic_bitset<Block> bitset_type;
typedef bitset_test< bitset_type > Tests;
typedef bitset_test<bitset_type> Tests;
const int bits_per_block = bitset_type::bits_per_block;
const std::string long_string = get_long_string();
const Block all_1s = static_cast<Block>(-1);
//=====================================================================
// Test construction from unsigned long
{
const std::size_t ulong_width = std::numeric_limits<unsigned long>::digits;
const unsigned long ulong_max =(std::numeric_limits<unsigned long>::max)();
typedef typename bitset_type::size_type size_type;
unsigned long numbers[] = { 0, 1, 40247, ulong_max >> 1, ulong_max };
const std::size_t array_count = sizeof(numbers) / sizeof(numbers[0]);
for (std::size_t i = 0; i < array_count; ++i) {
unsigned long number = numbers[i];
std::size_t n = 0;
Tests::from_unsigned_long(n, number);
// 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 };
n = std::size_t(0.7 * double(ulong_width));
Tests::from_unsigned_long(n, number);
n = 1 * ulong_width;
Tests::from_unsigned_long(n, number);
n = std::size_t(1.3 * double(ulong_width));
Tests::from_unsigned_long(n, number);
n = std::size_t(0.7 * double(bits_per_block));
Tests::from_unsigned_long(n, number);
n = 1 * bits_per_block;
Tests::from_unsigned_long(n, number);
n = std::size_t(1.3 * double(bits_per_block));
Tests::from_unsigned_long(n, number);
n = 3 * bits_per_block;
Tests::from_unsigned_long(n, number);
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
@@ -110,7 +178,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
// one hand I should have better tests. On the other one
// I don't want tests for dynamic_bitset to cope with locales,
// ctype::widen, etc. (but that's what you deserve when you
// don't separate concerns at the library level) - gps
// don't separate concerns at the library level)
//
run_string_tests<Tests>(
std::wstring(L"11111000000111111111010101010101010101010111111"));
@@ -123,8 +191,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
}
//=====================================================================
// Test construction from a block range
// [gps - this comment is erroneous]
// test from_block_range
{
std::vector<Block> blocks;
Tests::from_block_range(blocks);
@@ -133,7 +200,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
std::vector<Block> blocks(3);
blocks[0] = static_cast<Block>(0);
blocks[1] = static_cast<Block>(1);
blocks[2] = ~Block(0);
blocks[2] = all_1s;
Tests::from_block_range(blocks);
}
{
@@ -305,7 +372,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
std::vector<Block> blocks(3);
blocks[0] = static_cast<Block>(0);
blocks[1] = static_cast<Block>(1);
blocks[2] = ~Block(0);
blocks[2] = all_1s;
Tests::append_block_range(a, blocks);
}
{
@@ -330,7 +397,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
std::vector<Block> blocks(3);
blocks[0] = static_cast<Block>(0);
blocks[1] = static_cast<Block>(1);
blocks[2] = ~Block(0);
blocks[2] = all_1s;
Tests::append_block_range(a, blocks);
}
//=====================================================================

View File

@@ -1,6 +1,6 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2004.
// -----------------------------------------------------------
// 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
@@ -8,9 +8,8 @@
//
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/dynamic_bitset.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/config.hpp"

View File

@@ -1,6 +1,6 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2004.
// -----------------------------------------------------------
// 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
@@ -8,9 +8,9 @@
//
// -----------------------------------------------------------
#include <assert.h>
#include "bitset_test.hpp"
#include "boost/dynamic_bitset.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/limits.hpp"
#include "boost/config.hpp"
@@ -18,7 +18,7 @@
template <typename Block>
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
{
// a bunch of typedefs to have handy later on
// a bunch of typedefs which will be handy later on
typedef boost::dynamic_bitset<Block> bitset_type;
typedef bitset_test<bitset_type> Tests;
// typedef typename bitset_type::size_type size_type; // unusable with Borland 5.5.1
@@ -30,7 +30,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
// Test b.empty()
{
bitset_type b;
Tests::empty(b); // gps
Tests::empty(b);
}
{
bitset_type b(1, 1ul);
@@ -52,9 +52,13 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::to_ulong(b);
}
{
Block all_ones = ~Block(0);
boost::dynamic_bitset<Block> b(bitset_type::bits_per_block,
static_cast<unsigned long>(all_ones));
static_cast<unsigned long>(-1));
Tests::to_ulong(b);
}
{
std::string str(ul_width - 1, '1');
boost::dynamic_bitset<Block> b(str);
Tests::to_ulong(b);
}
{
@@ -90,6 +94,14 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::count(b);
}
{
boost::dynamic_bitset<Block> b(std::string("1"));
Tests::count(b);
}
{
boost::dynamic_bitset<Block> b(8, 255ul);
Tests::count(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::count(b);
@@ -388,6 +400,10 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
Tests::operator_less_than(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("10")), b(std::string("11"));
Tests::operator_less_than(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
Tests::operator_less_than(a, b);

View File

@@ -1,6 +1,6 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2004.
// -----------------------------------------------------------
// 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
@@ -10,9 +10,9 @@
#include <fstream>
#include <string>
#include <cstddef> // for std::size_t
#include <cstddef> // for std::size_t
#include <stdexcept> // for std::logic_error
#include <cassert>
#include <assert.h>
#include "boost/config.hpp"
#if !defined (BOOST_NO_STRINGSTREAM)
@@ -20,14 +20,14 @@
#endif
#include "bitset_test.hpp"
#include "boost/dynamic_bitset.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/detail/workaround.hpp"
// Codewarrior 8.3 for Win fails without this.
// Thanks Howard Hinnant ;)
#if BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
#pragma parse_func_templ off
#if defined __MWERKS__ && BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
# pragma parse_func_templ off
#endif
@@ -42,9 +42,15 @@ std::wstring widen_string( const std::string & str,
std::wstring result;
const std::string::size_type len = str.length();
if(len != 0) {
typedef std::ctype<wchar_t> ct_type;
typedef std::wstring::traits_type tr_type;
const ct_type & ct = BOOST_USE_FACET(ct_type, loc);
result.resize(len);
BOOST_USE_FACET(std::ctype<wchar_t>, loc)
.widen(&str[0], 1 + &str[len-1], &result[0]);
for (std::size_t i = 0; i < len; ++i)
tr_type::assign(result[i], ct.widen(str[i]));
}
return result;
}
@@ -71,7 +77,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
std::ios::eofbit | std::ios::failbit
};
std::string strings[] = {
static std::string strings[] = {
std::string(""),
std::string("0"),
std::string("1"),
@@ -128,7 +134,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
}
{
//NOTE: there are NO string stream tests - gps
//NOTE: there are NO string stream tests
}
#if !defined (BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS)
{
@@ -163,7 +169,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
// a good "real life" test. Some characters, such as '\v' and '\f', are not
// used exactly because they are the ones which will most likely give problems
// on some systems (for instance '\f' could actually be written as a sequence
// of new-lines, and we could never be able to read it back) [gps]
// of new-lines, and we could never be able to read it back)
//
// Note how the bitset object is not initially empty. That helps checking
// that it isn't erroneously clear()ed by operator>>.
@@ -179,7 +185,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
const std::string spaces = "\t\n "; //"\t\n\v\f ";
const std::string long_string = get_long_string();
/*const*/ std::string strings[] = {
/*const*/ static std::string strings[] = {
// NOTE: "const" gives the usual problems with Borland
// (in Tests::stream_extractor instantiation)

File diff suppressed because it is too large Load Diff

View File

@@ -1,20 +1,24 @@
exe timing_tests
: timing_tests.cpp
: <include>$(BOOST_ROOT)
// -----------------------------------------------------------
// 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)
//
// -----------------------------------------------------------
exe timing_tests
: timing_tests.cpp
;
exe example1
: example1.cpp
: <include>$(BOOST_ROOT)
;
exe example2
: example2.cpp
: <include>$(BOOST_ROOT)
;
exe example3
: example3.cpp
: <include>$(BOOST_ROOT)
;

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.
@@ -26,6 +27,7 @@
//
// -----------------------------------------------------------------------//
#include "boost/config.hpp"
#if defined (__STL_CONFIG_H) && !defined (__STL_USE_NEW_IOSTREAMS)

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-2006, 2008 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,21 +9,18 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset for documentation.
#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"
//#include "boost/static_assert.hpp" // gps
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
@@ -35,16 +32,41 @@ namespace boost {
return static_cast<const unsigned char *>(static_cast<const void *>(p));
}
template<typename T, int amount, int width /* = default */>
struct shifter
{
static void left_shift(T & v) {
amount >= width ? (v = 0)
: (v >>= BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(amount));
}
};
// ------- 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
@@ -79,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)
@@ -103,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){
@@ -121,8 +143,6 @@ namespace boost {
return num;
}
} // dynamic_bitset_count_impl
// -------------------------------------------------------
@@ -131,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>
@@ -150,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,8 +9,6 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset for documentation.
#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 - 2004.
// 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,9 +9,6 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset for documentation.
#ifndef BOOST_DYNAMIC_BITSET_CONFIG_HPP_GP_20040424
#define BOOST_DYNAMIC_BITSET_CONFIG_HPP_GP_20040424
@@ -23,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)
// workaround for gcc bug c++/8419 - gps
// 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
@@ -48,7 +39,7 @@ namespace boost { namespace detail {
#define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
#endif
// if we can't use friends then private members are exposed
// if we can't use friends then we simply expose private members
//
#if defined(BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS)
#define BOOST_DYNAMIC_BITSET_PRIVATE public

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-2006, 2008 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,24 +9,20 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset for documentation.
#ifndef BOOST_DYNAMIC_BITSET_DYNAMIC_BITSET_HPP
#define BOOST_DYNAMIC_BITSET_DYNAMIC_BITSET_HPP
#include <cassert>
#include <assert.h>
#include <string>
#include <stdexcept> // for std::overflow_error
#include <algorithm> // for std::swap, std::min, std::copy, std::fill
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <climits> // for CHAR_BIT
#include <climits> // for CHAR_BIT
#include "boost/dynamic_bitset/config.hpp"
#ifndef BOOST_NO_STD_LOCALE
# include <locale> // G.P.S
# include <locale>
#endif
#if defined(BOOST_OLD_IOSTREAMS)
@@ -42,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; // gps
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));
@@ -77,7 +69,6 @@ public:
public:
// A proxy class to simulate lvalues of bit type.
// Shouldn't it be private? [gps]
//
class reference
{
@@ -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)
{}
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
@@ -129,16 +123,16 @@ public:
const Allocator& alloc = Allocator());
// The presence of this constructor is a concession to ease of
// use, especially for the novice user. A conversion from string
// is, in most cases, formatting, and should be done by the standard
// formatting convention: operator>>.
// WARNING: you should avoid using this constructor.
//
// A conversion from string is, in most cases, formatting,
// and should be performed by using operator>>.
//
// NOTE:
// Leave the parentheses around std::basic_string<CharT, Traits, Alloc>::npos.
// g++ 3.2 requires them and probably the standard will - see core issue 325
// NOTE 2:
// split into two constructors because of bugs in MSVC 6.0sp5 with STLport
// Leave the parentheses around std::basic_string<CharT, Traits, Alloc>::npos.
// g++ 3.2 requires them and probably the standard will - see core issue 325
// NOTE 2:
// split into two constructors because of bugs in MSVC 6.0sp5 with STLport
template <typename CharT, typename Traits, typename Alloc>
dynamic_bitset(const std::basic_string<CharT, Traits, Alloc>& s,
@@ -150,7 +144,7 @@ public:
:m_bits(alloc),
m_num_bits(0)
{
init_from_string(s, pos, n, num_bits, alloc);
init_from_string(s, pos, n, num_bits);
}
template <typename CharT, typename Traits, typename Alloc>
@@ -162,7 +156,7 @@ public:
m_num_bits(0)
{
init_from_string(s, pos, (std::basic_string<CharT, Traits, Alloc>::npos),
npos, Allocator());
npos);
}
// The first bit in *first is the least significant bit, and the
@@ -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);
@@ -264,10 +287,6 @@ public:
size_type num_blocks() const;
size_type max_size() const;
bool empty() const;
#if 0 // gps
void reserve(size_type n);
size_type capacity() const;
#endif
bool is_subset_of(const dynamic_bitset& a) const;
bool is_proper_subset_of(const dynamic_bitset& a) const;
@@ -320,22 +339,21 @@ 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>
void init_from_string(const std::basic_string<CharT, Traits, Alloc>& s,
typename std::basic_string<CharT, Traits, Alloc>::size_type pos,
typename std::basic_string<CharT, Traits, Alloc>::size_type n,
size_type num_bits,
const Allocator& alloc)
size_type num_bits)
{
assert(pos <= s.size());
typedef typename std::basic_string<CharT, Traits, Alloc> StrT;
typedef typename StrT::traits_type Tr;
const typename StrT::size_type rlen = (std::min)(n, s.size() - pos); // gps
const typename StrT::size_type rlen = (std::min)(n, s.size() - pos);
const size_type sz = ( num_bits != npos? num_bits : rlen);
m_bits.resize(calc_num_blocks(sz));
m_num_bits = sz;
@@ -344,7 +362,7 @@ private:
BOOST_DYNAMIC_BITSET_CTYPE_FACET(CharT, fac, std::locale());
const CharT one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1');
const size_type m = num_bits < rlen ? num_bits : rlen; // [gps]
const size_type m = num_bits < rlen ? num_bits : rlen;
typename StrT::size_type i = 0;
for( ; i < m; ++i) {
@@ -360,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;
@@ -368,7 +419,7 @@ BOOST_DYNAMIC_BITSET_PRIVATE:
Block& m_highest_block();
const Block& m_highest_block() const;
buffer_type m_bits; // [gps] to be renamed
buffer_type m_bits;
size_type m_num_bits;
@@ -378,15 +429,21 @@ BOOST_DYNAMIC_BITSET_PRIVATE:
// helper for stream >>
// Supplies to the lack of an efficient append at the less
// significant end: bits are actually appended "at left" but
// rearranged in the destructor. Everything works just as if
// dynamic_bitset<> had an append_at_right() function (which
// threw, in case, the same exceptions as push_back) except
// that the function is actually called bit_appender::do_append().
// rearranged in the destructor. From the perspective of
// client code everything works *as if* dynamic_bitset<> had
// an append_at_right() function (eventually throwing the same
// exceptions as push_back) except that the function is in fact
// called bit_appender::do_append().
//
dynamic_bitset & bs;
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() {
@@ -419,6 +476,22 @@ BOOST_DYNAMIC_BITSET_PRIVATE:
};
#if !defined BOOST_NO_INCLASS_MEMBER_INITIALIZATION
template <typename Block, typename Allocator>
const typename dynamic_bitset<Block, Allocator>::block_width_type
dynamic_bitset<Block, Allocator>::bits_per_block;
template <typename Block, typename Allocator>
const typename dynamic_bitset<Block, Allocator>::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
// Global Functions:
// comparison
@@ -487,7 +560,7 @@ void swap(dynamic_bitset<Block, Allocator>& b1,
template <typename Block, typename Allocator, typename stringT>
void
to_string(const dynamic_bitset<Block, Allocator>& b, stringT & s); // gps
to_string(const dynamic_bitset<Block, Allocator>& b, stringT & s);
template <typename Block, typename Allocator, typename BlockOutputIterator>
void
@@ -495,15 +568,13 @@ to_block_range(const dynamic_bitset<Block, Allocator>& b,
BlockOutputIterator result);
// gps - check docs with Jeremy
//
template <typename BlockIterator, typename B, typename A>
inline void
from_block_range(BlockIterator first, BlockIterator last,
dynamic_bitset<B, A>& result)
{
// PRE: distance(first, last) <= numblocks()
std::copy (first, last, result.m_bits.begin()); //[gps]
std::copy (first, last, result.m_bits.begin());
}
//=============================================================================
@@ -523,39 +594,17 @@ 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)
{
if (num_bits == 0)
return;
typedef unsigned long num_type;
// cut off all bits in value that have pos >= num_bits, if any
if (num_bits < static_cast<size_type>(ulong_width)) {
const num_type mask = (num_type(1) << num_bits) - 1;
value &= mask;
}
if (bits_per_block >= ulong_width) {
m_bits[0] = static_cast<block_type>(value);
}
else {
for(size_type i = 0; value != 0; ++i) {
m_bits[i] = static_cast<block_type>(value);
value >>= BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(bits_per_block);
}
}
init_from_unsigned_long(num_bits, value);
}
// copy constructor
template <typename Block, typename Allocator>
inline dynamic_bitset<Block, Allocator>::
dynamic_bitset(const dynamic_bitset& b)
: m_bits(b.m_bits), m_num_bits(b.m_num_bits) // [gps]
: m_bits(b.m_bits), m_num_bits(b.m_num_bits)
{
}
@@ -579,15 +628,9 @@ template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>& dynamic_bitset<Block, Allocator>::
operator=(const dynamic_bitset<Block, Allocator>& b)
{
#if 0 // gps
dynamic_bitset<Block, Allocator> tmp(b);
this->swap(tmp);
return *this;
#else
m_bits = b.m_bits;
m_num_bits = b.m_num_bits;
return *this;
#endif
}
template <typename Block, typename Allocator>
@@ -611,34 +654,32 @@ resize(size_type num_bits, bool value) // strong guarantee
const block_type v = value? ~Block(0) : Block(0);
if (required_blocks != old_num_blocks) {
m_bits.resize(required_blocks, v); // s.g. (copy) [gps]
m_bits.resize(required_blocks, v); // s.g. (copy)
}
// At this point:
//
// - if the buffer was shrunk, there's nothing to do, except
// a call to m_zero_unused_bits()
// - if the buffer was shrunk, we have nothing more to do,
// except a call to m_zero_unused_bits()
//
// - if it it is enlarged, all the (used) bits in the new blocks have
// the correct value, but we should also take care of the bits,
// if any, that were 'unused bits' before enlarging: if value == true,
// - if it was enlarged, all the (used) bits in the new blocks have
// the correct value, but we have not yet touched those bits, if
// any, that were 'unused bits' before enlarging: if value == true,
// they must be set.
if (value && (num_bits > m_num_bits)) {
const size_type extra_bits = count_extra_bits(); // gps
const block_width_type extra_bits = count_extra_bits();
if (extra_bits) {
assert(old_num_blocks >= 1 && old_num_blocks <= m_bits.size());
// Set them.
m_bits[old_num_blocks - 1] |= (v << extra_bits); // gps
m_bits[old_num_blocks - 1] |= (v << extra_bits);
}
}
m_num_bits = num_bits;
m_zero_unused_bits();
@@ -657,16 +698,15 @@ template <typename Block, typename Allocator>
void dynamic_bitset<Block, Allocator>::
push_back(bool bit)
{
resize(size() + 1);
set(size() - 1, bit);
const size_type sz = size();
resize(sz + 1);
set(sz, bit);
}
template <typename Block, typename Allocator>
void dynamic_bitset<Block, Allocator>::
append(Block value) // strong guarantee
{
// G.P.S. to be reviewed...
const block_width_type r = count_extra_bits();
if (r == 0) {
@@ -766,14 +806,12 @@ dynamic_bitset<Block, Allocator>::operator<<=(size_type n)
b[div] = b[0];
}
// zero out div blocks at the less significant end
std::fill_n(b, div, static_cast<block_type>(0));
// zero out any 1 bit that flowed into the unused part
m_zero_unused_bits(); // thanks to Lester Gong
}
return *this;
@@ -853,13 +891,6 @@ template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>&
dynamic_bitset<Block, Allocator>::set(size_type pos, bool val)
{
// [gps]
//
// Below we have no set(size_type) function to call when
// value == true; instead of using a helper, I think
// overloading set (rather than giving it a default bool
// argument) would be more elegant.
assert(pos < m_num_bits);
if (val)
@@ -884,14 +915,14 @@ dynamic_bitset<Block, Allocator>&
dynamic_bitset<Block, Allocator>::reset(size_type pos)
{
assert(pos < m_num_bits);
#if BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
#if defined __MWERKS__ && BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
// CodeWarrior 8 generates incorrect code when the &=~ is compiled,
// use the |^ variation instead.. <grafik>
m_bits[block_index(pos)] |= bit_mask(pos);
m_bits[block_index(pos)] ^= bit_mask(pos);
#else
#else
m_bits[block_index(pos)] &= ~bit_mask(pos);
#endif
#endif
return *this;
}
@@ -959,60 +990,35 @@ dynamic_bitset<Block, Allocator>::operator~() const
return b;
}
/*
The following is the straightforward implementation of count(), which
we leave here in a comment for documentation purposes.
template <typename Block, typename Allocator>
typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::count() const
{
size_type sum = 0;
for (size_type i = 0; i != this->m_num_bits; ++i)
if (test(i))
++sum;
return sum;
}
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;
The actual algorithm uses a lookup table.
#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
enum { enough_table_width = table_width >= CHAR_BIT };
The basic idea of the method is to pick up X bits at a time
from the internal array of blocks and consider those bits as
the binary representation of a number N. Then, to use a table
of 1<<X elements where table[N] is the number of '1' digits
in the binary representation of N (i.e. in our X bits).
In this implementation X is 8 (but can be easily changed: you
just have to modify the definition of table_width and shrink/enlarge
the table accordingly - it could be useful, for instance, to expand
the table to 512 elements on an implementation with 9-bit bytes) and
the internal array of blocks is seen, if possible, as an array of bytes.
In practice the "reinterpretation" as array of bytes is possible if and
only if X >= CHAR_BIT and Block has no padding bits (that would be counted
together with the "real ones" if we saw the array as array of bytes).
Otherwise we simply 'extract' X bits at a time from each Block.
*/
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;
const bool no_padding = bits_per_block == CHAR_BIT * sizeof(Block);
const bool enough_table_width = table_width >= CHAR_BIT;
typedef mode_to_type< (no_padding && enough_table_width ?
access_by_bytes : access_by_blocks) > m;
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));
}
@@ -1055,7 +1061,7 @@ void to_string_helper(const dynamic_bitset<B, A> & b, stringT & s,
// making me (Gennaro) realize this important separation of
// concerns issue, as well as many things about i18n.
//
template <typename Block, typename Allocator, typename stringT> // G.P.S.
template <typename Block, typename Allocator, typename stringT>
inline void
to_string(const dynamic_bitset<Block, Allocator>& b, stringT& s)
{
@@ -1069,7 +1075,7 @@ to_string(const dynamic_bitset<Block, Allocator>& b, stringT& s)
//
template <typename B, typename A, typename stringT>
inline void
dump_to_string(const dynamic_bitset<B, A>& b, stringT& s) // G.P.S.
dump_to_string(const dynamic_bitset<B, A>& b, stringT& s)
{
to_string_helper(b, s, true /* =dump_all*/);
}
@@ -1081,7 +1087,7 @@ to_block_range(const dynamic_bitset<Block, Allocator>& b,
{
// note how this copies *all* bits, including the
// unused ones in the last block (which are zero)
std::copy(b.m_bits.begin(), b.m_bits.end(), result); // [gps]
std::copy(b.m_bits.begin(), b.m_bits.end(), result);
}
template <typename Block, typename Allocator>
@@ -1098,29 +1104,26 @@ to_ulong() const
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
// Ok, from now on we can be sure there's no "on" bit
// beyond the "allowed" positions
typedef unsigned long result_type;
if (bits_per_block >= ulong_width)
return m_bits[0];
const size_type max_size =
(std::min)(m_num_bits, static_cast<size_type>(ulong_width));
const size_type last_block = block_index( max_size - 1 );
size_type last_block = block_index((std::min)(m_num_bits-1, // gps
(size_type)(ulong_width-1)));
unsigned long result = 0;
assert((last_block * bits_per_block) < static_cast<size_type>(ulong_width));
result_type result = 0;
for (size_type i = 0; i <= last_block; ++i) {
assert((size_type)bits_per_block * i < (size_type)ulong_width); // gps
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
@@ -1149,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 :
@@ -1162,31 +1166,6 @@ inline bool dynamic_bitset<Block, Allocator>::empty() const
return size() == 0;
}
#if 0 // gps
template <typename Block, typename Allocator>
inline void dynamic_bitset<Block, Allocator>::reserve(size_type n)
{
assert(n <= max_size()); // PRE - G.P.S.
m_bits.reserve(calc_num_blocks(n));
}
template <typename Block, typename Allocator>
typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::capacity() const
{
// capacity is m_bits.capacity() * bits_per_block
// unless that one overflows
const size_type m = static_cast<size_type>(-1);
const size_type q = m / bits_per_block;
const size_type c = m_bits.capacity();
return c <= q ?
c * bits_per_block :
m;
}
#endif
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::
is_subset_of(const dynamic_bitset<Block, Allocator>& a) const
@@ -1203,13 +1182,17 @@ bool dynamic_bitset<Block, Allocator>::
is_proper_subset_of(const dynamic_bitset<Block, Allocator>& a) const
{
assert(size() == a.size());
assert(num_blocks() == a.num_blocks());
bool proper = false;
for (size_type i = 0; i < num_blocks(); ++i) {
Block bt = m_bits[i], ba = a.m_bits[i];
const Block & bt = m_bits[i];
const Block & ba = a.m_bits[i];
if (bt & ~ba)
return false; // not a subset at all
if (ba & ~bt)
proper = true;
if (bt & ~ba)
return false;
}
return proper;
}
@@ -1294,7 +1277,7 @@ bool operator==(const dynamic_bitset<Block, Allocator>& a,
const dynamic_bitset<Block, Allocator>& b)
{
return (a.m_num_bits == b.m_num_bits)
&& (a.m_bits == b.m_bits); // [gps]
&& (a.m_bits == b.m_bits);
}
template <typename Block, typename Allocator>
@@ -1311,23 +1294,20 @@ bool operator<(const dynamic_bitset<Block, Allocator>& a,
assert(a.size() == b.size());
typedef typename dynamic_bitset<Block, Allocator>::size_type size_type;
if (a.size() == 0)
return false;
//if (a.size() == 0)
// return false;
// Since we are storing the most significant bit
// at pos == size() - 1, we need to do the comparisons in reverse.
// Compare a block at a time
for (size_type i = a.num_blocks() - 1; i > 0; --i)
//
for (size_type ii = a.num_blocks(); ii > 0; --ii) {
size_type i = ii-1;
if (a.m_bits[i] < b.m_bits[i])
return true;
else if (a.m_bits[i] > b.m_bits[i])
return false;
if (a.m_bits[0] < b.m_bits[0])
return true;
else
return false;
}
return false;
}
template <typename Block, typename Allocator>
@@ -1369,7 +1349,7 @@ operator<<(std::ostream& os, const dynamic_bitset<Block, Alloc>& b)
const ios::iostate ok = ios::goodbit;
ios::iostate err = ok;
if (os.opfx()) { // gps
if (os.opfx()) {
//try
typedef typename dynamic_bitset<Block, Alloc>::size_type bitsetsize_type;
@@ -1377,7 +1357,7 @@ operator<<(std::ostream& os, const dynamic_bitset<Block, Alloc>& b)
const bitsetsize_type sz = b.size();
std::streambuf * buf = os.rdbuf();
size_t npad = os.width() <= 0 // careful: os.width() is signed (and can be < 0)
|| (bitsetsize_type) os.width() <= sz? 0 : os.width() - sz; //- gps
|| (bitsetsize_type) os.width() <= sz? 0 : os.width() - sz;
const char fill_char = os.fill();
const ios::fmtflags adjustfield = os.flags() & ios::adjustfield;
@@ -1386,16 +1366,16 @@ operator<<(std::ostream& os, const dynamic_bitset<Block, Alloc>& b)
if (adjustfield != ios::left) {
for (; 0 < npad; --npad)
if (fill_char != buf->sputc(fill_char)) {
err |= ios::failbit; // gps
err |= ios::failbit;
break;
}
}
if (err == ok) {
// output the bitset
for (bitsetsize_type i = b.size(); 0 < i; --i) {// G.P.S.
for (bitsetsize_type i = b.size(); 0 < i; --i) {
const char dig = b.test(i-1)? '1' : '0';
if (EOF == buf->sputc(dig)) { // ok?? gps
if (EOF == buf->sputc(dig)) {
err |= ios::failbit;
break;
}
@@ -1418,7 +1398,7 @@ operator<<(std::ostream& os, const dynamic_bitset<Block, Alloc>& b)
} // if opfx
if(err != ok)
os.setstate(err); // assume this does NOT throw - gps
os.setstate(err); // assume this does NOT throw
return os;
}
@@ -1445,11 +1425,11 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
try {
typedef typename dynamic_bitset<Block, Alloc>::size_type bitsetsize_type;
typedef basic_streambuf<Ch, Tr> buffer_type; // G.P.S.
typedef basic_streambuf<Ch, Tr> buffer_type;
buffer_type * buf = os.rdbuf();
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(); //- G.P.S.
|| (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;
@@ -1458,14 +1438,14 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
if (adjustfield != ios_base::left) {
for (; 0 < npad; --npad)
if (Tr::eq_int_type(Tr::eof(), buf->sputc(fill_char))) {
err |= ios_base::failbit; // G.P.S.
err |= ios_base::failbit;
break;
}
}
if (err == ok) {
// output the bitset
for (bitsetsize_type i = b.size(); 0 < i; --i) {// G.P.S.
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)) {
@@ -1507,8 +1487,8 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
#ifdef BOOST_OLD_IOSTREAMS
// gps - A sentry-like class that calls isfx in its
// destructor. Necessary because bit_appender::do_append may throw.
// A sentry-like class that calls isfx in its destructor.
// "Necessary" because bit_appender::do_append may throw.
class pseudo_sentry {
std::istream & m_r;
const bool m_ok;
@@ -1532,21 +1512,21 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
typedef dynamic_bitset<Block, Alloc> bitset_type;
typedef typename bitset_type::size_type size_type;
std::ios::iostate err = std::ios::goodbit; // gps
std::ios::iostate err = std::ios::goodbit;
pseudo_sentry cerberos(is); // skips whitespaces
if(cerberos) {
b.clear();
const std::streamsize w = is.width();
const size_type limit = w > 0 && static_cast<size_type>(w) < b.max_size()// gps
const size_type limit = w > 0 && 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() ) {
if (c == EOF) {
err |= std::ios::eofbit; // G.P.S.
err |= std::ios::eofbit;
break;
}
else if (char(c) != '0' && char(c) != '1')
@@ -1554,7 +1534,6 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
else {
try {
//throw std::bad_alloc(); // gps
appender.do_append(char(c) == '1');
}
catch(...) {
@@ -1566,10 +1545,10 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
} // for
}
is.width(0); // gps
is.width(0);
if (b.size() == 0)
err |= std::ios::failbit;
if (err != std::ios::goodbit) // gps
if (err != std::ios::goodbit)
is.setstate (err); // may throw
return is;
@@ -1588,10 +1567,10 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
typedef typename bitset_type::size_type size_type;
const streamsize w = is.width();
const size_type limit = 0 < w && static_cast<size_type>(w) < b.max_size()? // gps
const size_type limit = 0 < w && static_cast<size_type>(w) < b.max_size()?
w : b.max_size();
ios_base::iostate err = ios_base::goodbit; // gps
ios_base::iostate err = ios_base::goodbit;
typename basic_istream<Ch, Tr>::sentry cerberos(is); // skips whitespaces
if(cerberos) {
@@ -1604,11 +1583,11 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
try {
typename bitset_type::bit_appender appender(b);
basic_streambuf <Ch, Tr> * buf = is.rdbuf();
typename Tr::int_type c = buf->sgetc(); // G.P.S.
typename Tr::int_type c = buf->sgetc();
for( ; appender.get_count() < limit; c = buf->snextc() ) {
if (Tr::eq_int_type(Tr::eof(), c)) {
err |= ios_base::eofbit; // G.P.S.
err |= ios_base::eofbit;
break;
}
else {
@@ -1629,7 +1608,7 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
//
// bits_stored bits have been extracted and stored, and
// either no further character is extractable or we can't
// append to the underlying vector (out of memory) gps
// append to the underlying vector (out of memory)
bool rethrow = false; // see std 27.6.1.1/4
try { is.setstate(ios_base::badbit); }
@@ -1641,10 +1620,10 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
}
}
is.width(0); // gps
is.width(0);
if (b.size() == 0 /*|| !cerberos*/)
err |= ios_base::failbit;
if (err != ios_base::goodbit) // gps
if (err != ios_base::goodbit)
is.setstate (err); // may throw
return is;
@@ -1702,7 +1681,7 @@ inline void
swap(dynamic_bitset<Block, Allocator>& left,
dynamic_bitset<Block, Allocator>& right) // no throw
{
left.swap(right); // gps
left.swap(right);
}

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,9 +9,6 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset for documentation.
#ifndef BOOST_DYNAMIC_BITSET_FWD_HPP
#define BOOST_DYNAMIC_BITSET_FWD_HPP
@@ -23,6 +20,6 @@ template <typename Block = unsigned long,
typename Allocator = std::allocator<Block> >
class dynamic_bitset;
} // namespace boost
}
#endif // include guard

View File

@@ -1,20 +1,20 @@
// -------------------------------------
// -----------------------------------------------------------
// 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)
//
// ------------------------------------------------------
// -----------------------------------------------------------
#ifndef BOOST_LOWEST_BIT_HPP_GP_20030301
#define BOOST_LOWEST_BIT_HPP_GP_20030301
#include <cassert>
#include <assert.h>
#include "boost/pending/integer_log2.hpp"

View File

@@ -1,9 +1,15 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="refresh" content="0; URL=dynamic_bitset.html">
<meta http-equiv=refresh content="0; URL=dynamic_bitset.html">
<title>Automatic redirection</title>
</head>
<body>
Automatic redirection failed, please go to
<a href="dynamic_bitset.html">dynamic_bitset.html</a>.
<a href="dynamic_bitset.html">dynamic_bitset.html</a>.&nbsp;<hr>
<p>© Copyright Beman Dawes, 2001</p>
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
</body>
</html>