mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-19 04:12:09 +00:00
some cleanup (beware: not compiled)
[SVN r34883]
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
#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 <assert.h> // <cassert> is sometimes macro-guarded :-(
|
||||
@@ -79,7 +79,7 @@ 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');
|
||||
@@ -92,7 +92,7 @@ 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 doesn't
|
||||
// like std::isspace(c, loc) - gps
|
||||
// like std::isspace(c, loc)
|
||||
using namespace std;
|
||||
return isspace(c, s.getloc());
|
||||
}
|
||||
@@ -156,7 +156,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.
|
||||
@@ -175,7 +175,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);
|
||||
@@ -211,7 +211,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)
|
||||
@@ -239,7 +239,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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,7 +349,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)
|
||||
@@ -649,7 +649,7 @@ struct bitset_test {
|
||||
BOOST_CHECK(num == 0);
|
||||
else {
|
||||
for (std::size_t i = 0; i < sz; ++i)
|
||||
BOOST_CHECK(lhs[i] == (i < n ? nth_bit(num, i) : 0)); //G.P.S. bugfix
|
||||
BOOST_CHECK(lhs[i] == (i < n ? nth_bit(num, i) : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1020,14 +1020,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);
|
||||
@@ -1039,7 +1039,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)
|
||||
@@ -1053,7 +1053,7 @@ 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);
|
||||
}
|
||||
}
|
||||
@@ -1084,7 +1084,7 @@ struct bitset_test {
|
||||
}
|
||||
catch(const std::ios::failure &) {
|
||||
did_throw = true;
|
||||
}// catch bad alloc?? - gps
|
||||
}
|
||||
|
||||
// postconditions
|
||||
BOOST_CHECK(except == is.exceptions()); // paranoid
|
||||
@@ -1140,7 +1140,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));
|
||||
|
||||
@@ -1183,16 +1183,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));
|
||||
}
|
||||
|
||||
@@ -1205,7 +1205,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)
|
||||
|
||||
@@ -101,7 +101,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"));
|
||||
|
||||
@@ -31,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);
|
||||
|
||||
@@ -134,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)
|
||||
{
|
||||
@@ -169,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>>.
|
||||
|
||||
@@ -46,20 +46,6 @@ align="middle" width="277" height="86">
|
||||
<br>
|
||||
</p>
|
||||
|
||||
<!-- BEGIN TODO
|
||||
TODO:
|
||||
<ul>
|
||||
<li> ask to Jeremy about reference::operator& and about
|
||||
making reference itself private</li>
|
||||
<li>check the whole synopsis against code changes </li>
|
||||
<li>document intersects() after we reach consensus</li>
|
||||
</ul>
|
||||
<br>
|
||||
Note:
|
||||
Other things to do are marked by "[gps]"
|
||||
END TODO -->
|
||||
|
||||
|
||||
<h1>dynamic_bitset<Block, Allocator></h1>
|
||||
|
||||
<h2>Contents</h2>
|
||||
@@ -719,7 +705,7 @@ to <tt>std::numeric_limits<Block>::digits</tt>.
|
||||
<a name="npos">dynamic_bitset::npos</a>
|
||||
</pre>
|
||||
|
||||
The maximum value of <tt>size_type</tt>. [gps]
|
||||
The maximum value of <tt>size_type</tt>.
|
||||
|
||||
<hr>
|
||||
<h3><a name="constructors">Constructors</a></h3>
|
||||
@@ -954,7 +940,7 @@ void <a name=
|
||||
</pre>
|
||||
|
||||
<b>Effects:</b> This function provides the same end result as the
|
||||
following code, but is typically more efficient. [gps]
|
||||
following code, but is typically more efficient.
|
||||
|
||||
<pre>
|
||||
for (; first != last; ++first)
|
||||
@@ -1194,7 +1180,7 @@ object having the same type as <tt>*this</tt>. Note that if
|
||||
any <tt>dynamic_bitset</tt> operation causes <tt>size()</tt> to
|
||||
exceed <tt>max_size()</tt> then the <i>behavior is undefined</i>.
|
||||
<br><br>[The semantics of this function could change slightly
|
||||
when lib issue 197 will be closed - G.P.S.]<br>
|
||||
when lib issue 197 will be closed]<br>
|
||||
|
||||
<hr>
|
||||
<pre>
|
||||
@@ -1205,32 +1191,6 @@ bool <a name="empty">empty</a>() const;
|
||||
otherwise. <i>Note</i>: not to be confused with <tt>none()</tt>, that has
|
||||
different semantics.
|
||||
|
||||
<hr>
|
||||
<!-- ***************** To be removed - gps *************************
|
||||
<pre>
|
||||
void <a name="reserve">reserve</a>(size_type n);
|
||||
</pre>
|
||||
|
||||
<b>Precondition:</b> <tt>n <= this->max_size()</tt>.<br>
|
||||
<b>Effects:</b> informs the <tt>dynamic_bitset</tt> of a planned
|
||||
change in size(), so that reallocations can be managed accordingly.
|
||||
If before the call the dynamic_bitset's capacity is >= n then no
|
||||
reallocation happens and capacity remains unchanged. Otherwise
|
||||
storage is allocated and capacity becomes greater or equal to n.
|
||||
In any case, size() does not change.<br>
|
||||
<b>Throws:</b> An allocation error if <tt>n > capacity()</tt>
|
||||
and memory is exhausted (<tt>std::bad_alloc</tt> if <tt>
|
||||
Allocator=std::allocator</tt>).
|
||||
|
||||
<hr>
|
||||
<pre>
|
||||
size_type <a name="capacity">capacity()</a> const;
|
||||
</pre>
|
||||
|
||||
<b>Returns:</b> the total number of elements that <tt>*this</tt>
|
||||
can hold without requiring reallocation.<br>
|
||||
*************************************************************** -->
|
||||
|
||||
<hr>
|
||||
<pre>
|
||||
size_type <a name="count">count</a>() const
|
||||
@@ -1622,7 +1582,7 @@ were constructed by
|
||||
If <tt>bool(k)</tt> is true, it calls <tt>b.clear()</tt>
|
||||
then attempts to extract characters from <tt>is</tt>. For each character c
|
||||
that is a <i>bitset digit</i> the <i>corresponding bit value</i> is
|
||||
appended to the less significant end of <tt>b</tt> (appending may throw - gps ).
|
||||
appended to the less significant end of <tt>b</tt> (appending may throw).
|
||||
If <tt>is.width()</tt> is greater than zero and smaller than <tt>b.max_size()</tt>
|
||||
then the maximum number <tt>n</tt> of bits appended is <tt>is.width()</tt>;
|
||||
otherwise <tt>n</tt> = <tt>b.max_size()</tt>.
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <cstddef> // for std::size_t
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/detail/workaround.hpp"
|
||||
//#include "boost/static_assert.hpp" // gps
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#define BOOST_DYNAMIC_BITSET_GNUC_VERSION ( __GNUC__ * 100 * 100 \
|
||||
+ __GNUC_MINOR__ * 100)
|
||||
|
||||
// no-op function to workaround 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; }
|
||||
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
typedef Block block_type;
|
||||
typedef Allocator allocator_type;
|
||||
typedef std::size_t size_type;
|
||||
typedef int block_width_type; // gps
|
||||
typedef int block_width_type;
|
||||
|
||||
BOOST_STATIC_CONSTANT(block_width_type, bits_per_block = (std::numeric_limits<Block>::digits));
|
||||
BOOST_STATIC_CONSTANT(size_type, npos = static_cast<size_type>(-1));
|
||||
@@ -77,7 +77,6 @@ public:
|
||||
public:
|
||||
|
||||
// A proxy class to simulate lvalues of bit type.
|
||||
// Shouldn't it be private? [gps]
|
||||
//
|
||||
class reference
|
||||
{
|
||||
@@ -264,10 +263,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;
|
||||
@@ -334,7 +329,7 @@ private:
|
||||
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;
|
||||
@@ -343,7 +338,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) {
|
||||
|
||||
@@ -367,7 +362,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;
|
||||
|
||||
|
||||
@@ -428,8 +423,7 @@ BOOST_DYNAMIC_BITSET_PRIVATE:
|
||||
// The compiler is actually right, until core issue 454 will be settled:
|
||||
// http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_active.html#454
|
||||
//
|
||||
// Considering the direction taken by the committee, however, it
|
||||
// looks sensible to leave BOOST_WORKAROUND for the future (G. Prota)
|
||||
// It's arguable whether we want to mark this with BOOST_WORKAROUND or not.
|
||||
|
||||
|
||||
template<typename Block, typename Allocator>
|
||||
@@ -510,7 +504,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
|
||||
@@ -518,15 +512,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());
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
@@ -574,7 +566,7 @@ dynamic_bitset(size_type num_bits, unsigned long value, const Allocator& alloc)
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -598,15 +590,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>
|
||||
@@ -630,7 +616,7 @@ 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)
|
||||
}
|
||||
|
||||
|
||||
@@ -646,12 +632,12 @@ resize(size_type num_bits, bool value) // strong guarantee
|
||||
|
||||
if (value && (num_bits > m_num_bits)) {
|
||||
|
||||
const size_type extra_bits = count_extra_bits(); // gps
|
||||
const size_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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -683,8 +669,6 @@ 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) {
|
||||
@@ -871,13 +855,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)
|
||||
@@ -978,45 +955,6 @@ dynamic_bitset<Block, Allocator>::operator~() const
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
The actual algorithm uses a lookup table.
|
||||
|
||||
|
||||
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
|
||||
@@ -1073,7 +1011,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)
|
||||
{
|
||||
@@ -1087,7 +1025,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*/);
|
||||
}
|
||||
@@ -1099,7 +1037,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>
|
||||
@@ -1133,7 +1071,7 @@ to_ulong() const
|
||||
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
|
||||
assert((size_type)bits_per_block * i < (size_type)ulong_width);
|
||||
|
||||
result |= (m_bits[i] << (bits_per_block * i));
|
||||
}
|
||||
@@ -1183,31 +1121,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
|
||||
@@ -1319,7 +1232,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>
|
||||
@@ -1391,7 +1304,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;
|
||||
@@ -1399,7 +1312,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;
|
||||
@@ -1408,16 +1321,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;
|
||||
}
|
||||
@@ -1440,7 +1353,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;
|
||||
|
||||
}
|
||||
@@ -1467,11 +1380,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;
|
||||
@@ -1480,14 +1393,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)) {
|
||||
@@ -1529,8 +1442,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;
|
||||
@@ -1554,21 +1467,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')
|
||||
@@ -1576,7 +1489,6 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
|
||||
|
||||
else {
|
||||
try {
|
||||
//throw std::bad_alloc(); // gps
|
||||
appender.do_append(char(c) == '1');
|
||||
}
|
||||
catch(...) {
|
||||
@@ -1588,10 +1500,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;
|
||||
@@ -1610,10 +1522,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) {
|
||||
|
||||
@@ -1626,11 +1538,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 {
|
||||
@@ -1651,7 +1563,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); }
|
||||
@@ -1663,10 +1575,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;
|
||||
@@ -1724,7 +1636,7 @@ inline void
|
||||
swap(dynamic_bitset<Block, Allocator>& left,
|
||||
dynamic_bitset<Block, Allocator>& right) // no throw
|
||||
{
|
||||
left.swap(right); // gps
|
||||
left.swap(right);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user