mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-23 05:32:09 +00:00
Compare commits
133 Commits
boost-1.32
...
boost-1.58
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9879dd05b5 | ||
|
|
29ba0c22b1 | ||
|
|
8b7374b1db | ||
|
|
2091a4fd18 | ||
|
|
225064d355 | ||
|
|
b151c97fd2 | ||
|
|
a93174ddf9 | ||
|
|
1611aeb16a | ||
|
|
3229e26108 | ||
|
|
083c5e6214 | ||
|
|
18eb52ecee | ||
|
|
a3ea40d932 | ||
|
|
dd7cdc794e | ||
|
|
10195375ed | ||
|
|
9ed6f608a1 | ||
|
|
ba0ba59f24 | ||
|
|
bcc384b604 | ||
|
|
7b14895ec6 | ||
|
|
eb6004d98d | ||
|
|
f34a8a4b23 | ||
|
|
d19aeced56 | ||
|
|
5f4c0dc4d9 | ||
|
|
1b880102fe | ||
|
|
e8b37ccf10 | ||
|
|
e7aa32f5db | ||
|
|
86b177d3ee | ||
|
|
4c6825716f | ||
|
|
ac0baa94ee | ||
|
|
ae64496e98 | ||
|
|
0a1621f0e7 | ||
|
|
4d8b9b5c33 | ||
|
|
9fe813dd93 | ||
|
|
dd69fe8756 | ||
|
|
20df4eadc8 | ||
|
|
cccd1f74dc | ||
|
|
71a5cc6eeb | ||
|
|
c9fa6dbdd1 | ||
|
|
7186546f7d | ||
|
|
b82bfe4832 | ||
|
|
a257dead26 | ||
|
|
f44fbae9ba | ||
|
|
d6f1835fbb | ||
|
|
e6fc8e8ec9 | ||
|
|
734861bdac | ||
|
|
594140a081 | ||
|
|
59e99b9b45 | ||
|
|
f199a7f006 | ||
|
|
60f871da0c | ||
|
|
d77a2c4afa | ||
|
|
76d2f9d4d1 | ||
|
|
e3a2ca7276 | ||
|
|
38819630fd | ||
|
|
5c79c20827 | ||
|
|
6d0f9801f5 | ||
|
|
ed32df5ad2 | ||
|
|
da0b582703 | ||
|
|
622c8d8fd5 | ||
|
|
b7eedd0f46 | ||
|
|
16ca9cbb3c | ||
|
|
97d2bff3b6 | ||
|
|
a143af6e2f | ||
|
|
59825bc8db | ||
|
|
7d1144a461 | ||
|
|
c298ba0c5f | ||
|
|
4efeaee302 | ||
|
|
066e7dcf71 | ||
|
|
574f1dfe62 | ||
|
|
e953b16cee | ||
|
|
6b0d9627a8 | ||
|
|
180aa15c44 | ||
|
|
7ed46a6667 | ||
|
|
24d2081a73 | ||
|
|
f6ce97de67 | ||
|
|
7530a40476 | ||
|
|
c05a47b50d | ||
|
|
d09c7d2180 | ||
|
|
bddf77e5a4 | ||
|
|
d80a9dbdf8 | ||
|
|
15b61f694a | ||
|
|
eef25927d7 | ||
|
|
357e434387 | ||
|
|
a8998ae8a0 | ||
|
|
aa6053121c | ||
|
|
5d66eda2ac | ||
|
|
771e3d8779 | ||
|
|
d8b2330d42 | ||
|
|
61702fef06 | ||
|
|
1b7c462afe | ||
|
|
8a1da9667b | ||
|
|
6bf10f4ef0 | ||
|
|
717fb80e40 | ||
|
|
0999a9b907 | ||
|
|
4ae778ba4a | ||
|
|
c9dcc1de64 | ||
|
|
adc36a2b7f | ||
|
|
cc9b262cb9 | ||
|
|
a8c3c80888 | ||
|
|
3a04624801 | ||
|
|
ba7ccc50ae | ||
|
|
08357c3972 | ||
|
|
3e03a8d947 | ||
|
|
41e1f468d3 | ||
|
|
ae44c787e2 | ||
|
|
60375651d9 | ||
|
|
50ffc7be59 | ||
|
|
02f4b61f14 | ||
|
|
07b5b85dfe | ||
|
|
1170f90afb | ||
|
|
a0d66fd920 | ||
|
|
3e3d36c571 | ||
|
|
3be249a20e | ||
|
|
98917625dd | ||
|
|
5f1c39cb6c | ||
|
|
7c48bf04c2 | ||
|
|
109a0aef13 | ||
|
|
5995354ceb | ||
|
|
7f268666ad | ||
|
|
ecbc0c4262 | ||
|
|
184337e1cc | ||
|
|
2726ad0c3c | ||
|
|
30bd2e5bab | ||
|
|
38f7aa5d40 | ||
|
|
48aaaabed2 | ||
|
|
755fa101f8 | ||
|
|
9c0620b7f9 | ||
|
|
30b986e549 | ||
|
|
eb7f05d0c4 | ||
|
|
fff12b2c59 | ||
|
|
fb5e1d024d | ||
|
|
5e260f4364 | ||
|
|
896a792bec | ||
|
|
39f11e7cc0 | ||
|
|
b18fc5cd99 |
21
Jamfile
21
Jamfile
@@ -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)
|
||||
;
|
||||
@@ -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 :
|
||||
|
||||
|
||||
339
bitset_test.hpp
339
bitset_test.hpp
@@ -1,6 +1,8 @@
|
||||
// --------------------------------------------------
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006, 2008 Gennaro Prota
|
||||
// Copyright (c) 2014 Ahmed Charles
|
||||
// Copyright (c) 2014 Riccardo Marcangelo
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -8,7 +10,6 @@
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef BOOST_BITSET_TEST_HPP_GP_20040319
|
||||
#define BOOST_BITSET_TEST_HPP_GP_20040319
|
||||
|
||||
@@ -18,13 +19,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 +34,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 +80,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 +110,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(static_cast<typename Bitset::size_type>(num_bits), static_cast<unsigned long>(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 +168,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 +187,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 +195,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 +223,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 +251,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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,11 +269,12 @@ struct bitset_test {
|
||||
}
|
||||
}
|
||||
|
||||
// assignment operator (absent from std::bitset)
|
||||
static void assignment_operator(const Bitset& lhs, const Bitset& rhs)
|
||||
// copy assignment operator (absent from std::bitset)
|
||||
static void copy_assignment_operator(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
b = rhs;
|
||||
b = b; // self assignment check
|
||||
BOOST_CHECK(b == rhs);
|
||||
|
||||
// Changes to the copy do not affect the original
|
||||
@@ -269,18 +285,46 @@ struct bitset_test {
|
||||
}
|
||||
}
|
||||
|
||||
static void max_size(const Bitset& b)
|
||||
{
|
||||
BOOST_CHECK(b.max_size() > 0);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
|
||||
// move constructor (absent from std::bitset)
|
||||
static void move_constructor(const Bitset& b)
|
||||
{
|
||||
Bitset copy(boost::move(b));
|
||||
BOOST_CHECK(b == copy);
|
||||
}
|
||||
|
||||
// move assignment operator (absent from std::bitset)
|
||||
static void move_assignment_operator(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
Bitset c(rhs);
|
||||
b = boost::move(c);
|
||||
b = boost::move(b); // self assignment check
|
||||
BOOST_CHECK(b == rhs);
|
||||
}
|
||||
|
||||
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
|
||||
static void swap(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
// bitsets must be swapped
|
||||
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 +332,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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -323,6 +368,20 @@ struct bitset_test {
|
||||
BOOST_CHECK(b.size() == 0);
|
||||
}
|
||||
|
||||
static void pop_back(const Bitset& lhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
b.pop_back();
|
||||
BOOST_CHECK(b.size() == lhs.size() - 1);
|
||||
for (std::size_t i = 0; i < b.size(); ++i)
|
||||
BOOST_CHECK(b[i] == lhs[i]);
|
||||
|
||||
b.pop_back();
|
||||
BOOST_CHECK(b.size() == lhs.size() - 2);
|
||||
for (std::size_t j = 0; j < b.size(); ++j)
|
||||
BOOST_CHECK(b[j] == lhs[j]);
|
||||
}
|
||||
|
||||
static void append_bit(const Bitset& lhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
@@ -343,7 +402,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 +674,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 +710,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)
|
||||
@@ -675,49 +732,96 @@ struct bitset_test {
|
||||
BOOST_CHECK(Bitset(b).set().count() == b.size());
|
||||
}
|
||||
|
||||
static void all(const Bitset& b)
|
||||
{
|
||||
BOOST_CHECK(b.all() == (b.count() == b.size()));
|
||||
bool result = true;
|
||||
for(std::size_t i = 0; i < b.size(); ++i)
|
||||
if(!b[i]) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
BOOST_CHECK(b.all() == result);
|
||||
}
|
||||
|
||||
static void any(const Bitset& b)
|
||||
{
|
||||
BOOST_CHECK(b.any() == (b.count() > 0));
|
||||
BOOST_CHECK(b.any() == (b.count() != 0));
|
||||
bool result = false;
|
||||
for(std::size_t i = 0; i < b.size(); ++i)
|
||||
if(b[i]) {
|
||||
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 +834,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);
|
||||
}
|
||||
|
||||
@@ -876,6 +980,25 @@ struct bitset_test {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_set_bit(const Bitset& b, std::size_t pos, bool value)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
std::size_t N = lhs.size();
|
||||
if (pos < N) {
|
||||
Bitset prev(lhs);
|
||||
// Stores a new value in the bit at position pos in lhs.
|
||||
BOOST_CHECK(lhs.test_set(pos, value) == prev[pos]);
|
||||
BOOST_CHECK(lhs[pos] == value);
|
||||
|
||||
// All other values of lhs remain unchanged
|
||||
for (std::size_t I = 0; I < N; ++I)
|
||||
if (I != pos)
|
||||
BOOST_CHECK(lhs[I] == prev[I]);
|
||||
} else {
|
||||
// Not in range, doesn't satisfy precondition.
|
||||
}
|
||||
}
|
||||
|
||||
static void operator_shift_left(const Bitset& lhs, std::size_t pos)
|
||||
{
|
||||
Bitset x(lhs);
|
||||
@@ -940,7 +1063,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 +1104,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);
|
||||
@@ -999,8 +1122,8 @@ struct bitset_test {
|
||||
// This test require that os be an output _and_ input stream.
|
||||
// Of course dynamic_bitset's operator << doesn't require that.
|
||||
|
||||
size_type total_len = w <= 0 || (size_type)(w) < b.size()? b.size() : w;
|
||||
const string_type padding (total_len - b.size(), fill_char); // gps
|
||||
size_type total_len = w <= 0 || static_cast<size_type>(w) < b.size()? b.size() : static_cast<size_type>(w);
|
||||
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 +1137,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 +1168,7 @@ struct bitset_test {
|
||||
}
|
||||
catch(const std::ios::failure &) {
|
||||
did_throw = true;
|
||||
}// catch bad alloc?? - gps
|
||||
}
|
||||
|
||||
// postconditions
|
||||
BOOST_CHECK(except == is.exceptions()); // paranoid
|
||||
@@ -1090,7 +1213,7 @@ struct bitset_test {
|
||||
// {digits} or part of them
|
||||
const typename Bitset::size_type max_digits =
|
||||
w > 0 && static_cast<typename Bitset::size_type>(w) < b.max_size()
|
||||
? w : b.max_size();
|
||||
? static_cast<typename Bitset::size_type>(w) : b.max_size();
|
||||
|
||||
for( ; pos < len && (pos - after_spaces) < max_digits; ++pos) {
|
||||
if(!is_one_or_zero(is, str[pos]))
|
||||
@@ -1101,7 +1224,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 +1267,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 +1289,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)
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
// --------------------------------------------------------
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006 Gennaro Prota
|
||||
// Copyright (c) 2014 Ahmed Charles
|
||||
// Copyright (c) 2014 Riccardo Marcangelo
|
||||
//
|
||||
// Copyright (c) 2014 Glen Joseph Fernandes
|
||||
// glenfe at live dot com
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -8,17 +13,42 @@
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
#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"
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
#include <cstdlib>
|
||||
|
||||
template<class T>
|
||||
class minimal_allocator {
|
||||
public:
|
||||
typedef T value_type;
|
||||
|
||||
T* allocate(std::size_t n) {
|
||||
void* p = std::malloc(sizeof(T) * n);
|
||||
if (!p) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
return static_cast<T*>(p);
|
||||
}
|
||||
|
||||
void deallocate(T* p, std::size_t) {
|
||||
std::free(p);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#define BOOST_BITSET_TEST_COUNT(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
|
||||
// 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 +81,112 @@ 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)();
|
||||
// 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 };
|
||||
|
||||
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);
|
||||
|
||||
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 +202,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 +215,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 +224,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);
|
||||
}
|
||||
{
|
||||
@@ -173,29 +264,70 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
Tests::copy_constructor(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test assignment operator
|
||||
// Test copy assignment operator
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::assignment_operator(a, b);
|
||||
Tests::copy_assignment_operator(a, b);
|
||||
}
|
||||
{
|
||||
bitset_type a(std::string("1")), b(std::string("0"));
|
||||
Tests::assignment_operator(a, b);
|
||||
Tests::copy_assignment_operator(a, b);
|
||||
}
|
||||
{
|
||||
bitset_type a(long_string), b(long_string);
|
||||
Tests::assignment_operator(a, b);
|
||||
Tests::copy_assignment_operator(a, b);
|
||||
}
|
||||
{
|
||||
bitset_type a;
|
||||
bitset_type b(long_string); // b greater than a, a empty
|
||||
Tests::assignment_operator(a, b);
|
||||
Tests::copy_assignment_operator(a, b);
|
||||
}
|
||||
{
|
||||
bitset_type a(std::string("0"));
|
||||
bitset_type b(long_string); // b greater than a
|
||||
Tests::assignment_operator(a, b);
|
||||
Tests::copy_assignment_operator(a, b);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
//=====================================================================
|
||||
// Test move constructor
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::move_constructor(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::move_constructor(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::move_constructor(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test move assignment operator
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::move_assignment_operator(a, b);
|
||||
}
|
||||
{
|
||||
bitset_type a(std::string("1")), b(std::string("0"));
|
||||
Tests::move_assignment_operator(a, b);
|
||||
}
|
||||
{
|
||||
bitset_type a(long_string), b(long_string);
|
||||
Tests::move_assignment_operator(a, b);
|
||||
}
|
||||
{
|
||||
bitset_type a;
|
||||
bitset_type b(long_string); // b greater than a, a empty
|
||||
Tests::move_assignment_operator(a, b);
|
||||
}
|
||||
{
|
||||
bitset_type a(std::string("0"));
|
||||
bitset_type b(long_string); // b greater than a
|
||||
Tests::move_assignment_operator(a, b);
|
||||
}
|
||||
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
//=====================================================================
|
||||
// Test swap
|
||||
{
|
||||
@@ -248,6 +380,25 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
Tests::clear(a);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test pop back
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("01"));
|
||||
Tests::pop_back(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("10"));
|
||||
Tests::pop_back(a);
|
||||
}
|
||||
{
|
||||
const int size_to_fill_all_blocks = 4 * bits_per_block;
|
||||
boost::dynamic_bitset<Block> a(size_to_fill_all_blocks, 255ul);
|
||||
Tests::pop_back(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string);
|
||||
Tests::pop_back(a);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test append bit
|
||||
{
|
||||
boost::dynamic_bitset<Block> a;
|
||||
@@ -305,7 +456,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 +481,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);
|
||||
}
|
||||
//=====================================================================
|
||||
@@ -353,6 +504,14 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
bit_vec[i] = long_string[n - 1 - i] == '0' ? 0 : 1;
|
||||
Tests::operator_bracket(b, bit_vec);
|
||||
}
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
{
|
||||
typedef boost::dynamic_bitset<Block,
|
||||
minimal_allocator<Block> > Bitset;
|
||||
Bitset b;
|
||||
bitset_test<Bitset>::max_size(b);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// --------------------------------------------------------
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006 Gennaro Prota
|
||||
// Copyright (c) 2014 Ahmed Charles
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -8,9 +9,8 @@
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include "boost/config.hpp"
|
||||
|
||||
|
||||
@@ -195,14 +195,17 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
{ // case pos >= b.size()
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::set_one(b, 0, true);
|
||||
Tests::set_one(b, 0, false);
|
||||
}
|
||||
{ // case pos < b.size()
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::set_one(b, 0, true);
|
||||
Tests::set_one(b, 0, false);
|
||||
}
|
||||
{ // case pos == b.size() / 2
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::set_one(b, long_string.size()/2, true);
|
||||
Tests::set_one(b, long_string.size()/2, false);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.reset()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// --------------------------------------------------------
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006 Gennaro Prota
|
||||
// Copyright (c) 2014 Ahmed Charles
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -8,9 +9,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 +19,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 +31,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 +53,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 +95,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);
|
||||
@@ -109,32 +122,73 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
Tests::size(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.all()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::all(b);
|
||||
Tests::all(~b);
|
||||
Tests::all(b.set());
|
||||
Tests::all(b.reset());
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::all(b);
|
||||
Tests::all(~b);
|
||||
Tests::all(b.set());
|
||||
Tests::all(b.reset());
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::all(b);
|
||||
Tests::all(~b);
|
||||
Tests::all(b.set());
|
||||
Tests::all(b.reset());
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.any()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::any(b);
|
||||
Tests::any(~b);
|
||||
Tests::any(b.set());
|
||||
Tests::any(b.reset());
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::any(b);
|
||||
Tests::any(~b);
|
||||
Tests::any(b.set());
|
||||
Tests::any(b.reset());
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::any(b);
|
||||
Tests::any(~b);
|
||||
Tests::any(b.set());
|
||||
Tests::any(b.reset());
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.none()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::none(b);
|
||||
Tests::none(~b);
|
||||
Tests::none(b.set());
|
||||
Tests::none(b.reset());
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::none(b);
|
||||
Tests::none(~b);
|
||||
Tests::none(b.set());
|
||||
Tests::none(b.reset());
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::none(b);
|
||||
Tests::none(~b);
|
||||
Tests::none(b.set());
|
||||
Tests::none(b.reset());
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a.is_subset_of(b)
|
||||
@@ -388,6 +442,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);
|
||||
@@ -553,6 +611,23 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
Tests::test_bit(b, long_string.size()/2);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.test_set(pos)
|
||||
{ // case pos >= b.size()
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::test_set_bit(b, 0, true);
|
||||
Tests::test_set_bit(b, 0, false);
|
||||
}
|
||||
{ // case pos < b.size()
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::test_set_bit(b, 0, true);
|
||||
Tests::test_set_bit(b, 0, false);
|
||||
}
|
||||
{ // case pos == b.size() / 2
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::test_set_bit(b, long_string.size() / 2, true);
|
||||
Tests::test_set_bit(b, long_string.size() / 2, false);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b << pos
|
||||
{ // case pos == 0
|
||||
std::size_t pos = 0;
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
1204
dynamic_bitset.html
1204
dynamic_bitset.html
File diff suppressed because it is too large
Load Diff
@@ -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)
|
||||
;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -22,10 +23,15 @@
|
||||
// table in detail/dynamic_bitset.hpp and report any interesting
|
||||
// discovery on the list as well.
|
||||
|
||||
// You might also want to try both counting methods (by_bytes vs.
|
||||
// by_blocks) to see if the one that is selected automatically is
|
||||
// actually the fastest on your system.
|
||||
|
||||
//
|
||||
//
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
|
||||
#include "boost/config.hpp"
|
||||
|
||||
#if defined (__STL_CONFIG_H) && !defined (__STL_USE_NEW_IOSTREAMS)
|
||||
@@ -53,9 +59,9 @@ namespace {
|
||||
// see http://gcc.gnu.org/ml/gcc-bugs/1999-03n/msg00884.html
|
||||
//
|
||||
class boost_version {
|
||||
const int m_major;
|
||||
const int m_minor;
|
||||
const int m_subminor;
|
||||
int m_major;
|
||||
int m_minor;
|
||||
int m_subminor;
|
||||
|
||||
public:
|
||||
boost_version(unsigned long v = BOOST_VERSION):
|
||||
@@ -89,11 +95,11 @@ template <typename T>
|
||||
void timing_test(T* = 0) // dummy parameter to workaround VC6
|
||||
{
|
||||
|
||||
const unsigned long num = 100000;
|
||||
const unsigned long num = 30 * 100000;
|
||||
|
||||
|
||||
// This variable is printed at the end of the test,
|
||||
// to prevent the optimizer eliminating the call to
|
||||
// to prevent the optimizer from removing the call to
|
||||
// count() in the loop below.
|
||||
typename boost::dynamic_bitset<T>::size_type dummy = 0;
|
||||
|
||||
@@ -121,7 +127,6 @@ void timing_test(T* = 0) // dummy parameter to workaround VC6
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
prologue();
|
||||
|
||||
timing_test<unsigned char>();
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
// --------------------------------------------------
|
||||
// -----------------------------------------------------------
|
||||
//
|
||||
// (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
|
||||
//
|
||||
// Copyright (c) 2014 Glen Joseph Fernandes
|
||||
// glenfe at live dot com
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -9,21 +12,19 @@
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
// 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 <memory>
|
||||
#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 +36,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 +105,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 +129,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 +147,6 @@ namespace boost {
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
} // dynamic_bitset_count_impl
|
||||
// -------------------------------------------------------
|
||||
|
||||
|
||||
@@ -131,35 +155,84 @@ 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>
|
||||
typename T::size_type vector_max_size_workaround(const T & v) {
|
||||
inline typename T::size_type vector_max_size_workaround(const T & v)
|
||||
BOOST_NOEXCEPT
|
||||
{
|
||||
typedef typename T::allocator_type allocator_type;
|
||||
|
||||
typedef typename T::allocator_type allocator_type;
|
||||
const allocator_type& alloc = v.get_allocator();
|
||||
|
||||
const typename allocator_type::size_type alloc_max =
|
||||
v.get_allocator().max_size();
|
||||
const typename T::size_type container_max = v.max_size();
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
typedef std::allocator_traits<allocator_type> allocator_traits;
|
||||
|
||||
return alloc_max < container_max?
|
||||
alloc_max :
|
||||
container_max;
|
||||
const typename allocator_traits::size_type alloc_max =
|
||||
allocator_traits::max_size(alloc);
|
||||
#else
|
||||
const typename allocator_type::size_type alloc_max = alloc.max_size();
|
||||
#endif
|
||||
|
||||
const typename T::size_type container_max = v.max_size();
|
||||
|
||||
return alloc_max < container_max ? alloc_max : container_max;
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
|
||||
10
index.html
10
index.html
@@ -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>. <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>
|
||||
16
meta/libraries.json
Normal file
16
meta/libraries.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"key": "dynamic_bitset",
|
||||
"name": "Dynamic Bitset",
|
||||
"authors": [
|
||||
"Jeremy Siek",
|
||||
"Chuck Allison"
|
||||
],
|
||||
"description": "The dynamic_bitset class represents a set of bits. It provides accesses to the value of individual bits via an operator[] and provides all of the bitwise operators that one can apply to builtin integers, such as operator& and operator<<. The number of bits in the set is specified at runtime via a parameter to the constructor of the dynamic_bitset.",
|
||||
"documentation": "dynamic_bitset.html",
|
||||
"category": [
|
||||
"Containers"
|
||||
],
|
||||
"maintainers": [
|
||||
"Jeremy Siek <jeremy.siek -at- gmail.com>"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user