Compare commits

...

398 Commits

Author SHA1 Message Date
Yuriy Chernyshov
75d3e4d83d Fix compilation with standard libraries implementations which use raw pointers as iterators 2026-01-16 11:19:22 +01:00
sehe
9b64641093 Add missing friend declaration
Fixes issue #100
2025-12-22 12:21:01 +01:00
Gennaro Prota
54c841d585 Exercise subtraction between iterators in the unit tests
Reason: This was missing. And we forgot a friend declaration for the
corresponding operator-(), which will be added with the next commit.
2025-12-22 11:53:06 +01:00
Gennaro Prota
7c4dbfa2ac Fix broken HTML link rendering in the rationale section of index.adoc
This replaces a raw `<a href...>`, which was rendered verbatim, with the
AsciiDoc link syntax.
2025-10-31 11:15:18 +01:00
Gennaro Prota
e19c647bc7 Fix the redirects from the old documentation locations 2025-10-31 10:58:48 +01:00
joaquintides
f12c918881 renamed build_docs.sh to build_antora.sh as per ci_boost_release.py requisites 2025-10-30 10:45:24 +01:00
joaquintides
354c63cb24 Adjust build_docs.sh for invocation from an external directory (PR #97) 2025-10-24 18:21:50 +02:00
Gennaro Prota
0622f6a59f Update package[-lock].json as per files in Boost.URL 2025-10-24 12:28:28 +02:00
joaquintides
3fab9dfdf7 Add b2-based doc building (PR #96) 2025-10-21 18:52:05 +02:00
Gennaro Prota
393b731466 Remove max_size_workaround()
Reason: I checked the three major standard library implementations and
they all take the allocator into account in max_size(), so the
workaround should be no longer necessary.
2025-10-15 11:41:44 +02:00
Gennaro Prota
41799d3fe5 Take into account that the underlying container is not necessarily a std::vector in max_size()
The vector_max_size_workaround() we had in place, and one of the test
cases, only considered std::vectors, which are no longer the only
allowed containers. This commit fixes "Allow choosing the underlying
container type".
2025-10-15 11:41:44 +02:00
Gennaro Prota
957ee38823 Add some missing const qualifiers 2025-10-15 11:41:44 +02:00
Gennaro Prota
796fcb615b Add more tests for reverse iterators 2025-10-15 11:41:44 +02:00
Gennaro Prota
982073fbcd Increase the test coverage 2025-10-15 11:41:44 +02:00
Gennaro Prota
809b7a3796 Also test std::hash with bitsets having equal underlying vectors
This makes sure the size of the bitset is taken into account in the
calculation of the hash value.
2025-10-15 11:41:44 +02:00
Gennaro Prota
caee95bddd Make the implementation of find_next() consistent with that of find_next_off() 2025-10-15 11:41:44 +02:00
Gennaro Prota
c9964a771b Use the typename keyword for the template parameter of minimal_allocator
Reason: Consistency.
2025-10-15 11:41:44 +02:00
Gennaro Prota
6b5e49ea40 Assume locales and std::use_facet() are always available
I think the days we needed to cope with their absence are gone.
2025-10-15 11:41:44 +02:00
Gennaro Prota
67115073d2 Fix the condition to choose the definition of BOOST_DYNAMIC_BITSET_CTYPE_FACET()
I realized that BOOST_USE_FACET() is always defined, so we have always
used one branch of the preprocessing conditional for all this time.
2025-10-15 11:41:44 +02:00
Gennaro Prota
a2d4a0ebbb Copy edit a comment 2025-10-15 11:41:43 +02:00
Gennaro Prota
2c7085502a Parenthesize a macro parameter 2025-10-15 11:41:43 +02:00
Gennaro Prota
bd00ce2e58 Reuse nth_bit() in bitset_test::append_block() 2025-10-15 11:41:43 +02:00
Gennaro Prota
f3d7d5c960 Improve the resize() tests 2025-10-15 11:41:43 +02:00
Gennaro Prota
63716d84a3 Clean up the swap() tests
Note that we still stated that references must be stable under a swap,
which is no longer true after "Allow choosing the underlying container
type".
2025-10-15 11:41:43 +02:00
Gennaro Prota
286e721430 Shorten a condition in the tests of max_size() 2025-10-15 11:41:43 +02:00
Gennaro Prota
7aca0a80fd Remove an erroneous comment 2025-10-15 11:41:43 +02:00
Gennaro Prota
7a00f3c051 No longer condition the use of (unsigned) long long on BOOST_HAS_LONG_LONG
Reason: We require C++11.
2025-10-15 11:41:43 +02:00
Gennaro Prota
cd68ee4632 Remove two useless comments 2025-10-15 11:41:43 +02:00
Gennaro Prota
f637b5bab1 Remove some special test code for the Dinkumware stdlib of MSVC 6
Reason: MSVC 6 is no longer supported.
2025-10-15 11:41:43 +02:00
Gennaro Prota
57bdff3f12 Remove an erroneous comment 2025-10-15 11:41:43 +02:00
Gennaro Prota
5a25945ed7 Remove superfluous parentheses in a return statement 2025-10-15 11:41:43 +02:00
Gennaro Prota
7755190288 Improve the tests of operator!=() 2025-10-15 11:41:43 +02:00
Gennaro Prota
b52e7cd97b Improve the flip() tests 2025-10-15 11:41:43 +02:00
Gennaro Prota
bf2e39ec65 Don't assume the underlying container is contiguous in operator<<=() and operator>>=()
Reason: This is no longer guaranteed. See "Allow choosing the underlying
container type".
2025-10-15 11:41:43 +02:00
Gennaro Prota
fd0c440888 Delete the copy constructor and the copy assignment operator of bit_appender
Reason: That's better than declaring them as private and leaving them
undefined.
2025-10-15 11:41:43 +02:00
Gennaro Prota
410068c17d Add constexpr support when compiling as C++20 or later
This support is only added for C++20 or later, as it would be too
limited in earlier standards.
2025-10-15 11:41:43 +02:00
Gennaro Prota
d8131f641c Add a \param paragraph to the documentation of find_first_off( size_type )
The meaning of the parameter was clear from the \return paragraph, but,
without an explicit \param paragraph, MrDocs would show the
documentation of size_type as documentation of the parameter.
2025-10-15 11:41:43 +02:00
Gennaro Prota
fc47959cd4 Remove an unused template parameter from allocator_type_extractor_impl 2025-10-15 11:41:43 +02:00
Gennaro Prota
8387c4f494 Use \post for postcondition paragraphs in the Javadoc comments
Reason: More specific command (also, consistency, as we use \pre for
preconditions).
2025-10-15 11:41:43 +02:00
Gennaro Prota
5f62214ad5 Make push_back() more efficient 2025-10-15 11:41:43 +02:00
Gennaro Prota
3ff4a319d9 Work around Clang 10, 11, 12 not providing std::bidirectional_iterator 2025-10-15 11:41:43 +02:00
Gennaro Prota
2cff357a91 Update the description of bit_appender
Reason: dynamic_bitset does have an append_at_right(), now; it's called
push_front().
2025-10-15 11:41:43 +02:00
Gennaro Prota
ff1a0fda26 Assert that both the underlying container and dynamic_bitset provide at least bidirectional iterators
The assert uses C++20 concepts, so it is only performed in C++20 or
later.

Note that, while evaluating the concept for the second assert, MSVC 2022
complained a constructor of class reference was private, therefore we
added a friend declaration.
2025-10-15 11:41:43 +02:00
Gennaro Prota
134fab263b Add a missing #include directive 2025-10-15 11:41:43 +02:00
Gennaro Prota
68c5913983 Mark pre-C++11 compilers as unusable for the regression tests 2025-10-15 11:41:43 +02:00
Gennaro Prota
882e0e0665 Remove two superfluous #include directives
This fixes/completes "Remove other workarounds for obsolete compilers".
2025-10-15 11:41:43 +02:00
Gennaro Prota
843b6c3dd0 Fix two typos in two comments 2025-10-15 11:41:43 +02:00
Gennaro Prota
bbb2fa90df Update a comment about library issue 303 2025-10-15 11:41:43 +02:00
Gennaro Prota
15a73050cb Re-apply Clang-Format
We should really automate this. But, for the moment...
2025-10-15 11:41:43 +02:00
Gennaro Prota
ac5df5566a Add two missing const qualifiers 2025-10-15 11:41:43 +02:00
Gennaro Prota
9bba7af0b5 Avoid a redundant first != last check for append< BlockInputIterator >() with input iterators
Note that this also avoids a BOOST_ASSERT().
2025-10-15 11:41:43 +02:00
Gennaro Prota
4cf19a2b0a Fix append< BlockInputIterator >() for input iterators
We were using `AllocatorOrContainer` as if it were still guaranteed to
be an allocator type. Unfortunately, the append() tests didn't exercise
input iterators, so this went unnoticed. I've now added tests.
2025-10-15 11:41:43 +02:00
Gennaro Prota
a740393527 Remove extra parentheses in the implementation of operator<()
Reason: Consistency.
2025-10-15 11:41:43 +02:00
Gennaro Prota
7ae245eabf Add missing spaces in a comment
Reason: Consistency.
2025-10-15 11:41:43 +02:00
Gennaro Prota
9d604eba5a Simplify the implementation of all() 2025-10-15 11:41:43 +02:00
Gennaro Prota
fae55af67d Remove a reference to a removed comment
The referenced comment was removed when porting the documentation to
MrDocs. It advised against using the constructor from basic_string, but,
perhaps, that advice was a bit too strong (constructing from strings is
handy, and probably faster than inputting from a stringstream).
2025-10-15 11:41:43 +02:00
Gennaro Prota
81011d8161 Add trailing periods to the \pre paragraphs that missed them
Reason: Consistency.
2025-10-15 11:41:43 +02:00
Gennaro Prota
51db99cf32 Fix a few documentation glitches 2025-10-15 11:41:43 +02:00
Gennaro Prota
ac6b01140d Make the three "from string" constructors explicit
Making them non-explicit was an oversight.
2025-10-15 11:41:43 +02:00
Gennaro Prota
26dac17a4a Settle the documentation of the iterators
We choose to hide the iterator type definitions and just document their
category, which is enough.
2025-10-15 11:41:43 +02:00
Gennaro Prota
d3c4e2751a Improve the encapsulation of bit_iterator_base 2025-10-15 11:41:43 +02:00
Gennaro Prota
c58487c26a Fix an error in the documentation of operator==() 2025-10-15 11:41:43 +02:00
Gennaro Prota
6f3634aa4b Remove the dependency on core/allocator_access.hpp 2025-10-15 11:41:43 +02:00
Gennaro Prota
d8365ee015 Make the max_size() tests a bit more meaningful 2025-10-15 11:41:43 +02:00
Gennaro Prota
4ca26518ec Add a missing comment 2025-10-15 11:41:43 +02:00
Gennaro Prota
8f07dd356a Add push_front() and pop_front() 2025-10-15 11:41:43 +02:00
Gennaro Prota
efd4d41f60 No longer use BOOST_NO_CXX11_RVALUE_REFERENCES
Reason: We require decent C++11 support anyway.
2025-10-15 11:41:43 +02:00
Gennaro Prota
30ee0f68b5 Add two blank lines
Reason: Readability, consistency.
2025-10-15 11:41:43 +02:00
Gennaro Prota
eba192e3a3 Make the descriptions of the preconditions of the three "from string" constructors more precise 2025-10-15 11:41:43 +02:00
Gennaro Prota
bb489c186a Add a constructor from basic_string_view in C++17 or later
Note that we have MrDocs compile as C++17 again (a change that we had
reverted).
2025-10-15 11:41:43 +02:00
Gennaro Prota
0177f4adfa Add a constructor from const CharT * (pointer to C-style string)
This is in preparation of the next commit, which will add a constructor
from std::basic_string_view (otherwise, construction from a C-style
string would be ambiguous between the basic_string_view and the
basic_string constructor).

Note that, rather than duplicating code to test the new member, we
changed many constructions in dyn_bitset_unit_tests1.cpp to use const
char *, instead of std::string. (The constructor from std::basic_string
is tested separately anyway.)
2025-10-15 11:41:43 +02:00
Gennaro Prota
079cff781d Don't test for Tr::eq( c, one ) twice in init_from_string() 2025-10-15 11:41:43 +02:00
Gennaro Prota
e00d9b30ae No longer use boost::move()
Reason: We require C++11 now, so we can use std::move().
2025-10-15 11:41:43 +02:00
Gennaro Prota
ae9703b119 Actually test the move constructor in the move constructor tests
We were testing the *copy* constructor, instead.
2025-10-15 11:41:43 +02:00
Gennaro Prota
3ccf097dc1 Replace a #include of a deprecated include file 2025-10-15 11:41:43 +02:00
Gennaro Prota
88995c08b0 Remove a superfluous #include directive 2025-10-15 11:41:43 +02:00
Gennaro Prota
3531f6703b Add missing const qualifiers 2025-10-15 11:41:43 +02:00
Gennaro Prota
0ff8509214 Make lowest_bit() more efficient
As a nice bonus, this also removes the dependency on Boost.Integer.
2025-10-15 11:41:43 +02:00
Gennaro Prota
08191fc025 Remove a spurious space 2025-10-15 11:41:43 +02:00
Gennaro Prota
759c4f4e4a Fix a misleading variable name 2025-10-15 11:41:43 +02:00
Gennaro Prota
12dfcea22f Get rid of BOOST_STATIC_ASSERT() and BOOST_STATIC_CONSTANT()
Reason: They are no longer necessary, given that we require C++11 now.
2025-10-15 11:41:43 +02:00
Gennaro Prota
526104dbe9 Assert that Block is the same type as AllocatorOrContainer::value_type
Reason: That's required both when AllocatorOrContainer is an allocator
type and when it's a container type. Now, when it is an allocator type,
the assert is usually in the implementation of std::vector, which we
use. But, when it's a container type, we need to assert that on our own.
2025-10-15 11:41:43 +02:00
Gennaro Prota
b6a875976d Remove the parameter-less overloads of find_first() and find_first_off()
Reason: We can use a default argument, instead, which is what
dynamic_bitset usually does.
2025-10-15 11:41:43 +02:00
Gennaro Prota
394854535a Make pop_back() more efficient 2025-10-15 11:41:43 +02:00
Gennaro Prota
1bef343d12 Back out the support for operator<=> in our iterators
Reason: It required operator<=> for the underlying container, and
boost::container::small_vector doesn't support it.
2025-10-15 11:41:42 +02:00
Gennaro Prota
0ca460971e Make buffer_type public
Reason: Failures from GCC and Clang. See the new code comment.
2025-10-15 11:41:42 +02:00
Gennaro Prota
6747f81566 Remove some outdated macros (workarounds for MSVC 6) 2025-10-15 11:41:42 +02:00
Gennaro Prota
b428ca6365 Remove another workaround for CodeWarrior
Reason: Obsolete compiler.
2025-10-15 11:41:14 +02:00
Gennaro Prota
35b0094529 Add C++20 iterators
Reason: Requested on the mailing list.
2025-10-14 19:24:47 +02:00
Gennaro Prota
1b8ef09564 Allow choosing the underlying container type
The user can now choose the underlying container type used by
dynamic_bitset. This allows e.g. having small buffer optimization by
using boost::container::small_vector.

Since the underlying container is no longer guaranteed to be
std::vector, we revert "Reflect some noexcept specifications of
std::vector in dynamic_bitset" and the related "Let MrDocs compile the
code as C++17".

Note that we didn't add serialization tests (dyn_bitset_unit_tests5.cpp)
because boost::container::small_vector has no serialization support.

This closes issue #76.
2025-10-14 19:24:47 +02:00
Gennaro Prota
e194055264 Add find_first_off(), find_first_off( size_type ) and find_next_off( size_type ) 2025-10-14 19:24:47 +02:00
Gennaro Prota
54b32707c4 Don't repeat the preprocessing condition to specialize std::hash 2025-10-14 19:24:47 +02:00
Alan de Freitas
07e110d522 Make the MrDocs documentation multipage 2025-10-14 19:24:47 +02:00
Alan de Freitas
17e2192154 Support CMake root mode 2025-10-14 19:24:47 +02:00
Gennaro Prota
4a928c8787 Ensure all #includes are at the top of the source file 2025-10-14 19:24:47 +02:00
Gennaro Prota
f429a0a50d Document our support for std::hash 2025-10-14 19:24:47 +02:00
Gennaro Prota
7f4078b1a9 Remove some symbol filters from mrdocs.yml
Reason: They no longer seem necessary.
2025-10-14 19:24:46 +02:00
Gennaro Prota
043b5e1c86 Reword a comment using singular they 2025-10-14 19:24:46 +02:00
Gennaro Prota
0052e61ccc Document that max_size() doesn't emit exceptions 2025-10-14 19:24:46 +02:00
Gennaro Prota
f262bea730 Use noexcept instead of BOOST_NOEXCEPT
Reason: We require C++11 support anyway.
2025-10-14 19:24:46 +02:00
ivanpanch
1c82de1c51 Fix a typo (“slighly”) in a documentation comment 2025-10-14 19:24:46 +02:00
ivanpanch
b0bc76bfc8 Remove a spurious comma in a documentation comment 2025-10-14 19:24:46 +02:00
Gennaro Prota
b429e550e4 Avoid an interrupted sentence in the \brief documentation of the stream inserter 2025-10-14 19:24:46 +02:00
Gennaro Prota
aa7105f209 Use the same parameter name for the two overloads of at()
Reason: Consistency.

This incidentally also fixes the documentation of the non-const
overload.
2025-10-14 19:24:46 +02:00
Gennaro Prota
ac485ff3d2 Add a missing const qualifier 2025-10-14 19:24:46 +02:00
Gennaro Prota
ac2a5a65b4 Fix an error in the documentation of resize() 2025-10-14 19:24:46 +02:00
Gennaro Prota
80da0cdd28 Let MrDocs compile the code as C++17
Reason: Getting the noexcept specifications introduced in "Reflect some
noexcept specifications of std::vector in dynamic_bitset".
2025-10-14 19:24:46 +02:00
Gennaro Prota
431df92f41 Work around some glitches from the MrDocs parser 2025-10-14 19:24:46 +02:00
Gennaro Prota
6f1b27797d Document our overload of hash_value() 2025-10-14 19:24:46 +02:00
Gennaro Prota
acc7f2a458 Fix two typos in the documentation comments 2025-10-14 19:24:46 +02:00
Gennaro Prota
8547f23e2d Document many function parameters and some return values
For some of these, we were getting "undocumented parameter" warnings
from MrDocs. For others, MrDocs was automatically adding some
documentation, but that was inadequate for DynamicBitset.
2025-10-14 19:24:46 +02:00
Gennaro Prota
fa4f504a01 Run the Antora workflow on macOS 15, in GitHub Actions 2025-10-14 19:24:46 +02:00
Gennaro Prota
e848c84da3 Use the same parameter names in the two declarations of boost::swap()
Reason: Fixing an error from MSVC 14.3 about different noexcept
specifications between the two declarations.
2025-10-14 19:24:46 +02:00
Gennaro Prota
a7c9175201 Simplify a redundant assert condition 2025-10-14 19:24:46 +02:00
Gennaro Prota
74d1e42a3f Reflect some noexcept specifications of std::vector in dynamic_bitset
This closes issue #85.
2025-10-14 19:24:46 +02:00
Gennaro Prota
41c20338ef Always use braces with for-statements, as well
Reason: Consistency and safety.

See: "Always use braces with if-statements".
2025-10-14 19:24:46 +02:00
Gennaro Prota
882a352a8e Denote short and long consistently 2025-10-14 19:24:46 +02:00
Gennaro Prota
b2712c0112 Rename dynamic_bitset.tpp to "dynamic_bitset.ipp"
Reason: Having it copied at installation time.
2025-10-14 19:24:46 +02:00
Gennaro Prota
d63c03ceb2 Leave inline to the compiler 2025-10-14 19:24:46 +02:00
Gennaro Prota
f47536a712 Set badbit if an exception is thrown during output
Reason: This is what the standard formatted output functions do.
2025-10-14 19:24:46 +02:00
Gennaro Prota
abff9a45a1 Remove two erroneous references to the standard 2025-10-14 19:24:46 +02:00
Gennaro Prota
31c0804722 Move a few includes to where they are actually used 2025-10-14 19:24:46 +02:00
Gennaro Prota
1105d6e3c9 Always use braces with if-statements
Reason: Consistency and safety.
2025-10-14 19:24:46 +02:00
Gennaro Prota
b9ec4cdfae Fix a typo in the documentation of operator>>=() 2025-10-14 19:24:46 +02:00
Gennaro Prota
a3288d871b Shorten some brief descriptions in the docs
This simply separates the first sentence from the rest with a blank
line, so that MrDocs takes just the first sentence as brief description.
2025-10-14 19:24:46 +02:00
Gennaro Prota
5f2c3cc0dd Add two missing spaces in a documentation comment 2025-10-14 19:24:46 +02:00
Gennaro Prota
b6cc8844ee Also exclude bit_appender from the MrDocs documentation 2025-10-14 19:24:46 +02:00
Gennaro Prota
255295adf2 Remove a pair of unneeded parentheses 2025-10-14 19:24:46 +02:00
Sébastien Loriot
a8fcf950af qualify full path 2025-10-14 19:24:46 +02:00
Gennaro Prota
23ac016871 Fix nav.adoc 2025-10-14 19:24:46 +02:00
Gennaro Prota
737e95c053 Add a few links to the reference in the documentation index 2025-10-14 19:24:46 +02:00
Gennaro Prota
0936305e82 Add doc/package.json and doc/package-lock.json 2025-10-14 19:24:46 +02:00
Gennaro Prota
e9f99a4446 Exclude old, failing versions of Clang and GCC from CI 2025-10-14 19:24:46 +02:00
Gennaro Prota
14c1b22a4c Also build the documentation in the CI workflow 2025-10-14 19:24:46 +02:00
James E. King III
688fa7c451 Implement Boost.CI 2025.07 reusable workflow
This moves the majority of build logic into Boost.CI with configuration
options for consumers.  By moving build logic into Boost.CI we can fix
build issues faster for everyone.
2025-10-14 19:24:46 +02:00
Gennaro Prota
9403b3bf7e Rethrow any exception coming from the underlying vector, in the stream extractor 2025-10-14 19:24:46 +02:00
Gennaro Prota
802278fec2 Delete unary operator&() for dynamic_bitset::reference
Reason: That's better than declaring it as private and leaving it
undefined.
2025-10-14 19:24:46 +02:00
Gennaro Prota
d96d00ef08 Don't add a semicolon after "BOOST_RETHROW"
Reason: When exceptions are enabled, the semicolon is already included
in the macro expansion, and the resulting second semicolon (empty
statement) may give compiler warnings. Note how we added braces, for
when exceptions are disabled and the macro has an empty replacement
list.
2025-10-14 19:24:46 +02:00
Gennaro Prota
7c8b554850 Add a missing blank line 2025-10-14 19:24:46 +02:00
Gennaro Prota
0fce729fe1 Remove an unnecessary constructor definition 2025-10-14 19:24:46 +02:00
Gennaro Prota
5da2852728 Remove an unnecessary implementation detail 2025-10-14 19:24:46 +02:00
Gennaro Prota
2ef8b15211 Add a definition for the copy constructor of dynamic_bitset::reference
Reason: Implicit definition is deprecated, because the class has a
user-declared copy assignment operator.

This closes issue #62.
2025-10-14 19:24:46 +02:00
Gennaro Prota
d839f23916 Make scoped_temp_file non-copyable, as it should 2025-10-14 19:24:46 +02:00
Gennaro Prota
963cc09f3c Remove a nonsensical typedef 2025-10-14 19:24:46 +02:00
Gennaro Prota
c203591add Don't use lowerCamelCase for template type parameters 2025-10-14 19:24:45 +02:00
Gennaro Prota
aebe027628 Copy edit a comment 2025-10-14 19:24:45 +02:00
Gennaro Prota
a65fe4dd9e Remove a few unneeded permission notices 2025-10-14 19:24:45 +02:00
Gennaro Prota
825260e482 Port the documentation to MrDocs and Antora 2025-10-14 19:24:45 +02:00
Gennaro Prota
12acc40123 Reformat all the C++ code (with ClangFormat) 2025-10-14 19:24:45 +02:00
Gennaro Prota
1092cdbfe6 Add a ClangFormat configuration file
This specifies a more readable style with respect to the existing one.
I'll reformat the code with the next commit.
2025-10-14 19:24:45 +02:00
Gennaro Prota
482c4b9701 Move all the function definitions to a separate file
Reason: Improving readability of the class template declaration.

This separation was not originally possible due to limitations in older
compilers (see the removed comment at the start of the definition of
dynamic_bitset), but is now feasible.
2025-10-14 19:24:45 +02:00
Gennaro Prota
5459cdf373 Leverage core::popcount() in the implementation of count()
Reason: This significantly simplifies the code, replacing a previous
complex and error-prone implementation.
2025-10-14 19:24:45 +02:00
Gennaro Prota
fffe155495 Fix some inconsistent placement of const qualifiers 2025-10-14 19:24:45 +02:00
Gennaro Prota
f61a1bf652 Assert on the precondition to pop_back() 2025-10-14 19:24:45 +02:00
Gennaro Prota
28ddbd7afc Make the swap() functions noexcept 2025-10-14 19:24:45 +02:00
Gennaro Prota
76656c9a0f Remove a misleading comment 2025-10-14 19:24:45 +02:00
Gennaro Prota
4b7a03234d Remove a redundant assertion
We already assert that the two bitsets have the same size and, since
they have the same block_type, that implies they have the same number of
blocks.
2025-10-14 19:24:45 +02:00
Gennaro Prota
93cd78c251 Remove a top-level const qualifier for a function parameter 2025-10-14 19:24:45 +02:00
Gennaro Prota
c6709f3c74 Add a missing const qualifier in a test function 2025-10-14 19:24:45 +02:00
Gennaro Prota
2e0e407ad5 Use BOOST_TEST(), not assert(), for test cases 2025-10-14 19:24:45 +02:00
Gennaro Prota
e8d9288620 Remove other workarounds for obsolete compilers 2025-10-14 19:24:45 +02:00
Gennaro Prota
4c26bd9a97 Don't misuse the term "precondition" in the documentation
If you guarantee some behavior, e.g. throwing an exception, it's not
really a precondition.
2025-10-14 19:24:45 +02:00
Gennaro Prota
2044a0c53c Clean up detail/lowest_bit.hpp (mostly, reformat) 2025-10-14 19:24:45 +02:00
Gennaro Prota
59ceb8f16f Remove a naive comment
If you are asserting on it at the beginning of the function, it's
clearly a precondition :-).
2025-10-14 19:24:45 +02:00
Gennaro Prota
4db39188a4 Replace the references to the SGI documentation
This commit just removes all the links to the SGI documentation and
replaces most of them with links to cppreference.com. The SGI docs were
likely used by Jeremy Siek at the time because they were a good and
clear reference. But we have cppreference.com now, which is much better.
And, in the event it disappears, we can still revert this commit.

Some links have simply been removed (e.g. those to the documentation of
basic_string, which really didn't seem opportune).
2025-10-14 19:24:45 +02:00
Gennaro Prota
190096e539 Remove inconsistent uses of title case 2025-10-14 19:24:45 +02:00
Gennaro Prota
599cc67e9d Remove trailing whitespace 2025-10-14 19:24:45 +02:00
Gennaro Prota
a9fe026431 Remove an unneeded #include directive in a test file 2025-10-14 19:24:45 +02:00
Gennaro Prota
6a92632638 Remove a tab character in a test file 2025-10-14 19:24:45 +02:00
Gennaro Prota
4485bf9bbf Remove a superfluous #include directive 2025-10-14 19:24:45 +02:00
Gennaro Prota
583cb08f6f Copy edit the readme
Note how I removed the "Directories" paragraph, as it just stated the
obvious.
2025-10-14 19:24:45 +02:00
Gennaro Prota
2579c3d6cd Remove an unused, junk function template 2025-10-14 19:24:45 +02:00
Gennaro Prota
4aedddb332 Consistently use BOOST_ASSERT() in the implementation
Note: Not in the unit tests, which better do without the dependency.
2025-10-14 19:24:45 +02:00
Gennaro Prota
dab7861b74 Remove a workaround for CodeWarrior 8 2025-10-14 19:24:45 +02:00
Gennaro Prota
e28c5636d6 Remove a spurious #undef directive
The #undef'd macro wasn't actually defined anywhere.
2025-10-14 19:24:45 +02:00
Gennaro Prota
dc945046aa Declare some internal details as private
They had been accidentally made public.
2025-10-14 19:24:45 +02:00
Gennaro Prota
8400b5c4c7 Remove some redundant access specifiers 2025-10-14 19:24:45 +02:00
Gennaro Prota
aea65e101f Remove a hopefully outdated workaround 2025-10-14 19:24:45 +02:00
Gennaro Prota
3c2546f0bb Remove a nonsensical usage of boost::addressof()
Because `dynamic_bitset` doesn't overload unary `operator &`.
2025-10-14 19:24:27 +02:00
Gennaro Prota
831ad00039 Fix the initial description in the documentation
This also aligns it with meta/libraries.json.
2025-09-11 12:36:42 +02:00
Gennaro Prota
6591f2fd30 Update my email address etc. in the documentation 2025-09-11 12:31:18 +02:00
Gennaro Prota
048a1cd3e5 Fix the metadata in libraries.json
The main fix, here, is not stating that dynamic_bitset is a container.
It isn't (at least in the C++ meaning of the term), as specified in the
documentation.

I'm also taking over as a maintainer, so I added my email address.
2025-09-11 12:31:18 +02:00
Gennaro Prota
e00b0048f9 Clean up all the #include sections
This commit:

- Sorts the #include directives: The #includes of the ""-form come
  first, those of the <>-form come later (this helps checking if any
  include file is not self-sufficient); in each of the two groups, the
  names of the headers or source files are sorted alphabetically (this
  eases searching for a specific #include and avoids duplicates).

- Uses the ""-form when including Boost files; using the <>-form is a
  relic of the past. This was even discussed on the developers list many
  years ago and led to core issue 370. Note that some parts of
  DynamicBitset were already using the ""-form and that has never caused
  any problem, AFAIK.

- Removes some comments attached to the directives themselves which
  seemed pretty useless and prone to get out of sync.
2025-09-11 12:31:09 +02:00
Gennaro Prota
2852d27363 Remove all support for pre-standard iostreams
Reason: When I re-implemented dynamic_bitset, GCC 2.95 was still around
and its library still only implemented pre-standard iostreams, so I
added that support. But I'm pretty sure no one needs it, now.
2025-07-07 15:29:13 +02:00
Gennaro Prota
179d719c92 Remove a flawed "example" (timing_tests.cpp)
Reason: That file was intended as a benchmark, but it was poorly
constructed. It did not pre-load the cache, did not run the tested code
multiple times, and did not follow standard benchmarking practices. As
such, it was misleading and not useful.
2025-07-07 15:28:39 +02:00
greg7mdp
688a99f54a Fix typo. 2025-03-29 08:02:48 -04:00
Unix&Me
b96250c3c6 simplify push_back logic 2024-12-28 16:25:41 -05:00
James E. King III
d6eb91388f Update CI to 2024.12 spec, update README 2024-12-28 21:25:17 +00:00
Anthony Eden
41d08970cd Support stateful allocators 2024-12-24 09:29:42 -05:00
James E. King III
cd59d325d3 Enable branch coverage. 2024-11-30 19:43:12 +00:00
twomice
34f55c74b1 Implement find_first(pos). 2024-11-26 13:59:18 -05:00
James E. King III
b33c19e05c Given GHA busted ubuntu-18.04 containers, those build jobs have been
removed.  Others have been updated to move forward.
2024-11-26 18:56:51 +00:00
Alexander Grund
b3c78809c0 GHA: Reenable CMake jobs 2024-11-26 12:14:09 -05:00
Alexander Grund
3347ea317c GHA: Add CMake subdir test 2024-11-26 12:14:09 -05:00
James E. King III
8ad7522ca0 Fix documentation links in the README 2024-11-25 22:27:27 +00:00
James E. King III
4eada1889f Appveyor: move to cppalliance account
- Removed MINGW64 run from Appveyor, as it is done in GHA.
- Updated README to use badges from cppalliance org.
2024-11-25 22:21:52 +00:00
James E. King III
9f5a992ffa Remove GHA macos-12 as it is not offered any more. 2024-11-25 20:07:45 +00:00
James E. King III
0b9a081d97 Refresh GitHub Actions and Appveyor CI
Moved baseline to C++11 due to our dependencies.

- Remove C++98 and C++03 from CI and mark C++11 baseline
- Remove duplicate jobs between Appveyor and GHA
- Disable CMake GHA jobs for now; broken
2024-11-25 18:59:55 +00:00
Rene Rivera
053fadace9 Update build deps. 2024-11-24 06:48:02 -05:00
Rene Rivera
2cbf3ad7d8 Move inter-lib dependencies to a project variable and into the build targets. 2024-11-24 06:48:02 -05:00
Rene Rivera
3bb682db62 Update copyright dates. 2024-11-24 06:48:02 -05:00
Rene Rivera
76b4bba9c2 Bump B2 require to 5.2 2024-11-24 06:48:02 -05:00
Rene Rivera
11d94f6794 Add requires-b2 check to top-level build file. 2024-11-24 06:48:02 -05:00
Rene Rivera
0231a500ed Add missing import-search for cconfig/predef checks. 2024-11-24 06:48:02 -05:00
Rene Rivera
7939bf7ae6 Add missing b2 testing module import. 2024-11-24 06:48:02 -05:00
Rene Rivera
1eed20166e Switch to library requirements instead of source. As source puts extra source in install targets. 2024-11-24 06:48:02 -05:00
Rene Rivera
1e9aa506d0 Make the library modular usable. 2024-11-24 06:48:02 -05:00
Alexander Grund
8e20aa1462 Fix ccache saving on cache hit (#70)
See boostorg/boost-ci#166
2022-06-24 08:58:29 -07:00
akr
d4be7a4fcb Changed the order of at() 2022-05-02 20:38:40 -04:00
akr
29e1d40e88 Added std::out_of_range tests 2022-05-02 20:38:40 -04:00
akr
ccca25537a Updated docs 2022-05-02 20:38:40 -04:00
akr
12be4b4464 Added tests 2022-05-02 20:38:40 -04:00
akr
b15fd0075f Added at(size_type) 2022-05-02 20:38:40 -04:00
James E. King III
abd6417090 re-add mingw to ci 2022-04-24 21:16:37 -04:00
James E. King III
eb3f18086e Fix badges in readme for develop 2022-04-15 16:21:30 -04:00
James E. King III
c811f468cd align CI to boost-ci standard and update README 2022-04-15 12:40:54 -04:00
Sam Darwin
709a03b9e2 Update GitHub Actions CI file (#61) 2021-08-04 07:07:10 -07:00
Peter Dimov
11d85403b9 Regenerate CMakeLists.txt 2021-05-30 07:28:07 +03:00
Sam Darwin
296f902453 Add GitHub Actions config [ci skip] (#60) 2021-03-03 18:26:18 -08:00
Sam Darwin
a16a1c3afa add drone config [ci skip] (#57) 2021-03-03 18:25:37 -08:00
Edward Diener
66a956b114 Add "cxxstd" json field 2021-01-19 17:48:52 -05:00
Glen Fernandes
b59fc97a67 Use core/allocator_access for allocator use 2020-05-25 22:57:13 -04:00
Andrey Semashev
4a38853898 Avoid using deprecated headers to silence compiler warnings. (#56)
The warnings are generated by boost/detail/iterator.hpp and
boost/detail/no_exceptions_support.hpp. Also, updated location of
addressof.hpp.
2020-05-13 06:44:47 -07:00
joprodrigues
54b15ad171 Improvement to m_do_find_from (#55)
Use find_if to inside find next bit
2020-04-26 10:11:36 -04:00
Edward Diener
ffff25ac00 Change __BORLANDC__ to BOOST_BORLANDC, which is defined in Boost config for the Embarcadero non-clang-based compilers. (#54) 2020-04-16 07:47:58 -07:00
Glen Fernandes
3e0107909b Replace Block(~0) with a max_limit<Block>::value 2020-01-22 07:41:06 -05:00
Glen Fernandes
8359a80feb Make DynamicBitset no longer depend on Serialization (#50) 2019-09-30 15:29:43 -04:00
James E. King III
db5da12bcd Update CI
This fixes #41
2019-06-23 20:19:38 -04:00
Miutsuru kariya
ab192ca5f1 Make default constructor non-explicit (#48)
It is better to support copy-initialization with default constructor. cf. LWG Issue 2193. Default constructors for standard library containers are explicit.
2019-06-12 19:45:11 -04:00
James E. King III
26918f80d5 Add support for std::hash and unit tests for hashing 2019-06-07 13:55:57 -04:00
Alexey Stukalov
229bced733 hash_value() for dynamic_bitset (support boost::hash) 2019-06-07 13:55:57 -04:00
Glen Fernandes
ccb380a1bc Switch from deprecated Test to LightweightTest 2019-06-07 07:02:31 -04:00
Sam Day
4de44e9112 Add basic CMake support. 2019-06-06 11:37:47 -04:00
James E. King III
3f650f50c3 Since coverity with gcc hangs, trying clang 2019-04-26 12:56:07 -04:00
James E. King III
b64e20079c Fix coverity scan job 2019-04-26 09:48:03 -04:00
Andrey Semashev
83bdf5a335 Reenabled popcnt for MSVC, improved perf by leveraging ILP.
On MSVC and compatible compilers popcnt is now enabled if it is known at
compile time that the target CPU supports popcnt instruction. Unfortunately,
MSVC does not have a predefined macro specifically for popcnt, so we have
to test for AVX instead. __POPCNT__ is still tested in case clang or user
defines it.

For MSVC, the 64-bit popcount is now also implemented on 32-bit targets by
issuing two 32-bit popcnt instructions. For gcc and compatible compilers,
16-bit popcount implementation is provided, which is better than the generic
popcount implementation, but still slower than byte-wise do_count.

The do_count algorithm implementations have been improved by leveraging
instruction level parallelism better, which gives 0 to 27% improvement and
no regressions.

Also made code formatting more consistent and reduced code duplication between
do_count implementations.
2019-04-26 08:55:53 -04:00
Tinko Bartels
c747bec057 Change sgi/stl links to boost.org. 2019-04-23 13:32:20 -04:00
James E. King III
f506b99f70 Update CI and change boost/timer deprecated use 2019-04-23 10:40:34 -04:00
Tinko Bartels
1b8b128f29 Replaced links to sgi.com with links to a mirror. 2019-04-22 12:20:38 -04:00
James E. King III
91625cece1 Disable hardware supported popcount on MSVC.
- the new implementation failed to check for hardware support
- the behavior was undefined on platforms without SSE4
2019-02-22 08:36:12 -05:00
James E. King III
a580c496fa fix set() ambiguity with range based call and default value 2018-11-03 16:45:29 -04:00
James E. King III
1ca15c5fcd Enhance CI with libc++ and VC2017 strict jobs 2018-11-03 15:54:53 -04:00
James E. King III
512ac37529 Enhance Travis CI build coverage 2018-10-28 10:42:35 -04:00
James E. King III
8e265c49f8 cleanup pending and detail headers 2018-10-21 12:44:12 -04:00
Evgeny Shulgin
a449a11a80 Add set/reset/flip functions to change sequences (#27)
* Add set(pos, len) function to change sequences
* Add reset(pos, len) function to clear sequences
* Add flip(pos, len) function to flip sequences
* Add custom range operations
2018-10-12 08:07:01 -04:00
James E. King III
a0735943f2 Merge branch 'master' into develop 2018-10-12 11:47:12 +00:00
Glen Fernandes
8fe1db1b08 Correct e-mail address 2018-09-23 08:55:34 -04:00
Glen Fernandes
d7d6555f85 Correct e-mail address 2018-09-05 08:11:50 -04:00
Evgeny Shulgin
a90fe08934 Add hardware supported popcount 2018-09-01 21:56:57 -04:00
James E. King III
b944aa3008 fix broken ci jobs in travis 2018-07-14 20:51:19 +00:00
James E. King III
759af5e853 Fix coverity badges in readme 2018-07-04 08:05:54 -04:00
James E. King III
7b6379a356 Add CI framework used in a number of other repositories:
- travis with valgrind, cppcheck, ubsan, codecov, covscan (future)
  - appveyor with MSVC 2010 through 2017, cygwin 32/64, mingw 32/64
  - README, LICENSE, etc.
2018-07-04 07:49:11 -04:00
Edward Diener
4f54d83981 Merge pull request #21 from NAThompson/remove_deprecated_header
Replace deprecated header with non-deprecated
2018-02-11 16:50:56 -05:00
Nick Thompson
4cac68e762 Remove deprecated header. 2018-02-11 15:08:19 -06:00
Marshall Clow
d3eb4faf0c Fix some warnings from gcc - https://github.com/boostorg/dynamic_bitset/issues/19 2018-01-31 11:11:12 -08:00
Marshall Clow
3f3662d39d Fix comment block in Jamfile; addresses https://github.com/boostorg/dynamic_bitset/issues/20 2018-01-31 09:27:51 -08:00
Edward Diener
184d1ba7ad Merge pull request #17 from DanielaE/feature/squash-narrowing-warnings
squash compiler warnings due to wrong order of type-cast and integral…
2017-06-27 09:36:10 -04:00
Daniela Engert
5b39db5ba0 squash compiler warnings due to wrong order of type-cast and integral type promotion
Signed-off-by: Daniela Engert <dani@ngrt.de>
2017-05-25 10:29:34 +02:00
Edward Diener
f4e49ff56f Revert masks change 2017-05-18 11:52:03 -04:00
Edward Diener
0c8640efb8 Merge branch 'develop' into LessThanFix 2017-05-17 20:59:44 -04:00
Edward Diener
0ead484c37 Implemented lexigraphic compare when bitsets have different lengths. 2017-05-17 20:59:08 -04:00
Edward Diener
6cafa21c6d Fix for gcc and clang using libstdc++. 2017-05-15 16:29:38 -04:00
Edward Diener
dbfce8e174 Allow different sized bitsets to be compared for <, >, <=, >= 2017-05-15 13:03:15 -04:00
Marshall Clow
684b6117dd Merge pull request #16 from DanielaE/fix/wrong-parameter-type
fix wrong parameter type in constructor of dynamic_bitset::reference
2017-04-16 07:03:51 -07:00
Daniela Engert
572e9d78ff fix wrong parameter type in constructor of dynamic_bitset::reference
Signed-off-by: Daniela Engert <dani@ngrt.de>
2017-03-18 13:49:16 +01:00
Edward Diener
e49b08a289 Added expected doc subdirectory 2017-01-09 03:09:28 -05:00
Edward Diener
d644c83b13 Merge pull request #14 from sehe/develop
Add support for Boost Serialization of dynamic_bitset<>
2017-01-08 23:35:27 -05:00
Seth Heeren
a50768c085 Add tests for serialization support 2017-01-09 03:26:14 +01:00
Seth Heeren
91895380c6 Add optional serialization support
This implemenents non-intrusive serialization support to dynamic_bitset<> based on Boost Serialization

 - it supports archives that require named elements
 - it gets private member access using a nested friend class (to decouple the interface entirely)
 - relies on boost/serialization/vector.hpp for actual implementation
2017-01-09 03:19:57 +01:00
Marshall Clow
7259281f5b Merge pull request #15 from danieljames/move-tests
This looks fine to me.  I'll watch the test bots, and merge to master in a week or so.
2016-07-01 08:24:46 -07:00
Daniel
92af4f52e9 Dummy jamfile for the super project's build script. 2016-07-01 09:10:18 +01:00
Daniel
d86f4ebddb Move tests into test subdirectory 2016-07-01 09:08:51 +01:00
ricky65
340822f979 Add capacity(), reserve(), and shrink_to_fit(). 2015-06-03 22:45:16 -07:00
Ahmed Charles
1c5e30fe49 Merge branch 'master' into develop 2015-06-03 22:44:34 -07:00
Ahmed Charles
0f48010783 Merge branch 'develop' 2015-06-03 22:43:44 -07:00
Ahmed Charles
1d59cc4788 Add converting constructor to minimal_allocator. 2015-05-19 00:36:26 -07:00
Marshall Clow
9879dd05b5 Merge changes from develop for the 1.58.0 release 2015-04-01 10:29:10 -07:00
Marshall Clow
29ba0c22b1 Merge pull request #13 from ahmedcharles/doc
Update 'more' links.
2015-03-18 16:10:57 -07:00
Daniel James
8b7374b1db Update 'more' links.
[SVN r44996]
2015-03-18 22:51:14 +00:00
Steven Watanabe
2091a4fd18 Merge branch 'develop' 2015-03-07 11:53:03 -07:00
Marshall Clow
225064d355 Patch by Riccardo Marcangelo: Added a pop_back() member function which decreases the size of the bitset by one 2014-09-15 08:29:05 -07:00
Noel Belcourt
b151c97fd2 Merge pull request #10 from danieljames/metadata
Create metadata file.
2014-08-23 14:08:58 -06:00
Daniel James
a93174ddf9 Add metadata file. 2014-08-18 14:58:36 +01:00
Noel Belcourt
1611aeb16a Merge pull request #9 from boostorg/develop
Merge develop to master

Tested on Darwin, thanks.
2014-06-25 13:27:29 -06:00
Ahmed Charles
3229e26108 Merge pull request #8 from glenfe/develop
Support C++11 minimal allocators and add noexcept specifications
2014-05-28 10:12:07 -07:00
Glen Fernandes
083c5e6214 Use non-deprecated macro for r-value reference support detection 2014-05-19 17:41:50 -07:00
Glen Fernandes
18eb52ecee Add noexcept specifications 2014-05-19 17:39:39 -07:00
Glen Fernandes
a3ea40d932 Support C++11 minimal allocators 2014-05-19 17:38:23 -07:00
Ahmed Charles
dd7cdc794e Merge branch 'master' into develop 2014-05-17 16:32:16 -06:00
Ahmed Charles
10195375ed Fix lacking include in previous pull request. 2014-05-17 16:30:18 -06:00
Noel Belcourt
9ed6f608a1 Merge pull request #6 from 0-wiz-0/master
Fix implicit conversion changes signedness problems.

Looks good, thanks!
2014-05-16 11:46:05 -06:00
Boleslaw Ciesielski
ba0ba59f24 Add support to dynamic_bitset for compiling with exceptions disabled by using BOOST_TRY/BOOST_CATCH.
This applies the patch from bug https://svn.boost.org/trac/boost/ticket/9939
2014-05-16 12:05:43 -04:00
Thomas Klausner
bcc384b604 Fix implicit conversion changes signedness problems.
clang-3.5 trunk 201163 and OS X's clang (not sure which version)
report -Wsign-conversion warnings with this header. This patch fixes
them.

https://svn.boost.org/trac/boost/ticket/9725

Signed-off-by: Thomas Klausner <tk@giga.or.at>
2014-05-16 16:38:38 +02:00
Ahmed Charles
7b14895ec6 Merge branch 'develop' 2014-03-05 21:22:39 -08:00
Ahmed Charles
eb6004d98d Merge branch 'master' into develop 2014-03-05 21:17:47 -08:00
Ahmed Charles
f34a8a4b23 Fix broken build due to addressof() not being included on some platforms. 2014-03-04 12:21:31 -08:00
Ahmed Charles
d19aeced56 Add test_set() (#6164). 2014-03-01 18:19:54 -08:00
Ahmed Charles
5f4c0dc4d9 Improve testing for set(pos, val). 2014-03-01 18:13:58 -08:00
Ahmed Charles
1b880102fe Add all() (#8445).
Includes test cases.
2014-03-01 18:11:59 -08:00
Ahmed Charles
e8b37ccf10 Improve tests for any() and none(). 2014-03-01 18:09:52 -08:00
Ahmed Charles
e7aa32f5db Reenable check within test for dynamic_bitset::any(). 2014-03-01 18:09:51 -08:00
Ahmed Charles
86b177d3ee Add support for move constructors in C++11 (#6947). 2014-03-01 18:06:19 -08:00
Ahmed Charles
4c6825716f Fix MSVC warnings (#9621). There should be no behavior change. 2014-03-01 17:56:52 -08:00
Ahmed Charles
ac0baa94ee Whitespace changes. 2014-03-01 17:43:44 -08:00
Ahmed Charles
ae64496e98 Merge develop into master.
Tests on develop are passing.
2014-03-01 17:38:08 -08:00
Alexey Stukalov
0a1621f0e7 simplify dynamic_bitset::find_next()
Instead of masking all bits in the current block that were already
visited and then finding the lowest remaining bit, it shifts the current
block directly to the first unvisited bit and identifies the lowest
set bit.
It requires fewer operations that the original implementation and should
be faster.

See https://svn.boost.org/trac/boost/ticket/5159.
2014-03-01 17:26:39 -08:00
Marshall Clow
4d8b9b5c33 Merge pull request #4 from ahmedcharles/patch-2
Merge master into develop.
2014-02-24 07:51:35 -08:00
Ahmed Charles
9fe813dd93 Merge branch 'master' into develop. 2014-02-19 01:27:09 -08:00
Ahmed Charles
dd69fe8756 Create merge point from develop to master after git migration.
Both branches are the same, so this merge is uninteresting.
2014-02-18 23:34:43 -08:00
Marshall Clow
20df4eadc8 Merge pull request #2 from ahmedcharles/patch-1
Fix MSVC warning about mismatched sizes.
2014-02-18 22:44:15 -08:00
Ahmed Charles
cccd1f74dc Fix MSVC warning about mismatched sizes. 2014-02-18 22:04:43 -08:00
Ahmed Charles
71a5cc6eeb Rename variable to make slightly more sense. 2014-02-18 21:49:59 -08:00
Ahmed Charles
c9fa6dbdd1 Fix spelling mistake. 2014-02-18 21:46:27 -08:00
Gennaro Prota
7186546f7d Removed unused local typedef in dyn_bitset_unit_tests1.cpp.
[SVN r86557]
2013-11-03 21:41:30 +00:00
Gennaro Prota
b82bfe4832 Merged the latest tweaks to dynamic_bitset/example/timing_tests.cpp (trunk revision 86553).
[SVN r86556]
2013-11-03 21:33:30 +00:00
Gennaro Prota
a257dead26 Minor adjustments to dynamic_bitset's timing_test.cpp.
[SVN r86553]
2013-11-03 20:46:56 +00:00
Marshall Clow
f44fbae9ba Merge fixes to release; Fixes #5439
[SVN r72331]
2011-06-01 15:59:04 +00:00
Marshall Clow
d6f1835fbb Applied patch; Refs #5439
[SVN r71505]
2011-04-26 14:41:50 +00:00
Steven Watanabe
e6fc8e8ec9 Merge dynamic_bitset from the trunk
[SVN r67617]
2011-01-03 16:38:46 +00:00
Steven Watanabe
734861bdac Fix test for C++0x
[SVN r67581]
2011-01-02 19:24:47 +00:00
Steven Watanabe
594140a081 Document intersects. Fixes #2837.
[SVN r63221]
2010-06-22 04:38:42 +00:00
Steven Watanabe
59e99b9b45 Use the correct variable type to save the result of count_extra_bits(). Fixes #4022.
[SVN r62898]
2010-06-13 04:36:50 +00:00
Steven Watanabe
f199a7f006 Cast an anonymous enum to bool. Fixes #4025.
[SVN r62897]
2010-06-13 04:23:35 +00:00
Troy D. Straszheim
60f871da0c rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back
[SVN r56942]
2009-10-17 02:07:38 +00:00
Troy D. Straszheim
d77a2c4afa rm cmake from the release branch before it goes out broken. Policy dictates that you never commit to release, you commit to trunk and merge to release.
[SVN r56941]
2009-10-17 01:10:45 +00:00
Troy D. Straszheim
76d2f9d4d1 Copyrights on CMakeLists.txt to keep them from clogging up the inspect
reports.  This is essentially the same commit as r55095 on the release
branch.



[SVN r55159]
2009-07-26 00:49:56 +00:00
Troy D. Straszheim
e3a2ca7276 Add basic copyright/license to keep cmake out of the inspection report
[SVN r55095]
2009-07-22 21:51:01 +00:00
Daniel James
38819630fd Merge dynamic bitset fixes for gcc 4.3.3.
Merged revisions 52879-52881,53050 via svnmerge from 
https://svn.boost.org/svn/boost/trunk

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


[SVN r53259]
2009-05-25 20:26:02 +00:00
Daniel James
5c79c20827 Merge dynamic bitset from release.
I think the recent changes in trunk and release were for the same problem. But
I'm not sure so I've merged them together. Hopefully, the release branch might
fix the Intel C++ errors as well.

------------------------------------------------------------------------
r52960 | dgregor | 2009-05-13 07:11:03 +0100 (Wed, 13 May 2009) | 1 line

Use enum constants rather than local variables for integral constants. Should fix dynamic_bitset failures on GCC 4.3.x
------------------------------------------------------------------------



[SVN r53050]
2009-05-16 14:58:33 +00:00
Douglas Gregor
6d0f9801f5 Use enum constants rather than local variables for integral constants. Should fix dynamic_bitset failures on GCC 4.3.x
[SVN r52960]
2009-05-13 06:11:03 +00:00
Hartmut Kaiser
ed32df5ad2 Minor comment edit
[SVN r52881]
2009-05-10 16:59:27 +00:00
Hartmut Kaiser
da0b582703 Fixing the fix by taking into account __GNUC_PATCHLEVEL__ as well
[SVN r52880]
2009-05-10 16:55:07 +00:00
Hartmut Kaiser
622c8d8fd5 Applying patch fixing problem on certain patch levels for gcc.4.3.3/Ubuntu
[SVN r52879]
2009-05-10 16:52:14 +00:00
Troy D. Straszheim
b7eedd0f46 merge of cmake build files from trunk per beman
[SVN r50756]
2009-01-24 18:57:20 +00:00
Gennaro Prota
16ca9cbb3c dynamic_bitset: ported revisions 49433, 49586 from trunk
[SVN r50470]
2009-01-04 23:03:28 +00:00
Michael A. Jackson
97d2bff3b6 Updating dependency information for modularized libraries.
[SVN r49628]
2008-11-07 17:05:27 +00:00
Michael A. Jackson
a143af6e2f Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use.
[SVN r49627]
2008-11-07 17:02:56 +00:00
Gennaro Prota
59825bc8db dynamic_bitset:
* removed use of BOOST_WORKAROUND in #if for gcc bug c++/8419, as recent
      changes to the implementation of BOOST_WORKAROUND broke its usage with
      arguments such as ( (__GNUC__) * 100 * 100 + (__GNUC_MINOR__) * 100 )


[SVN r49586]
2008-11-04 16:52:00 +00:00
Michael A. Jackson
7d1144a461 Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor
[SVN r49510]
2008-11-01 13:15:41 +00:00
Gennaro Prota
c298ba0c5f dynamic_bitset:
always provide a definition for static data members of const integral type

[SVN r49433]
2008-10-22 15:47:27 +00:00
Gennaro Prota
4efeaee302 dynamic_bitset: full (recursive) sync with trunk for libs/dynamic_bitset/
[SVN r49423]
2008-10-21 17:57:39 +00:00
Gennaro Prota
066e7dcf71 dynamic_bitset:
ported revisions 49345-49346 (roughly: workaround for VC++ <= 7.0 removal, comment and documentation improvements) from trunk

[SVN r49378]
2008-10-18 11:04:39 +00:00
Gennaro Prota
574f1dfe62 dynamic_bitset: documentation:
* improved documentation of constructor from block range, with notes about library issue 438
    * fixed/improved wording and markup in several places
    * partially adjusted word wrap, for consistency


[SVN r49346]
2008-10-15 14:38:19 +00:00
Gennaro Prota
e953b16cee dynamic_bitset:
* removed one of the workarounds for VC++ <= 7.0 (we don't run tests on
      those compilers, anymore, so we don't really know if the library still
      works with them); other such workarounds exist, though: removing them
      involves heavy refactoring and is probably not worth the corresponding
      risk of destabilization; comments have been added about this latter point

    * comment fixes in detail/dynamic_bitset.hpp


[SVN r49345]
2008-10-15 12:33:37 +00:00
Gennaro Prota
6b0d9627a8 Ported *all* my trunk changes not yet merged so far, i.e. revisions 48251-48252,48280,48290,48350,48478,48496,48663-48664,48695,48729-48730; besides dynamic_bitset, these include fixes to setup_boostbook.sh and setup_boostbook.py, and changes to config/suffix.hpp [So: the affected "elements" are: a) the two setup_boostbook scripts, config/suffix.hpp and dynamic_bitset --note: yes, the list is exhaustive: all and only]
[SVN r48773]
2008-09-14 10:46:28 +00:00
Gennaro Prota
180aa15c44 dynamic_bitset: in reference constructor, assert() before it is (eventually) too late!
[SVN r48730]
2008-09-11 09:46:54 +00:00
Gennaro Prota
7ed46a6667 dynamic_bitset: in dyn_bitset_unit_tests1.cpp, replaced very ill-thought assert() with more sensible code to check for "negative sizes"
[SVN r48729]
2008-09-11 09:35:49 +00:00
Gennaro Prota
24d2081a73 added specific tests for constructor dispatch and clarified the corresponding comments a bit; minor formatting consistency fixes; updated documentation and added license reference text to it
[SVN r48695]
2008-09-10 10:07:46 +00:00
Gennaro Prota
f6ce97de67 dynamic_bitset: added spaces in the definition of BOOST_dynamic_bitset_is_numeric (detail/dynamic_bitset.hpp), to avoid getting an unintended alternative token "<:" when invoking the macro with argument "::boost::[u]long_long_type"
[SVN r48664]
2008-09-08 10:20:49 +00:00
Gennaro Prota
7530a40476 dynamic_bitset: changed a using directive to a set of using declarations, in the hope that this will fix regressions of Intel and others; (very minor) changed comment text
[SVN r48663]
2008-09-08 10:10:02 +00:00
Gennaro Prota
c05a47b50d dynamic_bitset:
* added user-declared default constructor to value_to_type<bool> (yeah, the
      usual "initializing a const instance of an empty class" problem, which
      also affected S. Meyers' null)
    * explicitly qualified occurrence of "bits_per_block" in count() member
      function, to let gcc 3.4.x understand that it *is* a constant expression
    * fixed namespace qualification for vector_max_size_workaround (should've
      been done in the previous commit, sorry)


[SVN r48496]
2008-08-31 11:53:45 +00:00
Gennaro Prota
d09c7d2180 dynamic_bitset:
* fixed form of some remaining copyright lines
    * using namespace detail::dynamic_bitset_impl for *all* implementation
      details (dynamic_bitset_*count*_impl removed) and consequently shortened
      some entity names
    * switched from enum to bools for "enum mode", to help several compilers
      which show problems with recognizing access_by_bytes and access_by_blocks
      as constant expressions
    * minor comment changes
    * implemented the do-the-right-thing dispatch for constructor from
      iterator-range, a la standard sequence containers (feature request #2172)
    * dropped now useless comparison with zero in reference constructor

NOTE:
    updated tests and documentation not committed yet; let's wait for the trunk
    results first


[SVN r48478]
2008-08-30 18:00:30 +00:00
Gennaro Prota
bddf77e5a4 boost/pending/: ported revision 48251 ("integer_log2.hpp and lowest_bit.hpp, in boost/pending/: little comment cleanup (svn anchors, etc.); added a static_cast<> to silence (harmless) MSVC++ warnings") from trunk
[SVN r48353]
2008-08-24 18:16:24 +00:00
Gennaro Prota
d80a9dbdf8 dynamic_bitset: tentative code reworking in count() member function, to help gcc 3.4.6 on Sandia-sun, which seems to have troubles with a simple constant expression of enumeration type (see <http://www.boost.org/development/tests/trunk/developer/dynamic_bitset_.html>)
[SVN r48280]
2008-08-21 11:49:12 +00:00
Gennaro Prota
15b61f694a dynamic_bitset:
* clean up and fix of copyright notices for the include files that are directly under boost/
    * parenthesized a couple of macro names in boost/dynamic_bitset/config.hpp
      (yeah, a bit paranoid, I know :-))
    * removed some superfluous comments and enclosed an url in angle brackets
    * changed block_width_type, to avoid a few level 4 warnings with MSVC++
    * added the usual private-and-non-implemented copy members to bit_appender
    * removed useless #pragma warning(disable:4996) for MSVC++ (it should have
      been eventually applied to much more places than it was; and, anyhow, the
      only sensible way to get rid of the warning is to disable it globally)
    * slight tweak in to_ulong (assert moved a bit earlier)


[SVN r48252]
2008-08-20 11:16:16 +00:00
Gennaro Prota
eef25927d7 integer_log2.hpp and lowest_bit.hpp, in boost/pending/: little comment cleanup (svn anchors, etc.); added a static_cast<> to silence (harmless) MSVC++ warnings
[SVN r48251]
2008-08-20 11:06:23 +00:00
Gennaro Prota
357e434387 dynamic_bitset.hpp: (minor) removed tab characters introduced with revision 35066 on trunk
[SVN r47666]
2008-07-21 23:46:39 +00:00
Gennaro Prota
a8998ae8a0 dynamic_bitset: in example3.cpp, changed #include of boost/dynamic_bitset.hpp to quoted form and moved the directive itself at the top (there has been discussion in the past about using the quoted form for boost includes, but it's almost two years now that the resolution of core issue 370 has been voted into WP...)
[SVN r47456]
2008-07-15 20:49:32 +00:00
Gennaro Prota
aa6053121c dynamic_bitset: cleaner implementation of to_ulong (which should also avoid some warnings on 64-bit implementations)
[SVN r47401]
2008-07-13 19:38:48 +00:00
Gennaro Prota
5d66eda2ac dynamic_bitset: removed svn keywords and anchors; removed useless "see ... for documentation" pointers; fixed copyright notices and made all "comment headers" consistent; cleaned up trailing whitespaces
[SVN r47392]
2008-07-13 19:08:31 +00:00
Gennaro Prota
771e3d8779 dynamic_bitset documentation and examples:
Documentation:
    --------------

    * converted from HTML 4.01 Transitional to XHTML 1.1 (reason: the website
      uses already XHTML 1.0 Strict, and our page didn't validate as such, even
      though on the website a link to the W3C markup validation service is
      affixed)
    * removed some misleading sentences
    * referenced the source files of examples, so that they do not go out of
      sync again
    * clarified rationale section

    Example files:
    --------------

    * example 3 shows that stream extraction may expand the bitset
    * minor improvements to all examples


[SVN r47389]
2008-07-13 17:55:45 +00:00
Gennaro Prota
d8b2330d42 dynamic_bitset.html: Documentation: dropped all sentences of the kind "note that the expression... is equivalent to creating a temporary copy and then...". They seem to be just a sort of performance warning and carry no useful information. This fixes issue #1591.
[SVN r47328]
2008-07-11 21:21:14 +00:00
Daniel James
61702fef06 Merged revisions 43206,43208-43213 via svnmerge from
https://svn.boost.org/svn/boost/trunk

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


[SVN r43214]
2008-02-10 16:39:38 +00:00
Daniel James
1b7c462afe Point links to the pages that used to be in 'more' to the site.
[SVN r43210]
2008-02-10 15:02:17 +00:00
Daniel James
8a1da9667b Link to people pages on the website, as they've been removed from the download.
[SVN r43209]
2008-02-10 14:56:22 +00:00
Boris Gubenko
6bf10f4ef0 merge change in trunk (changeset/41778) to release branch
[SVN r41959]
2007-12-10 18:51:19 +00:00
Boris Gubenko
717fb80e40 compute 'result' in to_ulong() as it is done in Boost 1.34
[SVN r41778]
2007-12-06 10:47:52 +00:00
Beman Dawes
0999a9b907 Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41370]
2007-11-25 18:38:02 +00:00
Beman Dawes
4ae778ba4a Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41369]
2007-11-25 18:07:19 +00:00
Beman Dawes
c9dcc1de64 config, detail, filesystem, system, tools, at 41278.
[SVN r41316]
2007-11-23 17:03:14 +00:00
Beman Dawes
adc36a2b7f Add missing copyright and license
[SVN r40835]
2007-11-06 13:41:19 +00:00
Beman Dawes
cc9b262cb9 Starting point for releases
[SVN r39706]
2007-10-05 14:25:06 +00:00
Vladimir Prus
a8c3c80888 Update to V2
[SVN r38525]
2007-08-08 19:31:55 +00:00
Vladimir Prus
3a04624801 Remove V1 Jamfiles
[SVN r38516]
2007-08-08 19:02:26 +00:00
Beman Dawes
08357c3972 Add copyright, license
[SVN r35905]
2006-11-07 19:11:57 +00:00
Frederick Akalin
41e1f468d3 added pragma to shut up warning for std::fill_n
[SVN r35066]
2006-09-11 02:23:00 +00:00
Gennaro Prota
ae44c787e2 identification
[SVN r34907]
2006-08-19 11:14:34 +00:00
Gennaro Prota
60375651d9 identification
[SVN r34905]
2006-08-19 11:04:25 +00:00
Gennaro Prota
50ffc7be59 (minor) oops in previous edit
[SVN r34904]
2006-08-19 10:55:07 +00:00
Gennaro Prota
02f4b61f14 identification
[SVN r34903]
2006-08-19 10:52:24 +00:00
Gennaro Prota
07b5b85dfe some cleanup (beware: not compiled)
[SVN r34883]
2006-08-13 15:08:24 +00:00
Gennaro Prota
1170f90afb boost guidelines (mainly from inspect tool: tabs, license reference text, etc.)
[SVN r34752]
2006-07-27 10:27:37 +00:00
Gennaro Prota
98917625dd improved swap tests
[SVN r34642]
2006-07-20 22:13:26 +00:00
Gennaro Prota
109a0aef13 updated copyright notice (years); used <assert.h>
[SVN r34401]
2006-06-25 19:32:44 +00:00
Gennaro Prota
5995354ceb updated copyright notice (years); used <assert.h>; included subdir main header; more count() and operator< tests; minor fixes
[SVN r34400]
2006-06-25 19:31:06 +00:00
Gennaro Prota
7f268666ad updated copyright notice (years); included subdir main header
[SVN r34399]
2006-06-25 19:28:33 +00:00
Gennaro Prota
ecbc0c4262 updated copyright notice (years); included "dynamic_bitset/dynamic_bitset.hpp"; added BOOST_BITSET_TEST_COUNT_OF (in the meantime); used -Wundef immune idiom everywhere; improved and simplified test code for construction from unsigned long; fixed some comments; added "all_1s" helper variable
[SVN r34398]
2006-06-25 19:26:21 +00:00
Gennaro Prota
184337e1cc updated copyright notice (years); used <assert.h> instead of <cassert>; include "dynamic_bitset/dynamic_bitset.hpp"; added a comment related to a Borland numeric_limits<> issue; some cleanup; strengthened many tests
[SVN r34397]
2006-06-25 19:16:48 +00:00
Gennaro Prota
2726ad0c3c updated copyright notice (years); added slash to doc url; introduced shifter<> template, for the implementation of the constructor from ulong
[SVN r34396]
2006-06-25 19:05:46 +00:00
Gennaro Prota
30bd2e5bab updated copyright notice (years); added slash to doc url; reworded some comments
[SVN r34395]
2006-06-25 18:58:27 +00:00
Gennaro Prota
38f7aa5d40 updated copyright notice (years); added slash to doc url; used <assert.h> instead of <cassert>; added assert in reference constructor; clarified some comments; removed superfluos Allocator parameter from init_from_string(); improved constructor from unsigned long, push_back(bool), to_ulong(), is_proper_subset_of(), operator <(); cleanup
[SVN r34394]
2006-06-25 18:54:35 +00:00
Gennaro Prota
48aaaabed2 init_from_string() doesn't need the alloc parameter; usual style for BOOST_WORKAROUNDs
[SVN r34303]
2006-06-14 17:33:31 +00:00
Gennaro Prota
755fa101f8 included *sub-directory* main source file (dynamic_bitset/dynamic_bitset.hpp); immunized BOOST_WORKAROUND invocations against gcc's -Wundef (for now); used single parameter version of std::ctype<> ::widen (which is valid regardless of the resolution of lib issue 530)
[SVN r34302]
2006-06-14 14:59:25 +00:00
Gennaro Prota
9c0620b7f9 use our usual -Wundef compatible form for IBM's AIX workaround; added a comment pointing out that the compiler is actually right
[SVN r34115]
2006-05-29 17:43:42 +00:00
Gennaro Prota
30b986e549 to_ulong function cleanup (including removal of a superfluous if test)
[SVN r34114]
2006-05-29 17:12:25 +00:00
Gennaro Prota
eb7f05d0c4 made valid HTML 4.01 transitional (but this redirect tecnique is considered poor practice by the W3C, anyway; among other things, it breaks the browser's back button)
[SVN r34113]
2006-05-29 16:58:42 +00:00
Gennaro Prota
fff12b2c59 added new test for to_ulong function
[SVN r34112]
2006-05-29 16:43:42 +00:00
Gennaro Prota
fb5e1d024d in to_string(): removed initial comment (besides having several typos, it was incosistent: other test functions don't explain what the tested function does); avoided all-uppercase identifiers and shortened test expression; minor cleanup
[SVN r34111]
2006-05-29 16:40:15 +00:00
56 changed files with 11853 additions and 6841 deletions

97
.appveyor.yml Normal file
View File

@@ -0,0 +1,97 @@
# Copyright 2016, 2017 Peter Dimov
# Copyright 2017 - 2019 James E. King III
# Copyright 2019 - 2021 Alexander Grund
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
#
# Generic Appveyor build script for boostorg repositories
# See: https://github.com/boostorg/boost-ci/
#
# Instructions for customizing this script for your library:
#
# 1. Customize the compilers and language levels you want.
# 2. If you have more than include/, src/, test/, example/, examples/,
# benchmark/ or tools/ directories, set the environment variable DEPINST.
# For example if your build uses code in "bench/" and "fog/" directories:
# - DEPINST: --include bench --include fog
# 3. Enable pull request builds in your boostorg/<library> account.
#
# That's it - the script will do everything else for you.
#
version: 1.0.{build}-{branch}
shallow_clone: true
branches:
only:
- master
- develop
- /bugfix\/.*/
- /feature\/.*/
- /fix\/.*/
- /pr\/.*/
skip_commits:
files:
- LICENSE
- meta/*
- README.md
matrix:
fast_finish: false
# Adding MAYFAIL to any matrix job allows it to fail but the build stays green:
allow_failures:
- MAYFAIL: true
environment:
global:
B2_CI_VERSION: 1
GIT_FETCH_JOBS: 4
# see: http://www.boost.org/build/doc/html/bbv2/overview/invocation.html#bbv2.overview.invocation.properties
# to use the default for a given environment, comment it out; recommend you build debug and release however:
# on Windows it is important to exercise all the possibilities, especially shared vs static, however most
# libraries that care about this exercise it in their Jamfiles...
B2_ADDRESS_MODEL: 32,64
B2_LINK: shared,static
# B2_THREADING: threading=multi,single
B2_VARIANT: release
matrix:
- FLAVOR: Visual Studio 2017 C++2a Strict
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
B2_CXXFLAGS: -permissive-
B2_CXXSTD: 2a
B2_TOOLSET: msvc-14.1
- FLAVOR: Visual Studio 2017 C++14/17
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
B2_CXXSTD: 14,17
B2_TOOLSET: msvc-14.1
- FLAVOR: cygwin (32-bit)
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
ADDPATH: C:\cygwin\bin;
B2_ADDRESS_MODEL: 32
B2_CXXSTD: 11,14,1z
B2_TOOLSET: gcc
- FLAVOR: cygwin (64-bit)
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
ADDPATH: C:\cygwin64\bin;
B2_ADDRESS_MODEL: 64
B2_CXXSTD: 11,14,1z
B2_TOOLSET: gcc
install:
- git clone --depth 1 https://github.com/boostorg/boost-ci.git C:\boost-ci-cloned
# Copy ci folder if not testing Boost.CI
- if NOT "%APPVEYOR_PROJECT_NAME%" == "boost-ci" xcopy /s /e /q /i /y C:\boost-ci-cloned\ci .\ci
- rmdir /s /q C:\boost-ci-cloned
- ci\appveyor\install.bat
build: off
test_script: ci\build.bat

168
.clang-format Normal file
View File

@@ -0,0 +1,168 @@
# ============================================================================
# Copyright 2025 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)
# ============================================================================
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: AcrossEmptyLinesAndComments
AlignConsecutiveBitFields: AcrossEmptyLinesAndComments
AlignConsecutiveDeclarations: AcrossEmptyLinesAndComments
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignEscapedNewlines: Right
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: AllDefinitions
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros: [ ]
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Never
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: true
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: true
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: ''
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros: [ ]
IfMacros: [ ]
IncludeBlocks: Regroup
IncludeCategories:
- Regex: 'top_level_namespace.hpp'
Priority: 0
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 1
CaseSensitive: false
IncludeIsMainRegex: ''
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: false
IndentPPDirectives: AfterHash
IndentExternBlock: AfterExternBlock
IndentRequires: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: Wrapped
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Middle
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: true
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Both
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Always
SpacesInConditionalStatement: true
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: true
SpacesInSquareBrackets: true
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros: [ ]
StatementMacros: [ ]
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros: [ ]
# Local Variables:
# mode: yaml
# End:
# vim: set ft=yaml:

31
.codecov.yml Normal file
View File

@@ -0,0 +1,31 @@
# Copyright 2019 - 2021 Alexander Grund
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
#
# Sample codecov configuration file. Edit as required
codecov:
max_report_age: off
require_ci_to_pass: yes
notify:
# Increase this if you have multiple coverage collection jobs
after_n_builds: 2
wait_for_ci: yes
parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no
# Change how pull request comments look
comment:
layout: "reach,diff,flags,files,footer"
# Ignore specific files or folders. Glob patterns are supported.
# See https://docs.codecov.com/docs/ignoring-paths
ignore:
- libs/dynamic_bitset/test/
- test/

110
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,110 @@
#
# Copyright 2020-2021 Peter Dimov
# Copyright 2021 Andrey Semashev
# Copyright 2021-2024 Alexander Grund
# Copyright 2022-2025 James E. King III
# Copyright 2023 Alan de Freitas
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
#
# This workflow uses the Boost.CI reusable workflow which builds a variety of
# configurations of your project, runs tests, and generates code coverage reports.
#
# To use it, copy this file into your repository as `.github/workflows/ci.yml` and
# customize it appropriately.
#
---
name: Boost.CI
on:
pull_request:
push:
branches:
- master
- develop
- bugfix/**
- feature/**
- fix/**
- pr/**
paths-ignore:
- LICENSE
- meta/**
- README.md
jobs:
call-boost-ci:
name: Run Boost.CI
uses: boostorg/boost-ci/.github/workflows/reusable.yml@master
with:
# These compilers fail.
exclude_compiler: 'clang-3.5,clang-3.6,clang-3.7,clang-3.8,gcc-4.8,gcc-4.9'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
COVERITY_SCAN_NOTIFICATION_EMAIL: ${{ secrets.COVERITY_SCAN_NOTIFICATION_EMAIL }}
COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
antora:
name: Antora docs
strategy:
matrix:
include:
- { name: Windows, os: windows-latest }
- { name: Ubuntu, os: ubuntu-latest }
- { name: macOS, os: macos-15 }
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
steps:
- name: Install packages
uses: alandefreitas/cpp-actions/package-install@v1.8.8
with:
apt-get: git cmake
- name: Clone Boost.DynamicBitset
uses: actions/checkout@v4
- name: Clone Boost
uses: alandefreitas/cpp-actions/boost-clone@v1.8.8
id: boost-clone
with:
branch: ${{ (github.ref_name == 'master' && github.ref_name) || 'develop' }}
boost-dir: ../boost-source
scan-modules-dir: .
scan-modules-ignore: dynamic_bitset
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Setup Ninja
if: runner.os == 'Windows'
uses: seanmiddleditch/gha-setup-ninja@v5
- name: Build Antora docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global --add safe.directory "$(pwd)"
cd ..
BOOST_SRC_DIR="$(pwd)/boost-source"
export BOOST_SRC_DIR
cd dynamic_bitset
cd doc
bash ./build_antora.sh
# Antora returns zero even if it fails, so we check if the site directory exists.
if [ ! -d "html" ]
then
echo "Antora build failed"
exit 1
fi
- name: Create Antora docs artifact
uses: actions/upload-artifact@v4
with:
name: antora-docs-${{ matrix.name }}
path: doc/html

96
CMakeLists.txt Normal file
View File

@@ -0,0 +1,96 @@
# Generated by `boostdep --cmake dynamic_bitset`
# Copyright 2020 Peter Dimov
# Copyright 2025 Gennaro Prota
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.16)
project(boost_dynamic_bitset VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
set(BOOST_DYNAMIC_BITSET_IS_ROOT OFF)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(BOOST_DYNAMIC_BITSET_IS_ROOT ON)
endif ()
add_library(boost_dynamic_bitset INTERFACE)
add_library(Boost::dynamic_bitset ALIAS boost_dynamic_bitset)
target_include_directories(boost_dynamic_bitset INTERFACE include)
if (BOOST_DYNAMIC_BITSET_IS_ROOT)
# This means this script will be executed as the root CMakeLists.txt
# so the Boost:: targets are not available unless we explicitly include
# them here. MrDocs executes this script as root too.
if (NOT DEFINED BOOST_SRC_DIR AND DEFINED ENV{BOOST_SRC_DIR})
set(DEFAULT_BOOST_SRC_DIR "$ENV{BOOST_SRC_DIR}")
else ()
set(DEFAULT_BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
endif ()
set(BOOST_SRC_DIR ${DEFAULT_BOOST_SRC_DIR} CACHE STRING "Boost source dir to use when running CMake from this directory")
if (NOT IS_ABSOLUTE ${BOOST_SRC_DIR})
set(BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${BOOST_SRC_DIR}")
endif ()
# Validate BOOST_SRC_DIR
set(BOOST_SRC_DIR_IS_VALID ON)
foreach (F "CMakeLists.txt" "Jamroot" "boost-build.jam" "bootstrap.sh" "libs")
if (NOT EXISTS "${BOOST_SRC_DIR}/${F}")
message(STATUS "${BOOST_SRC_DIR}/${F} does not exist. Fallback to find_package.")
set(BOOST_SRC_DIR_IS_VALID OFF)
break()
endif ()
endforeach ()
if (NOT BOOST_SRC_DIR_IS_VALID)
message(FATAL_ERROR "BOOST_SRC_DIR is not valid. Please set it to the root of a Boost checkout.")
endif ()
# If BOOST_SRC_DIR is valid, fallback to find_package
set(CMAKE_FOLDER Dependencies)
set(BOOST_INCLUDE_LIBRARIES assert config container_hash core throw_exception)
set(BOOST_EXCLUDE_LIBRARIES dynamic_bitset)
set(PREV_BUILD_TESTING ${BUILD_TESTING})
set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE)
add_subdirectory(${BOOST_SRC_DIR} Dependencies/boost EXCLUDE_FROM_ALL)
set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${BOOST_SRC_DIR}/tools/cmake/include")
unset(CMAKE_FOLDER)
endif()
target_link_libraries(boost_dynamic_bitset
INTERFACE
Boost::assert
Boost::config
Boost::container_hash
Boost::core
Boost::throw_exception
)
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
endif()
if (DYNAMIC_BITSET_MRDOCS_BUILD)
set(INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include")
# Create a temporary source file that includes boost/dynamic_bitset.hpp.
set(TEMP_CPP_FILE "${CMAKE_CURRENT_BINARY_DIR}/dynamic_bitset_for_mrdocs.cpp")
file(WRITE ${TEMP_CPP_FILE} "// This file is generated automatically by CMake\n\n")
file(APPEND ${TEMP_CPP_FILE} "#include \"boost/dynamic_bitset.hpp\"\n")
# Create a custom target for MrDocs.
add_library(dynamic_bitset_mrdocs_target ${TEMP_CPP_FILE})
# This is to get the documentation of the constructor from basic_string_view.
set_target_properties(dynamic_bitset_mrdocs_target PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES)
# Set any other target properties here.
target_include_directories(dynamic_bitset_mrdocs_target PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(dynamic_bitset_mrdocs_target PRIVATE boost_dynamic_bitset)
file(GLOB BOOST_MODULE_PATHS "$ENV{BOOST_SRC_DIR}/libs/*/include")
target_include_directories(dynamic_bitset_mrdocs_target PRIVATE ${BOOST_MODULE_PATHS})
# Don't create any other targets.
return()
endif()

View File

@@ -1,15 +0,0 @@
#
# 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 :
[ run dyn_bitset_unit_tests1.cpp ]
[ run dyn_bitset_unit_tests2.cpp ]
[ run dyn_bitset_unit_tests3.cpp ]
[ run dyn_bitset_unit_tests4.cpp ]
;

23
LICENSE Normal file
View File

@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

25
README.md Normal file
View File

@@ -0,0 +1,25 @@
DynamicBitset, part of the [Boost C++ Libraries](https://github.com/boostorg), is a bit vector similar to std::bitset but dynamically resizable.
### License
Distributed under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt).
### Properties
* C++11
* Header-only
### Build status
<!-- boost-ci/tools/makebadges.sh --project dynamic_bitset --appveyor n7bki5ka3v918r5r --codecov PVG5jth1ez --coverity 16167 -->
| Branch | GitHub Actions | AppVeyor | Coverity Scan | Codecov | Deps | Docs | Tests |
| :-------------: | -------------- | -------- | ------------- | ------- | ---- | ---- | ----- |
| [`master`](https://github.com/boostorg/dynamic_bitset/tree/master) | [![Build status](https://github.com/boostorg/dynamic_bitset/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/boostorg/dynamic_bitset/actions?query=branch:master) | [![Build status](https://ci.appveyor.com/api/projects/status/n7bki5ka3v918r5r/branch/master?svg=true)](https://ci.appveyor.com/project/cppalliance/dynamic-bitset/branch/master) | [![Coverity Scan build status](https://scan.coverity.com/projects/16167/badge.svg)](https://scan.coverity.com/projects/boostorg-dynamic_bitset) | [![Codecov](https://codecov.io/gh/boostorg/dynamic_bitset/branch/master/graph/badge.svg?token=PVG5jth1ez)](https://codecov.io/gh/boostorg/dynamic_bitset/tree/master) | [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/dynamic_bitset.html) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](https://www.boost.org/doc/libs/master/libs/dynamic_bitset) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](https://www.boost.org/development/tests/master/developer/dynamic_bitset.html)
| [`develop`](https://github.com/boostorg/dynamic_bitset/tree/develop) | [![Build status](https://github.com/boostorg/dynamic_bitset/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/boostorg/dynamic_bitset/actions?query=branch:develop) | [![Build status](https://ci.appveyor.com/api/projects/status/n7bki5ka3v918r5r/branch/develop?svg=true)](https://ci.appveyor.com/project/cppalliance/dynamic-bitset/branch/develop) | [![Coverity Scan build status](https://scan.coverity.com/projects/16167/badge.svg)](https://scan.coverity.com/projects/boostorg-dynamic_bitset) | [![Codecov](https://codecov.io/gh/boostorg/dynamic_bitset/branch/develop/graph/badge.svg?token=PVG5jth1ez)](https://codecov.io/gh/boostorg/dynamic_bitset/tree/develop) | [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/dynamic_bitset.html) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](https://www.boost.org/doc/libs/develop/libs/dynamic_bitset) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](https://www.boost.org/development/tests/develop/developer/dynamic_bitset.html)
### More information
* [Ask questions](https://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-dynamic_bitset).
* [Report bugs](https://github.com/boostorg/dynamic_bitset/issues): Be sure to mention the Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good, as well.
* Submit your patches as pull requests against the **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt).
* Discussions about the library are held on the [Boost developers mailing list](https://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](https://www.boost.org/community/policy.html) before posting, and add the `[dynamic_bitset]` tag at the beginning of the subject line.

File diff suppressed because it is too large Load Diff

27
build.jam Normal file
View File

@@ -0,0 +1,27 @@
# Copyright René Ferdinand Rivera Morell 2023-2024
# 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)
require-b2 5.2 ;
constant boost_dependencies :
/boost/assert//boost_assert
/boost/config//boost_config
/boost/container_hash//boost_container_hash
/boost/core//boost_core
/boost/throw_exception//boost_throw_exception ;
project /boost/dynamic_bitset
: common-requirements
<include>include
;
explicit
[ alias boost_dynamic_bitset : : : : <library>$(boost_dependencies) ]
[ alias all : boost_dynamic_bitset example test ]
;
call-if : boost-library dynamic_bitset
;

57
doc/Jamfile.v2 Normal file
View File

@@ -0,0 +1,57 @@
import generate ;
import path ;
import property-set ;
import virtual-target ;
path-constant HERE : . ;
make html/index.html : build_antora.sh : @run-script ;
generate files-to-install : html/index.html : <generating-rule>@delayed-glob ;
install install
: files-to-install
: <location>html
<install-source-root>html/dynamic_bitset
;
explicit html/index.html files-to-install ;
# this runs the antora script
actions run-script
{
bash $(>)
}
# this globs after its sources are created
rule delayed-glob ( project name : property-set : sources * )
{
for local src in $(sources)
{
# the next line causes the source to be generated immediately
# and not later (which it normally would)
UPDATE_NOW [ $(src).actualize ] ;
}
# we need to construct the path to the globbed directory;
# this path would be <current-project>/antora
local root = [ path.root html [ $(project).location ] ] ;
local files ;
# actual globbing happens here
for local file in [ path.glob-tree $(root) : * ]
{
# we have to skip directories, because our match expression accepts anything
if [ CHECK_IF_FILE $(file) ]
{
# we construct a list of targets to copy
files += [ virtual-target.from-file $(file:D=) : $(file:D) : $(project) ] ;
}
}
# we prepend empty usage requirements to the result
return [ property-set.empty ] $(files) ;
}
###############################################################################
alias boostdoc ;
explicit boostdoc ;
alias boostrelease : install ;
explicit boostrelease ;

21
doc/antora.yml Normal file
View File

@@ -0,0 +1,21 @@
# ============================================================================
# Copyright 2025 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)
# ============================================================================
name: dynamic_bitset
version: ~
title: Boost.DynamicBitset
start_page: index.adoc
asciidoc:
attributes:
source-language: asciidoc@
table-caption: false
nav:
- modules/ROOT/nav.adoc
ext:
cpp-reference:
config: doc/mrdocs.yml

31
doc/build_antora.sh Executable file
View File

@@ -0,0 +1,31 @@
#! /bin/sh --
# ============================================================================
# Copyright 2023 Alan de Freitas.
# Copyright 2025 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)
# ============================================================================
set -eu
if [ $# -eq 0 ]
then
echo "No playbook supplied, using default playbook."
PLAYBOOK="local-playbook.yml"
else
PLAYBOOK=$1
fi
SCRIPT_DIR=$( dirname -- "${BASH_SOURCE[0]}" )
cd "$SCRIPT_DIR"
echo "Installing npm dependencies..."
npm ci
echo "Building docs in custom dir..."
PATH="$(pwd)/node_modules/.bin:${PATH}"
export PATH
npx antora --clean --fetch "$PLAYBOOK" --stacktrace --log-level all
echo "Done"

57
doc/local-playbook.yml Normal file
View File

@@ -0,0 +1,57 @@
# ============================================================================
# Copyright 2023 Alan de Freitas.
# Copyright 2025 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)
# ============================================================================
#
# An antora playbook used for local development.
# The playbook includes Boost.DynamicBitset as its only component.
# ----------------------------------------------------------------------------
site:
title: Boost.DynamicBitset
start_page: dynamic_bitset::index.adoc
robots: allow
keys:
repo_url: 'https://github.com/boostorg/dynamic_bitset'
content:
sources:
- url: ..
start_path: doc
edit_url: 'https://github.com/boostorg/dynamic_bitset/edit/{refname}/{path}'
output:
dir: html
ui:
bundle:
url: https://github.com/boostorg/website-v2-docs/releases/download/ui-master/ui-bundle.zip
snapshot: true
antora:
extensions:
- require: '@antora/lunr-extension' # https://gitlab.com/antora/antora-lunr-extension
index_latest_only: true
- require: '@cppalliance/antora-cpp-tagfiles-extension'
cpp-tagfiles:
using-namespaces:
- 'boost::'
- require: '@cppalliance/antora-cpp-reference-extension'
dependencies:
- name: 'boost'
repo: 'https://github.com/boostorg/boost.git'
tag: 'develop'
variable: 'BOOST_SRC_DIR'
system-env: 'BOOST_SRC_DIR'
asciidoc:
attributes:
# Enable pagination
page-pagination: ''
extensions:
- '@cppalliance/asciidoctor-boost-links'
- '@asciidoctor/tabs'

10
doc/modules/ROOT/nav.adoc Normal file
View File

@@ -0,0 +1,10 @@
// ===========================================================================
// Copyright 2025 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)
// ===========================================================================
* xref:index.adoc[]
* xref:reference:boost/dynamic_bitset.adoc[Reference]

View File

@@ -0,0 +1,72 @@
// ===========================================================================
// Copyright 2001 Jeremy Siek
// Copyright 2003-2004, 2008, 2025 Gennaro Prota
// Copyright 2014 Ahmed Charles
// Copyright 2014 Riccardo Marcangelo
// Copyright 2018 Evgeny Shulgin
//
// 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)
// ===========================================================================
= Boost.DynamicBitset
Boost.DynamicBitset is a portable library that provides a set of bits.
The set
(xref:reference:boost/dynamic_bitset.adoc#boost-dynamic_bitset[dynamic_bitset])
provides access to the value of individual bits via
xref:reference:boost/dynamic_bitset/operator_subs-08.adoc[operator[\]] and
provides all of the bitwise operators that one can apply to builtin integers,
such as xref:reference:boost/operator_bitand.adoc[operator&] and
xref:reference:boost/dynamic_bitset/operator_lshift.adoc[operator<<]. The number
of bits can change at runtime.
`dynamic_bitset` is nearly identical to `std::bitset`. The difference is that
the size of a `dynamic_bitset` (the number of bits) can change at runtime,
whereas the size of a `std::bitset` is specified at compile-time through an
integer template parameter.
The main problem that `dynamic_bitset` is designed to solve is that of
representing a subset of a finite set. Each bit represents whether an element of
the finite set is in the subset or not. As such the bitwise operations of
`dynamic_bitset`, such as `operator&` and `operator|`, correspond to set
operations, such as intersection and union.
== Definitions
Each bit represents either the Boolean value `true` or `false` (1 or 0). To set
a bit is to assign it 1. To clear or reset a bit is to assign it 0. To flip a
bit is to change the value to 1 if it was 0 and to 0 if it was 1. Each bit has a
non-negative position. A bitset `x` contains `x.size()` bits, with each bit
assigned a unique position in the range `[0, x.size())`. The bit at position 0
is called the least significant bit and the bit at position `size() - 1` is the
most significant bit. When converting an instance of `dynamic_bitset` to or from
an unsigned long `n`, the bit at position `i` of the bitset has the same value
as `(n >> i) & 1`.
== Rationale
Because of the proxy reference type, `dynamic_bitset` is not a
https://en.cppreference.com/w/cpp/named_req/Container.html[Container] and its
iterators do not satisfy the requirements for a LegacyForwardIterator. This
means that its iterators are not usable with many standard algorithms. However,
`dynamic_bitset` provides C++20 iterators which can be used with ranges.
Some people prefer the name "toggle" to "flip". The name "flip" was chosen
because that is the name used in `std::bitset`. In fact, most of the function
names for `dynamic_bitset` were chosen for this reason.
`dynamic_bitset` does not throw exceptions when a precondition is violated (as
is done in `std::bitset`). Instead `BOOST_ASSERT()` is used. See the guidelines
for Error and Exception Handling for the explanation. Note that, consistently
with this, the documentation of the member functions doesn't use the term
"precondition" for conditions that cause an exception to be emitted (the C++
standard uses the term "requires" in such cases).
== Acknowledgments
We would like to thank the Boost community for putting in the time to review and
accept this library. This library is much better than it ever would have been
due to all the suggestions from Boost members. We especially thank Matt Marcus
for taking on the task of review manager. Also, a special thanks goes to James
Kanze for his invaluable help with the internationalization issues.

26
doc/mrdocs.yml Normal file
View File

@@ -0,0 +1,26 @@
# ============================================================================
# Copyright 2025 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)
# ============================================================================
verbose: true
source-root: ..
cmake: '-DDYNAMIC_BITSET_MRDOCS_BUILD=ON'
input:
- ../include
exclude-symbols:
- 'boost::bit_iterator_base'
- 'boost::bit_iterator'
- 'boost::const_bit_iterator'
- 'boost::detail'
- 'boost::detail::**'
- 'boost::to_string_helper'
- 'boost::dynamic_bitset::bit_appender'
- 'boost::dynamic_bitset::buffer_type'
file-patterns:
- '*.hpp'
multipage: true
generator: adoc

2460
doc/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

15
doc/package.json Normal file
View File

@@ -0,0 +1,15 @@
{
"devDependencies": {
"@antora/cli": "3.1.10",
"@antora/site-generator": "3.1.10",
"antora": "3.1.10"
},
"dependencies": {
"@antora/expand-path-helper": "^2.0.0",
"@antora/lunr-extension": "^1.0.0-alpha.8",
"@asciidoctor/tabs": "^1.0.0-beta.3",
"@cppalliance/antora-cpp-reference-extension": "^0.0.8",
"@cppalliance/antora-cpp-tagfiles-extension": "^0.0.5",
"@cppalliance/asciidoctor-boost-links": "^0.0.2"
}
}

1
doc/readme Normal file
View File

@@ -0,0 +1 @@
To build the documentation, run build_docs.sh.

View File

@@ -1,370 +0,0 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/dynamic_bitset.hpp"
#include "boost/limits.hpp"
#include "boost/config.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
#endif
template <typename Tests, typename String>
void run_string_tests(const String& s
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tests)
)
{
const std::size_t len = s.length();
const std::size_t step = len/4 ? len/4 : 1;
// bitset length determined by the string-related arguments
std::size_t i;
for (i = 0; i <= len/2 ; i += step) {
Tests::from_string(s, i, len/2); // len/2 - i bits
Tests::from_string(s, i, len); // len - i bits
Tests::from_string(s, i, 1 + len*2); // len - i bits
}
// bitset length explicitly specified
for (i = 0; i <= len/2; i += step) {
for (std::size_t sz = 0; sz <= len*4; sz+= step*2) {
Tests::from_string(s, i, len/2, sz);
Tests::from_string(s, i, len, sz);
Tests::from_string(s, i, 1 + len*2, sz);
}
}
}
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;
const int bits_per_block = bitset_type::bits_per_block;
const std::string long_string = get_long_string();
//=====================================================================
// 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)();
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);
}
}
//=====================================================================
// Test construction from a string
{
run_string_tests<Tests>(std::string("")); // empty string
run_string_tests<Tests>(std::string("1"));
run_string_tests<Tests>(long_string);
# if !defined BOOST_NO_STD_WSTRING
// I need to decide what to do for non "C" locales here. On
// 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
//
run_string_tests<Tests>(
std::wstring(L"11111000000111111111010101010101010101010111111"));
# endif
// Note that these are _valid_ arguments
Tests::from_string(std::string("x11y"), 1, 2);
Tests::from_string(std::string("x11"), 1, 10);
Tests::from_string(std::string("x11"), 1, 10, 10);
}
//=====================================================================
// Test construction from a block range
// [gps - this comment is erroneous]
{
std::vector<Block> blocks;
Tests::from_block_range(blocks);
}
{
std::vector<Block> blocks(3);
blocks[0] = static_cast<Block>(0);
blocks[1] = static_cast<Block>(1);
blocks[2] = ~Block(0);
Tests::from_block_range(blocks);
}
{
const unsigned int n = (std::numeric_limits<unsigned char>::max)();
std::vector<Block> blocks(n);
for (typename std::vector<Block>::size_type i = 0; i < n; ++i)
blocks[i] = static_cast<Block>(i);
Tests::from_block_range(blocks);
}
//=====================================================================
// test to_block_range
{
bitset_type b;
Tests::to_block_range(b);
}
{
bitset_type b(1, 1ul);
Tests::to_block_range(b);
}
{
bitset_type b(long_string);
Tests::to_block_range(b);
}
//=====================================================================
// Test copy constructor
{
boost::dynamic_bitset<Block> b;
Tests::copy_constructor(b);
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::copy_constructor(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::copy_constructor(b);
}
//=====================================================================
// Test assignment operator
{
bitset_type a, b;
Tests::assignment_operator(a, b);
}
{
bitset_type a(std::string("1")), b(std::string("0"));
Tests::assignment_operator(a, b);
}
{
bitset_type a(long_string), b(long_string);
Tests::assignment_operator(a, b);
}
{
bitset_type a;
bitset_type b(long_string); // b greater than a, a empty
Tests::assignment_operator(a, b);
}
{
bitset_type a(std::string("0"));
bitset_type b(long_string); // b greater than a
Tests::assignment_operator(a, b);
}
//=====================================================================
// Test swap
{
bitset_type a;
bitset_type b(std::string("1"));
Tests::swap(a, b);
Tests::swap(b, a);
Tests::swap(a, a);
}
{
bitset_type a;
bitset_type b(long_string);
Tests::swap(a, b);
Tests::swap(b, a);
}
{
bitset_type a(std::string("0"));
bitset_type b(long_string);
Tests::swap(a, b);
Tests::swap(b, a);
Tests::swap(a, a);
Tests::swap(b, b);
}
//=====================================================================
// Test resize
{
boost::dynamic_bitset<Block> a;
Tests::resize(a);
}
{
boost::dynamic_bitset<Block> a(std::string("0"));
Tests::resize(a);
}
{
boost::dynamic_bitset<Block> a(std::string("1"));
Tests::resize(a);
}
{
boost::dynamic_bitset<Block> a(long_string);
Tests::resize(a);
}
//=====================================================================
// Test clear
{
boost::dynamic_bitset<Block> a;
Tests::clear(a);
}
{
boost::dynamic_bitset<Block> a(long_string);
Tests::clear(a);
}
//=====================================================================
// Test append bit
{
boost::dynamic_bitset<Block> a;
Tests::append_bit(a);
}
{
boost::dynamic_bitset<Block> a(std::string("0"));
Tests::append_bit(a);
}
{
boost::dynamic_bitset<Block> a(std::string("1"));
Tests::append_bit(a);
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
boost::dynamic_bitset<Block> a(size_to_fill_all_blocks, 255ul);
Tests::append_bit(a);
}
{
boost::dynamic_bitset<Block> a(long_string);
Tests::append_bit(a);
}
//=====================================================================
// Test append block
{
boost::dynamic_bitset<Block> a;
Tests::append_block(a);
}
{
boost::dynamic_bitset<Block> a(std::string("0"));
Tests::append_block(a);
}
{
boost::dynamic_bitset<Block> a(std::string("1"));
Tests::append_block(a);
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
boost::dynamic_bitset<Block> a(size_to_fill_all_blocks, 15ul);
Tests::append_block(a);
}
{
boost::dynamic_bitset<Block> a(long_string);
Tests::append_block(a);
}
//=====================================================================
// Test append block range
{
boost::dynamic_bitset<Block> a;
std::vector<Block> blocks;
Tests::append_block_range(a, blocks);
}
{
boost::dynamic_bitset<Block> a(std::string("0"));
std::vector<Block> blocks(3);
blocks[0] = static_cast<Block>(0);
blocks[1] = static_cast<Block>(1);
blocks[2] = ~Block(0);
Tests::append_block_range(a, blocks);
}
{
boost::dynamic_bitset<Block> a(std::string("1"));
const unsigned int n = (std::numeric_limits<unsigned char>::max)();
std::vector<Block> blocks(n);
for (typename std::vector<Block>::size_type i = 0; i < n; ++i)
blocks[i] = static_cast<Block>(i);
Tests::append_block_range(a, blocks);
}
{
boost::dynamic_bitset<Block> a;
a.append(Block(1));
a.append(Block(2));
Block x[] = {3, 4, 5};
std::size_t sz = sizeof(x) / sizeof(x[0]);
std::vector<Block> blocks(x, x + sz);
Tests::append_block_range(a, blocks);
}
{
boost::dynamic_bitset<Block> a(long_string);
std::vector<Block> blocks(3);
blocks[0] = static_cast<Block>(0);
blocks[1] = static_cast<Block>(1);
blocks[2] = ~Block(0);
Tests::append_block_range(a, blocks);
}
//=====================================================================
// Test bracket operator
{
boost::dynamic_bitset<Block> b1;
std::vector<bool> bitvec1;
Tests::operator_bracket(b1, bitvec1);
}
{
boost::dynamic_bitset<Block> b(std::string("1"));
std::vector<bool> bit_vec(1, true);
Tests::operator_bracket(b, bit_vec);
}
{
boost::dynamic_bitset<Block> b(long_string);
std::size_t n = long_string.size();
std::vector<bool> bit_vec(n);
for (std::size_t i = 0; i < n; ++i)
bit_vec[i] = long_string[n - 1 - i] == '0' ? 0 : 1;
Tests::operator_bracket(b, bit_vec);
}
}
int
test_main(int, char*[])
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
run_test_cases<unsigned int>();
run_test_cases<unsigned long>();
# ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type>();
# endif
return 0;
}

View File

@@ -1,291 +0,0 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/dynamic_bitset.hpp"
#include "boost/config.hpp"
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;
const int bits_per_block = bitset_type::bits_per_block;
std::string long_string = get_long_string();
//=====================================================================
// Test operator&=
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::and_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::and_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
Tests::and_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
Tests::and_assignment(lhs, rhs);
}
//=====================================================================
// Test operator |=
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::or_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::or_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
Tests::or_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
Tests::or_assignment(lhs, rhs);
}
//=====================================================================
// Test operator^=
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::xor_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::xor_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(std::string("0")), rhs(std::string("1"));
Tests::xor_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string), rhs(long_string);
Tests::xor_assignment(lhs, rhs);
}
//=====================================================================
// Test operator-=
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::sub_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::sub_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(std::string("0")), rhs(std::string("1"));
Tests::sub_assignment(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string), rhs(long_string);
Tests::sub_assignment(lhs, rhs);
}
//=====================================================================
// Test operator<<=
{ // case pos == 0
std::size_t pos = 0;
{
boost::dynamic_bitset<Block> b;
Tests::shift_left_assignment(b, pos);
}
{
boost::dynamic_bitset<Block> b(std::string("1010"));
Tests::shift_left_assignment(b, pos);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_left_assignment(b, pos);
}
}
{
// test with both multiple and
// non multiple of bits_per_block
const int how_many = 10;
for (int i = 1; i <= how_many; ++i) {
std::size_t multiple = i * bits_per_block;
std::size_t non_multiple = multiple - 1;
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_left_assignment(b, multiple);
Tests::shift_left_assignment(b, non_multiple);
}
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_left_assignment(b, pos);
}
{ // case pos >= n
std::size_t pos = long_string.size();
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_left_assignment(b, pos);
}
//=====================================================================
// Test operator>>=
{ // case pos == 0
std::size_t pos = 0;
{
boost::dynamic_bitset<Block> b;
Tests::shift_right_assignment(b, pos);
}
{
boost::dynamic_bitset<Block> b(std::string("1010"));
Tests::shift_right_assignment(b, pos);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_right_assignment(b, pos);
}
}
{
// test with both multiple and
// non multiple of bits_per_block
const int how_many = 10;
for (int i = 1; i <= how_many; ++i) {
std::size_t multiple = i * bits_per_block;
std::size_t non_multiple = multiple - 1;
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_right_assignment(b, multiple);
Tests::shift_right_assignment(b, non_multiple);
}
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_right_assignment(b, pos);
}
{ // case pos >= n
std::size_t pos = long_string.size();
boost::dynamic_bitset<Block> b(long_string);
Tests::shift_right_assignment(b, pos);
}
//=====================================================================
// test b.set()
{
boost::dynamic_bitset<Block> b;
Tests::set_all(b);
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::set_all(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::set_all(b);
}
//=====================================================================
// Test b.set(pos)
{ // case pos >= b.size()
boost::dynamic_bitset<Block> b;
Tests::set_one(b, 0, true);
}
{ // case pos < b.size()
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::set_one(b, 0, true);
}
{ // case pos == b.size() / 2
boost::dynamic_bitset<Block> b(long_string);
Tests::set_one(b, long_string.size()/2, true);
}
//=====================================================================
// Test b.reset()
{
boost::dynamic_bitset<Block> b;
Tests::reset_all(b);
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::reset_all(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::reset_all(b);
}
//=====================================================================
// Test b.reset(pos)
{ // case pos >= b.size()
boost::dynamic_bitset<Block> b;
Tests::reset_one(b, 0);
}
{ // case pos < b.size()
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::reset_one(b, 0);
}
{ // case pos == b.size() / 2
boost::dynamic_bitset<Block> b(long_string);
Tests::reset_one(b, long_string.size()/2);
}
//=====================================================================
// Test ~b
{
boost::dynamic_bitset<Block> b;
Tests::operator_flip(b);
}
{
boost::dynamic_bitset<Block> b(std::string("1"));
Tests::operator_flip(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::operator_flip(b);
}
//=====================================================================
// Test b.flip()
{
boost::dynamic_bitset<Block> b;
Tests::flip_all(b);
}
{
boost::dynamic_bitset<Block> b(std::string("1"));
Tests::flip_all(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::flip_all(b);
}
//=====================================================================
// Test b.flip(pos)
{ // case pos >= b.size()
boost::dynamic_bitset<Block> b;
Tests::flip_one(b, 0);
}
{ // case pos < b.size()
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::flip_one(b, 0);
}
{ // case pos == b.size() / 2
boost::dynamic_bitset<Block> b(long_string);
Tests::flip_one(b, long_string.size()/2);
}
}
int
test_main(int, char*[])
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
run_test_cases<unsigned int>();
run_test_cases<unsigned long>();
# ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type>();
# endif
return 0;
}

View File

@@ -1,675 +0,0 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/dynamic_bitset.hpp"
#include "boost/limits.hpp"
#include "boost/config.hpp"
template <typename Block>
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
{
// a bunch of typedefs to have 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
std::string long_string = get_long_string();
std::size_t ul_width = std::numeric_limits<unsigned long>::digits;
//=====================================================================
// Test b.empty()
{
bitset_type b;
Tests::empty(b); // gps
}
{
bitset_type b(1, 1ul);
Tests::empty(b);
}
{
bitset_type b(bitset_type::bits_per_block
+ bitset_type::bits_per_block/2, 15ul);
Tests::empty(b);
}
//=====================================================================
// Test b.to_long()
{
boost::dynamic_bitset<Block> b;
Tests::to_ulong(b);
}
{
boost::dynamic_bitset<Block> b(std::string("1"));
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));
Tests::to_ulong(b);
}
{
std::string ul_str(ul_width, '1');
boost::dynamic_bitset<Block> b(ul_str);
Tests::to_ulong(b);
}
{ // case overflow
boost::dynamic_bitset<Block> b(long_string);
Tests::to_ulong(b);
}
//=====================================================================
// Test to_string(b, str)
{
boost::dynamic_bitset<Block> b;
Tests::to_string(b);
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::to_string(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::to_string(b);
}
//=====================================================================
// Test b.count()
{
boost::dynamic_bitset<Block> b;
Tests::count(b);
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::count(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::count(b);
}
//=====================================================================
// Test b.size()
{
boost::dynamic_bitset<Block> b;
Tests::size(b);
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::size(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::size(b);
}
//=====================================================================
// Test b.any()
{
boost::dynamic_bitset<Block> b;
Tests::any(b);
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::any(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::any(b);
}
//=====================================================================
// Test b.none()
{
boost::dynamic_bitset<Block> b;
Tests::none(b);
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::none(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::none(b);
}
//=====================================================================
// Test a.is_subset_of(b)
{
boost::dynamic_bitset<Block> a, b;
Tests::subset(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
Tests::subset(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
Tests::subset(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
Tests::subset(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
a[long_string.size()/2].flip();
Tests::subset(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
b[long_string.size()/2].flip();
Tests::subset(a, b);
}
//=====================================================================
// Test a.is_proper_subset_of(b)
{
boost::dynamic_bitset<Block> a, b;
Tests::proper_subset(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
Tests::proper_subset(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
Tests::proper_subset(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
Tests::proper_subset(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
a[long_string.size()/2].flip();
Tests::proper_subset(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
b[long_string.size()/2].flip();
Tests::proper_subset(a, b);
}
//=====================================================================
// Test intersects
{
bitset_type a; // empty
bitset_type b;
Tests::intersects(a, b);
}
{
bitset_type a;
bitset_type b(5, 8ul);
Tests::intersects(a, b);
}
{
bitset_type a(8, 0ul);
bitset_type b(15, 0ul);
b[9] = 1;
Tests::intersects(a, b);
}
{
bitset_type a(15, 0ul);
bitset_type b(22, 0ul);
a[14] = b[14] = 1;
Tests::intersects(a, b);
}
//=====================================================================
// Test find_first
{
// empty bitset
bitset_type b;
Tests::find_first(b);
}
{
// bitset of size 1
bitset_type b(1, 1ul);
Tests::find_first(b);
}
{
// all-0s bitset
bitset_type b(4 * bitset_type::bits_per_block, 0ul);
Tests::find_first(b);
}
{
// first bit on
bitset_type b(1, 1ul);
Tests::find_first(b);
}
{
// last bit on
bitset_type b(4 * bitset_type::bits_per_block - 1, 0ul);
b.set(b.size() - 1);
Tests::find_first(b);
}
//=====================================================================
// Test find_next
{
// empty bitset
bitset_type b;
// check
Tests::find_next(b, 0);
Tests::find_next(b, 1);
Tests::find_next(b, 200);
Tests::find_next(b, b.npos);
}
{
// bitset of size 1 (find_next can never find)
bitset_type b(1, 1ul);
// check
Tests::find_next(b, 0);
Tests::find_next(b, 1);
Tests::find_next(b, 200);
Tests::find_next(b, b.npos);
}
{
// all-1s bitset
bitset_type b(16 * bitset_type::bits_per_block);
b.set();
// check
const typename bitset_type::size_type larger_than_size = 5 + b.size();
for(typename bitset_type::size_type i = 0; i <= larger_than_size; ++i) {
Tests::find_next(b, i);
}
Tests::find_next(b, b.npos);
}
{
// a bitset with 1s at block boundary only
const int num_blocks = 32;
const int block_width = bitset_type::bits_per_block;
bitset_type b(num_blocks * block_width);
typename bitset_type::size_type i = block_width - 1;
for ( ; i < b.size(); i += block_width) {
b.set(i);
typename bitset_type::size_type first_in_block = i - (block_width - 1);
b.set(first_in_block);
}
// check
const typename bitset_type::size_type larger_than_size = 5 + b.size();
for (i = 0; i <= larger_than_size; ++i) {
Tests::find_next(b, i);
}
Tests::find_next(b, b.npos);
}
{
// bitset with alternate 1s and 0s
const typename bitset_type::size_type sz = 1000;
bitset_type b(sz);
typename bitset_type::size_type i = 0;
for ( ; i < sz; ++i) {
b[i] = (i%2 == 0);
}
// check
const typename bitset_type::size_type larger_than_size = 5 + b.size();
for (i = 0; i <= larger_than_size; ++i) {
Tests::find_next(b, i);
}
Tests::find_next(b, b.npos);
}
//=====================================================================
// Test operator==
{
boost::dynamic_bitset<Block> a, b;
Tests::operator_equal(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
Tests::operator_equal(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
Tests::operator_equal(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
Tests::operator_equal(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
a[long_string.size()/2].flip();
Tests::operator_equal(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
b[long_string.size()/2].flip();
Tests::operator_equal(a, b);
}
//=====================================================================
// Test operator!=
{
boost::dynamic_bitset<Block> a, b;
Tests::operator_not_equal(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
Tests::operator_not_equal(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
Tests::operator_not_equal(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
Tests::operator_not_equal(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
a[long_string.size()/2].flip();
Tests::operator_not_equal(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
b[long_string.size()/2].flip();
Tests::operator_not_equal(a, b);
}
//=====================================================================
// Test operator<
{
boost::dynamic_bitset<Block> a, b;
Tests::operator_less_than(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
Tests::operator_less_than(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
Tests::operator_less_than(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
Tests::operator_less_than(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
a[long_string.size()/2].flip();
Tests::operator_less_than(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
b[long_string.size()/2].flip();
Tests::operator_less_than(a, b);
}
// check for consistency with ulong behaviour
{
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
assert(a < b);
}
{
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
assert(!(a < b));
}
{
boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
assert(!(a < b));
}
//=====================================================================
// Test operator<=
{
boost::dynamic_bitset<Block> a, b;
Tests::operator_less_than_eq(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
Tests::operator_less_than_eq(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
Tests::operator_less_than_eq(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
Tests::operator_less_than_eq(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
a[long_string.size()/2].flip();
Tests::operator_less_than_eq(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
b[long_string.size()/2].flip();
Tests::operator_less_than_eq(a, b);
}
// check for consistency with ulong behaviour
{
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
assert(a <= b);
}
{
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
assert(a <= b);
}
{
boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
assert(!(a <= b));
}
//=====================================================================
// Test operator>
{
boost::dynamic_bitset<Block> a, b;
Tests::operator_greater_than(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
Tests::operator_greater_than(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
Tests::operator_greater_than(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
Tests::operator_greater_than(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
a[long_string.size()/2].flip();
Tests::operator_greater_than(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
b[long_string.size()/2].flip();
Tests::operator_greater_than(a, b);
}
// check for consistency with ulong behaviour
{
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
assert(!(a > b));
}
{
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
assert(!(a > b));
}
{
boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
assert(a > b);
}
//=====================================================================
// Test operator<=
{
boost::dynamic_bitset<Block> a, b;
Tests::operator_greater_than_eq(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
Tests::operator_greater_than_eq(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
Tests::operator_greater_than_eq(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
Tests::operator_greater_than_eq(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
a[long_string.size()/2].flip();
Tests::operator_greater_than_eq(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
b[long_string.size()/2].flip();
Tests::operator_greater_than_eq(a, b);
}
// check for consistency with ulong behaviour
{
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
assert(!(a >= b));
}
{
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
assert(a >= b);
}
{
boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
assert(a >= b);
}
//=====================================================================
// Test b.test(pos)
{ // case pos >= b.size()
boost::dynamic_bitset<Block> b;
Tests::test_bit(b, 0);
}
{ // case pos < b.size()
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::test_bit(b, 0);
}
{ // case pos == b.size() / 2
boost::dynamic_bitset<Block> b(long_string);
Tests::test_bit(b, long_string.size()/2);
}
//=====================================================================
// Test b << pos
{ // case pos == 0
std::size_t pos = 0;
boost::dynamic_bitset<Block> b(std::string("1010"));
Tests::operator_shift_left(b, pos);
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset<Block> b(long_string);
Tests::operator_shift_left(b, pos);
}
{ // case pos >= n
std::size_t pos = long_string.size();
boost::dynamic_bitset<Block> b(long_string);
Tests::operator_shift_left(b, pos);
}
//=====================================================================
// Test b >> pos
{ // case pos == 0
std::size_t pos = 0;
boost::dynamic_bitset<Block> b(std::string("1010"));
Tests::operator_shift_right(b, pos);
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset<Block> b(long_string);
Tests::operator_shift_right(b, pos);
}
{ // case pos >= n
std::size_t pos = long_string.size();
boost::dynamic_bitset<Block> b(long_string);
Tests::operator_shift_right(b, pos);
}
//=====================================================================
// Test a & b
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::operator_and(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::operator_and(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
Tests::operator_and(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
Tests::operator_and(lhs, rhs);
}
//=====================================================================
// Test a | b
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::operator_or(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::operator_or(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
Tests::operator_or(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
Tests::operator_or(lhs, rhs);
}
//=====================================================================
// Test a^b
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::operator_xor(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::operator_xor(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
Tests::operator_xor(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
Tests::operator_xor(lhs, rhs);
}
//=====================================================================
// Test a-b
{
boost::dynamic_bitset<Block> lhs, rhs;
Tests::operator_sub(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
Tests::operator_sub(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
Tests::operator_sub(lhs, rhs);
}
{
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
Tests::operator_sub(lhs, rhs);
}
}
int
test_main(int, char*[])
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
run_test_cases<unsigned int>();
run_test_cases<unsigned long>();
# ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type>();
# endif
return 0;
}

View File

@@ -1,329 +0,0 @@
// --------------------------------------------------------
// (C) Copyright Jeremy Siek 2001.
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
#include <fstream>
#include <string>
#include <cstddef> // for std::size_t
#include <stdexcept> // for std::logic_error
#include <cassert>
#include "boost/config.hpp"
#if !defined (BOOST_NO_STRINGSTREAM)
# include <sstream>
#endif
#include "bitset_test.hpp"
#include "boost/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
#endif
#if defined BOOST_NO_STD_WSTRING || defined BOOST_NO_STD_LOCALE
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
#endif
#if !defined BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
std::wstring widen_string( const std::string & str,
const std::locale & loc = std::locale() )
{
std::wstring result;
const std::string::size_type len = str.length();
if(len != 0) {
result.resize(len);
BOOST_USE_FACET(std::ctype<wchar_t>, loc)
.widen(&str[0], 1 + &str[len-1], &result[0]);
}
return result;
}
#endif
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;
//=====================================================================
// Test stream operator<<
{
// The test "variables" are: the stream type and its state, the
// exception mask, the width, the fill char and the padding side (left/right)
std::ios::iostate masks[] = {
std::ios::goodbit,
std::ios::eofbit,
std::ios::failbit,
std::ios::eofbit | std::ios::failbit
};
static std::string strings[] = {
std::string(""),
std::string("0"),
std::string("1"),
std::string("11100"),
get_long_string()
};
char fill_chars[] = { '*', 'x', ' ' };
std::size_t num_masks = sizeof(masks) / sizeof(masks[0]);
std::size_t num_strings = sizeof(strings) / sizeof(strings[0]);
std::size_t num_chars = sizeof(fill_chars) / sizeof(fill_chars[0]);
std::fstream not_good_stream("dynamic_bitset_tests - this file shouldn't exist",
std::ios::in);
for (std::size_t mi = 0; mi < num_masks; ++mi) {
for (std::size_t si = 0; si < num_strings; ++si) {
std::streamsize slen = (std::streamsize)(strings[si].length());
assert( (std::numeric_limits<std::streamsize>::max)()
>=(std::streamsize)(1+slen*2) );
for (std::size_t ci = 0; ci < num_chars; ++ci) {
// note how "negative widths" are tested too
const std::streamsize widths[] = { -1 - slen/2, 0, slen/2, 1 + slen*2 };
std::size_t num_widths = sizeof(widths) / sizeof(widths[0]);
for (std::size_t wi = 0; wi < num_widths; ++wi) {
std::streamsize w = widths[wi];
{
// test 0 - stream !good()
if(not_good_stream.good())
throw std::logic_error("Error in operator << tests"
" - please, double check");
bitset_type b(strings[si]);
not_good_stream.width(w);
not_good_stream.fill(fill_chars[ci]);
try { not_good_stream.exceptions(masks[mi]); } catch(...) {}
Tests::stream_inserter(b, not_good_stream, "<unused_string>");
}
{
// test 1a - file stream
bitset_type b(strings[si]);
std::ofstream file(test_file_name(), std::ios::trunc);
file.width(w);
file.fill(fill_chars[ci]);
file.exceptions(masks[mi]);
Tests::stream_inserter(b, file, test_file_name());
}
{
//NOTE: there are NO string stream tests - gps
}
#if !defined (BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS)
{
// test 1b - wide file stream
bitset_type b(strings[si]);
std::wofstream file(test_file_name());
file.width(w);
file.fill(fill_chars[ci]);
file.exceptions(masks[mi]);
Tests::stream_inserter(b, file, test_file_name());
}
#endif
}
}
}
} // for (; mi..)
}
//=====================================================================
// Test stream operator>>
{
// The test "variables" are: the stream type, the exception mask,
// the actual contents (and/or state) of the stream, and width.
//
// With few exceptions, each test case consists of writing a different
// assortment of digits and "whitespaces" to a text stream and then checking
// that what was written gets read back unchanged. That's NOT guaranteed by
// the standard, unless the assortment always ends with a '\n' and satisfies
// other conditions (see C99, 7.19.2/2), however it works in practice and is
// 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]
//
// Note how the bitset object is not initially empty. That helps checking
// that it isn't erroneously clear()ed by operator>>.
std::ios::iostate masks[] = {
std::ios::goodbit,
std::ios::eofbit,
std::ios::failbit,
std::ios::eofbit | std::ios::failbit
};
const std::string spaces = "\t\n "; //"\t\n\v\f ";
const std::string long_string = get_long_string();
/*const*/ static std::string strings[] = {
// NOTE: "const" gives the usual problems with Borland
// (in Tests::stream_extractor instantiation)
#if !(defined __BORLANDC__ \
&& BOOST_WORKAROUND(BOOST_RWSTD_VER, BOOST_TESTED_AT(0x20101)))
// Borland 5.5.1 with RW library crashes
// empty string
std::string(""),
// no bitset
spaces,
#endif
// no bitset
std::string("x"),
std::string("\t xyz"),
// bitset of size 1
std::string("0"),
std::string("1"),
std::string(" 0 "),
std::string(" 1 "),
spaces + "1",
"1" + spaces,
spaces + "1" + spaces,
std::string(" x1x "),
std::string(" 1x "),
// long bitset
long_string,
" " + long_string + " xyz",
spaces + long_string,
spaces + long_string + spaces
};
//-----------------------------------------------------
std::stringstream not_good_stream;
not_good_stream << "test";
std::string sink;
not_good_stream >> sink; // now the stream should be in eof state
const std::size_t num_masks = sizeof(masks) / sizeof(masks[0]);
const std::size_t num_strings = sizeof(strings) / sizeof(strings[0]);
for (std::size_t mi = 0; mi < num_masks; ++mi) {
for (std::size_t si = 0; si < num_strings; ++si) {
const std::streamsize slen = (std::streamsize)(strings[si].length());
assert((std::numeric_limits<std::streamsize>::max)() >= (std::streamsize)(1+slen*2));
std::streamsize widths[] = { -1, 0, slen/2, slen, 1 + slen*2 };
std::size_t num_widths = sizeof(widths) / sizeof(widths[0]);
for(std::size_t wi = 0; wi < num_widths; ++wi) {
const std::streamsize w = widths[wi];
// test 0 - !good() stream
{
if(not_good_stream.good())
throw std::logic_error("Error in operator >> tests"
" - please, double check");
bitset_type b(1, 15ul); // note: b is not empty
not_good_stream.width(w);
try { not_good_stream.exceptions(masks[mi]); } catch(...) {}
std::string irrelevant;
Tests::stream_extractor(b, not_good_stream, irrelevant);
}
// test 1a - (narrow) file stream
{
bitset_type b(1, 255ul);
{
std::ofstream f(test_file_name());
f << strings[si];
}
std::ifstream f(test_file_name());
f.width(w);
f.exceptions(masks[mi]);
Tests::stream_extractor(b, f, strings[si]);
}
#if !defined(BOOST_NO_STRINGSTREAM)
// test 2a - stringstream
{
bitset_type b(1, 255ul);
std::istringstream stream(strings[si]);
stream.width(w);
stream.exceptions(masks[mi]);
Tests::stream_extractor(b, stream, strings[si]);
}
#endif
#if !defined(BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS)
// test 1b - wchar_t file stream
{
std::wstring wstr = widen_string(strings[si]);
bitset_type b(1, 255ul);
{
std::basic_ofstream<wchar_t> of(test_file_name());
of << wstr;
}
std::basic_ifstream<wchar_t> f(test_file_name());
f.width(w);
f.exceptions(masks[mi]);
Tests::stream_extractor(b, f, wstr);
}
// test 2b - wstringstream
{
bitset_type b(1, 255ul);
std::wstring wstr = widen_string(strings[si]);
std::wistringstream wstream(wstr);
wstream.width(w);
wstream.exceptions(masks[mi]);
Tests::stream_extractor(b, wstream, wstr);
}
#endif // BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
}
}
} // for ( mi = 0; ...)
}
//=====================================================================
// << Any other tests go here >>
// .....
}
int
test_main(int, char*[])
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
run_test_cases<unsigned int>();
run_test_cases<unsigned long>();
# ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type>();
# endif
return 0;
}

File diff suppressed because it is too large Load Diff

23
example/Jamfile Normal file
View File

@@ -0,0 +1,23 @@
# -----------------------------------------------------------
# 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)
#
# -----------------------------------------------------------
project : requirements <library>/boost/dynamic_bitset//boost_dynamic_bitset ;
exe example1
: example1.cpp
;
exe example2
: example2.cpp
;
exe example3
: example3.cpp
;

View File

@@ -3,23 +3,32 @@
// 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 "boost/dynamic_bitset.hpp"
#include <iostream>
#include <boost/dynamic_bitset.hpp>
int main() {
boost::dynamic_bitset<> x(5); // all 0's by default
x[0] = 1;
x[1] = 1;
x[4] = 1;
for (boost::dynamic_bitset<>::size_type i = 0; i < x.size(); ++i)
std::cout << x[i];
std::cout << "\n";
std::cout << x << "\n";
return EXIT_SUCCESS;
int
main()
{
boost::dynamic_bitset<> x( 5 ); // all 0's by default
x[ 0 ] = 1;
x[ 1 ] = 1;
x[ 4 ] = 1;
for ( boost::dynamic_bitset<>::size_type i = 0; i < x.size(); ++i )
std::cout << x[ i ];
std::cout << "\n";
std::cout << x << "\n";
return 0;
}

View File

@@ -3,27 +3,30 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Sample output:
// Sample output:
//
// bits(0) = 00
// bits(1) = 01
// bits(2) = 10
// bits(3) = 11
#include "boost/dynamic_bitset.hpp"
#include <iostream>
#include <boost/dynamic_bitset.hpp>
int main()
int
main()
{
const boost::dynamic_bitset<> b0(2, 0ul);
std::cout << "bits(0) = " << b0 << std::endl;
const boost::dynamic_bitset<> b0( 2, 0ul );
std::cout << "bits(0) = " << b0 << std::endl;
const boost::dynamic_bitset<> b1(2, 1ul);
std::cout << "bits(1) = " << b1 << std::endl;
const boost::dynamic_bitset<> b1( 2, 1ul );
std::cout << "bits(1) = " << b1 << std::endl;
const boost::dynamic_bitset<> b2(2, 2ul);
std::cout << "bits(2) = " << b2 << std::endl;
const boost::dynamic_bitset<> b2( 2, 2ul );
std::cout << "bits(2) = " << b2 << std::endl;
const boost::dynamic_bitset<> b3(2, 3ul);
std::cout << "bits(3) = " << b3 << std::endl;
const boost::dynamic_bitset<> b3( 2, 3ul );
std::cout << "bits(3) = " << b3 << std::endl;
return EXIT_SUCCESS;
return 0;
}

View File

@@ -1,35 +1,69 @@
// (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 <iostream>
#include <boost/dynamic_bitset.hpp>
#include <ostream>
int main(int, char*[]) {
const boost::dynamic_bitset<> mask(12, 2730ul);
std::cout << "mask = " << mask << std::endl;
int
main()
{
boost::dynamic_bitset<> mask( 12, 2730ul );
std::cout << "mask = " << mask << std::endl;
boost::dynamic_bitset<> x(12);
std::cout << "x.size()=" << x.size() << std::endl;
boost::dynamic_bitset<> x;
std::cout << "x.size() = " << x.size() << std::endl;
std::cout << "Enter a 12-bit bitset in binary: " << std::flush;
if (std::cin >> x) {
std::cout << "input number: " << x << std::endl;
std::cout << "As unsigned long: " << x.to_ulong() << std::endl;
std::cout << "And with mask: " << (x & mask) << std::endl;
std::cout << "Or with mask: " << (x | mask) << std::endl;
std::cout << "Shifted left: " << (x << 1) << std::endl;
std::cout << "Shifted right: " << (x >> 1) << std::endl;
}
return EXIT_SUCCESS;
std::cout << "Enter a bitset in binary: x = " << std::flush;
if ( std::cin >> x ) {
const std::size_t sz = x.size();
std::cout << std::endl;
std::cout << "Input number: " << x << std::endl;
std::cout << "x.size() is now: " << sz << std::endl;
bool fits_in_ulong = true;
unsigned long ul = 0;
try {
ul = x.to_ulong();
} catch ( std::overflow_error & ) {
fits_in_ulong = false;
}
std::cout << "As unsigned long: ";
if ( fits_in_ulong ) {
std::cout << ul;
} else {
std::cout << "(overflow exception)";
}
std::cout << std::endl;
mask.resize( sz );
std::cout << "Mask (possibly resized): " << mask << std::endl;
std::cout << "And with mask: " << ( x & mask ) << std::endl;
std::cout << "Or with mask: " << ( x | mask ) << std::endl;
std::cout << "Shifted left by 1: " << ( x << 1 ) << std::endl;
std::cout << "Shifted right by 1: " << ( x >> 1 ) << std::endl;
}
return 0;
}

View File

@@ -1,137 +0,0 @@
// -----------------------------------------------------------
// boost::dynamic_bitset timing tests
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
// NOTE:
// ~~~~~
// This is a preliminary, incomplete version.
//
// If you are interested in having more benchmarks please make a
// request on the boost list, which could encourage me to continue
// this work.
// Also, if you use boost::dynamic_bitset on a platform where
// CHAR_BIT >= 9 I suggest experimenting with the size of the count
// table in detail/dynamic_bitset.hpp and report any interesting
// discovery on the list as well.
//
//
// -----------------------------------------------------------------------//
#include "boost/config.hpp"
#if defined (__STL_CONFIG_H) && !defined (__STL_USE_NEW_IOSTREAMS)
// for pre 3.0 versions of libstdc++
# define BOOST_OLD_IOSTREAMS
#endif
// ------------------------------------------------- //
#include <typeinfo>
#include <iostream>
#if !defined(BOOST_OLD_IOSTREAMS)
# include <ostream>
#endif
#include "boost/cstdlib.hpp"
#include "boost/version.hpp"
#include "boost/timer.hpp"
#include "boost/dynamic_bitset.hpp"
namespace {
// the m_ prefixes, below, are mainly to avoid problems with g++:
// 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;
public:
boost_version(unsigned long v = BOOST_VERSION):
m_major(v / 100000), m_minor(v / 100 % 1000), m_subminor(v % 100) {}
friend std::ostream & operator<<(std::ostream &, const boost_version &);
};
// give up using basic_ostream, to avoid headaches with old libraries
std::ostream& operator<<(std::ostream& os, const boost_version & v) {
return os << v.m_major << '.' << v.m_minor << '.' << v.m_subminor;
}
}
void prologue()
{
std::cout << '\n';
std::cout << "Compiler: " << BOOST_COMPILER << '\n';
std::cout << "Std lib : " << BOOST_STDLIB << '\n';
std::cout << "Boost v.: " << boost_version() << '\n';
std::cout << '\n';
}
template <typename T>
void timing_test(T* = 0) // dummy parameter to workaround VC6
{
const unsigned long num = 100000;
// This variable is printed at the end of the test,
// to prevent the optimizer eliminating the call to
// count() in the loop below.
typename boost::dynamic_bitset<T>::size_type dummy = 0;
std::cout << "\nTimings for dynamic_bitset<" << typeid(T).name()
<< "> [" << num << " iterations]\n";
std::cout << "--------------------------------------------------\n";
{
boost::timer time;
const typename boost::dynamic_bitset<T>::size_type sz = 5000;
for (unsigned long i = 0; i < num; ++i) {
boost::dynamic_bitset<T> bs(sz, i);
dummy += bs.count();
}
const double elaps = time.elapsed();
std::cout << "Elapsed: " << elaps << '\n';
}
std::cout << "(total count: " << dummy << ")\n\n";
}
int main()
{
prologue();
timing_test<unsigned char>();
timing_test<unsigned short>();
timing_test<unsigned int>();
timing_test<unsigned long>();
# ifdef BOOST_HAS_LONG_LONG
timing_test< ::boost::ulong_long_type>();
# endif
return boost::exit_success;
}

View File

@@ -1,168 +0,0 @@
// --------------------------------------------------
//
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
// 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 "boost/config.hpp"
#include "boost/detail/workaround.hpp"
//#include "boost/static_assert.hpp" // gps
namespace boost {
namespace detail {
// Gives (read-)access to the object representation
// of an object of type T (3.9p4). CANNOT be used
// on a base sub-object
//
template <typename T>
inline const unsigned char * object_representation (T* p)
{
return static_cast<const unsigned char *>(static_cast<const void *>(p));
}
// ------- count function implementation --------------
namespace dynamic_bitset_count_impl {
typedef unsigned char byte_type;
enum mode { access_by_bytes, access_by_blocks };
template <mode> struct mode_to_type {};
// the table: wrapped in a class template, so
// that it is only instantiated if/when needed
//
template <bool dummy_name = true>
struct count_table { static const byte_type table[]; };
template <>
struct count_table<false> { /* no table */ };
const unsigned int table_width = 8;
template <bool b>
const byte_type count_table<b>::table[] =
{
// Automatically generated by GPTableGen.exe v.1.0
//
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
};
// overload for access by bytes
//
template <typename Iterator>
inline std::size_t do_count(Iterator first, std::size_t length,
int /*dummy param*/,
mode_to_type<access_by_bytes>* )
{
std::size_t num = 0;
if (length)
{
const byte_type * p = object_representation(&*first);
length *= sizeof(*first);
do {
num += count_table<>::table[*p];
++p;
--length;
} while (length);
}
return num;
}
// overload for access by blocks
//
template <typename Iterator, typename ValueType>
inline std::size_t do_count(Iterator first, std::size_t length, ValueType,
mode_to_type<access_by_blocks>*)
{
std::size_t num = 0;
while (length){
ValueType value = *first;
while (value) {
num += count_table<>::table[value & ((1u<<table_width) - 1)];
value >>= table_width;
}
++first;
--length;
}
return num;
}
} // dynamic_bitset_count_impl
// -------------------------------------------------------
// Some library implementations simply return a dummy
// value such as
//
// size_type(-1) / sizeof(T)
//
// from vector<>::max_size. This tries to get out more
// meaningful info.
//
template <typename T>
typename T::size_type vector_max_size_workaround(const T & v) {
typedef typename T::allocator_type allocator_type;
const typename allocator_type::size_type alloc_max =
v.get_allocator().max_size();
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 {
enum { value = (T(-1) > 0) }; // ensure T has no sign
};
template <>
struct dynamic_bitset_allowed_block_type<bool> {
enum { value = false };
};
} // namespace detail
} // namespace boost
#endif // include guard

View File

@@ -1,7 +1,7 @@
// --------------------------------------------------
// -----------------------------------------------------------
//
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2004.
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2004, 2008 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,8 +9,6 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset for documentation.
#ifndef BOOST_DYNAMIC_BITSET_HPP
#define BOOST_DYNAMIC_BITSET_HPP

View File

@@ -1,7 +1,7 @@
// --------------------------------------------------
// -----------------------------------------------------------
//
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2004.
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008, 2025 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,73 +9,43 @@
//
// -----------------------------------------------------------
// 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
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
// support for pre 3.0 libstdc++ - thanks Phil Edwards!
#if defined (__STL_CONFIG_H) && !defined (__STL_USE_NEW_IOSTREAMS)
# 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
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))
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(expr) \
(boost::detail::make_non_const(expr))
#else
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(expr) (expr)
#endif
// no-op function to workaround gcc bug c++/8419
//
#if (defined __BORLANDC__ && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))) \
|| (defined BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
#define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
namespace boost {
namespace detail {
template< typename T >
T
make_non_const( T t )
{
return t;
}
}
}
#if defined( __GNUC__ )
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT( expr ) \
( boost::detail::make_non_const( expr ) )
#else
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT( expr ) ( expr )
#endif
// if we can't use friends then private members are exposed
//
#if defined(BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS)
#define BOOST_DYNAMIC_BITSET_PRIVATE public
#else
#define BOOST_DYNAMIC_BITSET_PRIVATE private
#if ! defined( BOOST_NO_CXX11_HDR_FUNCTIONAL ) && ! defined( BOOST_DYNAMIC_BITSET_NO_STD_HASH )
# define BOOST_DYNAMIC_BITSET_SPECIALIZE_STD_HASH
#endif
// A couple of macros to cope with libraries without locale
// support. The first macro must be used to declare a reference
// to a ctype facet. The second one to widen a char by using
// that ctype object. If facets and locales aren't available
// the first macro is a no-op and the second one just expands
// to its parameter c.
//
#if defined (BOOST_USE_FACET)
#if ( defined( _MSVC_LANG ) && _MSVC_LANG >= 201703L ) || __cplusplus >= 201703L
# define BOOST_DYNAMIC_BITSET_USE_CPP17_OR_LATER
#endif
#define BOOST_DYNAMIC_BITSET_CTYPE_FACET(ch, name, loc) \
const std::ctype<ch> & name = \
BOOST_USE_FACET(std::ctype<ch>, loc) /**/
#define BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, c) \
(fac.widen(c))
#if ( defined( _MSVC_LANG ) && _MSVC_LANG >= 202002L ) || __cplusplus >= 202002L
# define BOOST_DYNAMIC_BITSET_CONSTEXPR20 constexpr
#else
#define BOOST_DYNAMIC_BITSET_CTYPE_FACET(ch, name, loc) /**/
#define BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, c) c
# define BOOST_DYNAMIC_BITSET_CONSTEXPR20
#endif
#endif // include guard

View File

@@ -0,0 +1,154 @@
// -----------------------------------------------------------
//
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008, 2025 Gennaro Prota
// Copyright (c) 2014 Glen Joseph Fernandes
// (glenjofe@gmail.com)
// Copyright (c) 2018 Evgeny Shulgin
// Copyright (c) 2019 Andrey Semashev
//
// 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_DETAIL_DYNAMIC_BITSET_HPP
#define BOOST_DETAIL_DYNAMIC_BITSET_HPP
#include <cstddef>
#include <memory>
#include <type_traits>
#include <utility>
namespace boost {
namespace detail {
namespace dynamic_bitset_impl {
template< typename AllocatorOrContainer, typename Block >
class is_container
{
private:
template< typename U >
static decltype( std::declval< U >().resize( std::size_t{} ), std::declval< U >()[ 0 ], typename U::value_type(), std::is_same< typename U::value_type, Block >{}, std::true_type{} ) test( int );
template< typename >
static std::false_type test( ... );
public:
static constexpr bool value = decltype( test< AllocatorOrContainer >( 0 ) )::value;
};
template< typename AllocatorOrContainer, bool IsContainer >
class allocator_type_extractor_impl;
template< typename AllocatorOrContainer >
class allocator_type_extractor_impl< AllocatorOrContainer, false >
{
public:
typedef AllocatorOrContainer type;
};
template< typename AllocatorOrContainer >
class allocator_type_extractor_impl< AllocatorOrContainer, true >
{
public:
typedef typename AllocatorOrContainer::allocator_type type;
};
template< typename AllocatorOrContainer, typename Block >
class allocator_type_extractor
{
public:
typedef typename allocator_type_extractor_impl<
AllocatorOrContainer,
is_container< AllocatorOrContainer, Block >::value >::type type;
};
template< typename T, int amount, int width /* = default */ >
struct shifter
{
static BOOST_DYNAMIC_BITSET_CONSTEXPR20 void
left_shift( T & v )
{
amount >= width ? ( v = 0 )
: ( v >>= BOOST_DYNAMIC_BITSET_WRAP_CONSTANT( amount ) );
}
};
template< bool value >
struct value_to_type
{
};
// for static_asserts
template< typename T >
struct allowed_block_type
{
enum
{
value = T( -1 ) > 0 // ensure T has no sign
};
};
template<>
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 );
BOOST_dynamic_bitset_is_numeric( int );
BOOST_dynamic_bitset_is_numeric( long );
BOOST_dynamic_bitset_is_numeric( long long );
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 );
BOOST_dynamic_bitset_is_numeric( unsigned long long );
// 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
#endif // include guard

View File

@@ -0,0 +1,36 @@
// -----------------------------------------------------------
// lowest_bit()
//
// Position of the lowest bit that is set.
//
// Copyright (c) 2003-2004, 2008, 2025 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 "boost/assert.hpp"
#include "boost/core/bit.hpp"
#include <type_traits>
namespace boost {
namespace detail {
template< typename T >
int
lowest_bit( T x )
{
BOOST_ASSERT( x >= 1 );
return boost::core::countr_zero( static_cast< typename std::make_unsigned< T >::type >( x ) );
}
}
}
#endif // include guard

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,49 @@
// -----------------------------------------------------------
//
// Copyright (c) 2015 Seth Heeren
//
// 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_DYNAMIC_BITSET_SERIALIZATION_HPP
#define BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
#include "boost/core/nvp.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
namespace boost {
// implementation for optional zero-copy serialization support
template< typename Block, typename Allocator >
class dynamic_bitset< Block, Allocator >::serialize_impl
{
public:
template< typename Ar >
static void
serialize( Ar & ar, dynamic_bitset< Block, Allocator > & bs, unsigned )
{
ar & boost::make_nvp( "m_num_bits", bs.m_num_bits )
& boost::make_nvp( "m_bits", bs.m_bits );
}
};
}
// ADL hook to Boost Serialization library
namespace boost {
namespace serialization {
template< typename Ar, typename Block, typename Allocator >
void
serialize( Ar & ar, dynamic_bitset< Block, Allocator > & bs, unsigned version )
{
dynamic_bitset< Block, Allocator >::serialize_impl::serialize( ar, bs, version );
}
} // namespace serialization
} // namespace boost
#endif // include guard

View File

@@ -1,7 +1,7 @@
// --------------------------------------------------
// -----------------------------------------------------------
//
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
// (C) Copyright Gennaro Prota 2003 - 2004.
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2004 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,9 +9,6 @@
//
// -----------------------------------------------------------
// See http://www.boost.org/libs/dynamic_bitset for documentation.
#ifndef BOOST_DYNAMIC_BITSET_FWD_HPP
#define BOOST_DYNAMIC_BITSET_FWD_HPP
@@ -19,10 +16,9 @@
namespace boost {
template <typename Block = unsigned long,
typename Allocator = std::allocator<Block> >
template< typename Block = unsigned long, typename AllocatorOrContainer = std::allocator< Block > >
class dynamic_bitset;
} // namespace boost
}
#endif // include guard

View File

@@ -1,39 +0,0 @@
// -------------------------------------
// lowest_bit.hpp
//
// Position of the lowest bit 'on'
//
// (C) Copyright Gennaro Prota 2003 - 2004.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// ------------------------------------------------------
#ifndef BOOST_LOWEST_BIT_HPP_GP_20030301
#define BOOST_LOWEST_BIT_HPP_GP_20030301
#include <cassert>
#include "boost/pending/integer_log2.hpp"
namespace boost {
template <typename T>
int lowest_bit(T x) {
assert(x >= 1); // PRE
// clear all bits on except the rightmost one,
// then calculate the logarithm base 2
//
return boost::integer_log2<T>( x - ( x & (x-1) ) );
}
}
#endif // include guard

View File

@@ -1,24 +1,15 @@
<!--
Copyright Beman Dawes 2002
Copyright Gennaro Prota 2006
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="refresh" content="0; URL=dynamic_bitset.html" />
<title></title>
</head>
<body>
Automatic redirection failed, please go to <a href=
"dynamic_bitset.html">dynamic_bitset.html</a>.
</body>
</html>
<!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=doc/html/index.html">
<title>Automatic redirection</title>
</head>
<body>
Automatic redirection failed, please go to
<a href="dynamic_bitset.html">doc/html/index.html</a>.&nbsp;<hr>
<p>© Copyright Beman Dawes, 2001</p>
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
</body>
</html>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<explicit-failures-markup>
<library name="dynamic_bitset">
<mark-unusable>
<toolset name="*c++98"/>
<toolset name="*gnu98"/>
<toolset name="*c++0x"/>
<toolset name="*gnu0x"/>
<toolset name="msvc-7.1"/>
<toolset name="msvc-8.*"/>
<toolset name="msvc-9.*"/>
<toolset name="msvc-10.*"/>
<toolset name="msvc-11.*"/>
<note author="Gennaro Prota">DynamicBitset requires at least C++11.</note>
</mark-unusable>
</library>
</explicit-failures-markup>

16
meta/libraries.json Normal file
View File

@@ -0,0 +1,16 @@
{
"key": "dynamic_bitset",
"name": "Dynamic Bitset",
"authors": [
"Jeremy Siek",
"Chuck Allison"
],
"description": "The dynamic_bitset template represents a set of bits. It provides access to the value of individual bits via 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 can change at runtime.",
"category": [
"Data structures"
],
"maintainers": [
"Gennaro Prota <firstName.lastName -at- gmail.com>"
],
"cxxstd": "11"
}

50
test/Jamfile.v2 Normal file
View File

@@ -0,0 +1,50 @@
#
# 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)
#
import os ;
import testing ;
# import rules for testing conditional on config file variables
import-search /boost/config/checks ;
import config : requires ;
project : requirements <library>/boost/dynamic_bitset//boost_dynamic_bitset ;
test-suite dynamic_bitset :
[ run dyn_bitset_unit_tests1.cpp : : : <library>/boost/filesystem//boost_filesystem
<library>/boost/system//boost_system ]
[ run dyn_bitset_unit_tests2.cpp : : : <library>/boost/filesystem//boost_filesystem
<library>/boost/system//boost_system ]
[ run dyn_bitset_unit_tests3.cpp : : : <library>/boost/filesystem//boost_filesystem
<library>/boost/system//boost_system ]
[ run dyn_bitset_unit_tests4.cpp : : : <library>/boost/filesystem//boost_filesystem
<library>/boost/system//boost_system ]
[ run test_ambiguous_set.cpp ]
[ run test_lowest_bit.cpp ]
[ run test_boost_hash.cpp ]
[ run test_std_hash.cpp : : : [ requires cxx11_hdr_unordered_set ] ]
[ compile-fail test_std_hash.cpp : [ requires cxx11_hdr_unordered_set ]
<define>BOOST_DYNAMIC_BITSET_NO_STD_HASH
: test_std_hash_disabled ]
;
# due to https://github.com/boostorg/serialization/issues/108
if ! [ os.environ UBSAN_OPTIONS ]
{
test-suite dynamic_bitset_serialization :
[ run dyn_bitset_unit_tests5.cpp
: : : <define>_SCL_SECURE_NO_WARNINGS=1
<library>/boost/filesystem//boost_filesystem
<library>/boost/serialization//boost_serialization
<library>/boost/system//boost_system ]
;
}

1630
test/bitset_test.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
# Copyright 2021-2024 Alexander Grund
# 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
cmake_minimum_required(VERSION 3.5...3.16)
project(cmake_subdir_test LANGUAGES CXX)
# Those 2 should work the same
# while using find_package for the installed Boost avoids the need to manually specify dependencies
if(BOOST_CI_INSTALL_TEST)
find_package(boost_dynamic_bitset REQUIRED)
else()
set(BOOST_INCLUDE_LIBRARIES dynamic_bitset)
add_subdirectory(../../../.. deps/boost EXCLUDE_FROM_ALL)
endif()
add_executable(main main.cpp)
target_link_libraries(main Boost::dynamic_bitset)
enable_testing()
add_test(NAME main COMMAND main)

8
test/cmake_test/main.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include <boost/dynamic_bitset.hpp>
int main()
{
const boost::dynamic_bitset<> db{3, 4};
return db[2] ? 0 : 1;
}

View File

@@ -0,0 +1,633 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006, 2025 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2014 Riccardo Marcangelo
//
// Copyright (c) 2014 Glen Joseph Fernandes
// (glenjofe@gmail.com)
//
// 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)
//
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/config.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/limits.hpp"
#if ! defined( BOOST_NO_CXX11_ALLOCATOR )
# include <cstdlib>
# include <new>
template< typename T >
class minimal_allocator
{
public:
typedef T value_type;
minimal_allocator()
{
}
template< typename U >
minimal_allocator( const minimal_allocator< U > & )
{
}
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 ] ) )
template< typename Tests, typename String >
void
run_string_tests( const String & s )
{
const std::size_t len = s.length();
const std::size_t step = len / 4 ? len / 4 : 1;
// bitset length determined by the string-related arguments
std::size_t i;
for ( i = 0; i <= len / 2; i += step ) {
Tests::from_string( s, i, len / 2 ); // len/2 - i bits
Tests::from_string( s, i, len ); // len - i bits
Tests::from_string( s, i, 1 + len * 2 ); // len - i bits
}
// bitset length explicitly specified
for ( i = 0; i <= len / 2; i += step ) {
for ( std::size_t sz = 0; sz <= len * 4; sz += step * 2 ) {
Tests::from_string( s, i, len / 2, sz );
Tests::from_string( s, i, len, sz );
Tests::from_string( s, i, 1 + len * 2, sz );
}
}
}
// tests the do-the-right-thing constructor dispatch
template< typename Tests, typename T >
void
run_numeric_ctor_tests()
{
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, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases()
{
typedef boost::dynamic_bitset< Block, AllocatorOrContainer >
bitset_type;
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
{
// NOTE:
//
// 1. keep this in sync with the numeric types supported
// for constructor dispatch (of course)
// 2. bool is tested separately; ugly and inelegant, but
// we don't have much time to think of a better solution
// which is likely to work on broken compilers
//
const int sizes[] = {
0, 1, 3, 7 * bits_per_block / 10, bits_per_block, 13 * bits_per_block / 10, 3 * bits_per_block
};
const bool values[] = { false, true };
for ( std::size_t 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, long long >();
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 >();
run_numeric_ctor_tests< Tests, unsigned long long >();
}
//=====================================================================
// Test construction from a string
{
run_string_tests< Tests >( std::string( "" ) ); // empty string
run_string_tests< Tests >( std::string( "1" ) );
run_string_tests< Tests >( long_string );
#if ! defined BOOST_NO_STD_WSTRING
// I need to decide what to do for non "C" locales here. On
// 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)
//
run_string_tests< Tests >(
std::wstring( L"11111000000111111111010101010101010101010111111" ) );
#endif
// Note that these are _valid_ arguments
Tests::from_string( std::string( "x11y" ), 1, 2 );
Tests::from_string( std::string( "x11" ), 1, 10 );
Tests::from_string( std::string( "x11" ), 1, 10, 10 );
}
//=====================================================================
// test from_block_range
{
std::vector< Block > blocks;
Tests::from_block_range( blocks );
}
{
std::vector< Block > blocks( 3 );
blocks[ 0 ] = static_cast< Block >( 0 );
blocks[ 1 ] = static_cast< Block >( 1 );
blocks[ 2 ] = all_1s;
Tests::from_block_range( blocks );
}
{
const unsigned int n = ( std::numeric_limits< unsigned char >::max )();
std::vector< Block > blocks( n );
for ( typename std::vector< Block >::size_type i = 0; i < n; ++i )
blocks[ i ] = static_cast< Block >( i );
Tests::from_block_range( blocks );
}
//=====================================================================
// test iterators
{
bitset_type b;
Tests::iterate_forward( b );
Tests::iterate_backward( b );
Tests::iterator_operations( b );
}
{
bitset_type b( 1, 1ul );
Tests::iterate_forward( b );
Tests::iterate_backward( b );
Tests::iterator_operations( b );
}
{
bitset_type b( bitset_type::bits_per_block, 100ul );
Tests::iterate_forward( b );
Tests::iterate_backward( b );
Tests::iterator_operations( b );
}
{
bitset_type b( long_string );
Tests::iterate_forward( b );
Tests::iterate_backward( b );
Tests::iterator_operations( b );
}
//=====================================================================
// test to_block_range
{
bitset_type b;
Tests::to_block_range( b );
}
{
bitset_type b( 1, 1ul );
Tests::to_block_range( b );
}
{
bitset_type b( long_string );
Tests::to_block_range( b );
}
//=====================================================================
// Test copy constructor
{
bitset_type b;
Tests::copy_constructor( b );
}
{
bitset_type b( "0" );
Tests::copy_constructor( b );
}
{
bitset_type b ( long_string );
Tests::copy_constructor( b );
}
//=====================================================================
// Test copy assignment operator
{
bitset_type a, b;
Tests::copy_assignment_operator( a, b );
}
{
bitset_type a( "1" ), b( "0" );
Tests::copy_assignment_operator( a, b );
}
{
bitset_type a( long_string ), b( long_string );
Tests::copy_assignment_operator( a, b );
}
{
bitset_type a;
bitset_type b( long_string ); // b greater than a, a empty
Tests::copy_assignment_operator( a, b );
}
{
bitset_type a( "0" );
bitset_type b( long_string ); // b greater than a
Tests::copy_assignment_operator( a, b );
}
//=====================================================================
// Test move constructor
{
bitset_type b;
Tests::move_constructor( b );
}
{
bitset_type b( "0" );
Tests::move_constructor( b );
}
{
bitset_type b( long_string );
Tests::move_constructor( b );
}
//=====================================================================
// Test move assignment operator
{
bitset_type a, b;
Tests::move_assignment_operator( a, b );
}
{
bitset_type a( "1" ), b( "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( "0" );
bitset_type b( long_string ); // b greater than a
Tests::move_assignment_operator( a, b );
}
//=====================================================================
// Test swap
{
bitset_type a;
bitset_type b( "1" );
Tests::swap( a, b );
Tests::swap( b, a );
Tests::swap( a, a );
}
{
bitset_type a;
bitset_type b( long_string );
Tests::swap( a, b );
Tests::swap( b, a );
}
{
bitset_type a( "0" );
bitset_type b( long_string );
Tests::swap( a, b );
Tests::swap( b, a );
Tests::swap( a, a );
Tests::swap( b, b );
}
//=====================================================================
// Test resize
{
bitset_type a;
Tests::resize( a );
}
{
bitset_type a( "0" );
Tests::resize( a );
}
{
bitset_type a( "1" );
Tests::resize( a );
}
{
bitset_type a( long_string );
Tests::resize( a );
}
//=====================================================================
// Test clear
{
bitset_type a;
Tests::clear( a );
}
{
bitset_type a( long_string );
Tests::clear( a );
}
//=====================================================================
// Test pop back
{
bitset_type a( "01" );
Tests::pop_back( a );
}
{
bitset_type a( "10" );
Tests::pop_back( a );
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
bitset_type a( size_to_fill_all_blocks, 255ul );
Tests::pop_back( a );
}
{
bitset_type a( long_string.c_str() );
Tests::pop_back( a );
}
//=====================================================================
// Test pop_front
{
bitset_type a( "01" );
Tests::pop_front( a );
}
{
bitset_type a( "10" );
Tests::pop_front( a );
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
bitset_type a( size_to_fill_all_blocks, 255ul );
Tests::pop_front( a );
}
{
bitset_type a( long_string.c_str() );
Tests::pop_front( a );
}
//=====================================================================
// Test append bit
{
bitset_type a;
Tests::append_bit( a );
}
{
bitset_type a( "0" );
Tests::append_bit( a );
}
{
bitset_type a( "1" );
Tests::append_bit( a );
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
bitset_type a( size_to_fill_all_blocks, 255ul );
Tests::append_bit( a );
}
{
bitset_type a( long_string );
Tests::append_bit( a );
}
//=====================================================================
// Test push_front
{
bitset_type a;
Tests::prepend_bit( a );
}
{
bitset_type a( "0" );
Tests::prepend_bit( a );
}
{
bitset_type a( "1" );
Tests::prepend_bit( a );
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
bitset_type a( size_to_fill_all_blocks, 255ul );
Tests::prepend_bit( a );
}
{
bitset_type a( long_string );
Tests::prepend_bit( a );
}
//=====================================================================
// Test append block
{
bitset_type a;
Tests::append_block( a );
}
{
bitset_type a( "0" );
Tests::append_block( a );
}
{
bitset_type a( "1" );
Tests::append_block( a );
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
bitset_type a( size_to_fill_all_blocks, 15ul );
Tests::append_block( a );
}
{
bitset_type a( long_string.c_str() );
Tests::append_block( a );
}
//=====================================================================
// Test append block range
{
bitset_type a;
std::vector< Block > blocks;
Tests::append_block_range( a, blocks );
}
{
bitset_type a( "0" );
std::vector< Block > blocks( 3 );
blocks[ 0 ] = static_cast< Block >( 0 );
blocks[ 1 ] = static_cast< Block >( 1 );
blocks[ 2 ] = all_1s;
Tests::append_block_range( a, blocks );
}
{
bitset_type a( "1" );
const unsigned int n = ( std::numeric_limits< unsigned char >::max )();
std::vector< Block > blocks( n );
for ( typename std::vector< Block >::size_type i = 0; i < n; ++i )
blocks[ i ] = static_cast< Block >( i );
Tests::append_block_range( a, blocks );
}
{
bitset_type a;
a.append( Block( 1 ) );
a.append( Block( 2 ) );
Block x[] = { 3, 4, 5 };
std::size_t sz = sizeof( x ) / sizeof( x[ 0 ] );
std::vector< Block > blocks( x, x + sz );
Tests::append_block_range( a, blocks );
}
{
bitset_type a( long_string.c_str() );
std::vector< Block > blocks( 3 );
blocks[ 0 ] = static_cast< Block >( 0 );
blocks[ 1 ] = static_cast< Block >( 1 );
blocks[ 2 ] = all_1s;
Tests::append_block_range( a, blocks );
}
// Test with input iterators
{
bitset_type b;
Tests::append_block_range_input_iter( b );
}
{
bitset_type b( "0" );
Tests::append_block_range_input_iter( b );
}
{
bitset_type b( long_string.c_str() );
Tests::append_block_range_input_iter( b );
}
//=====================================================================
// Test bracket operator
{
bitset_type b1;
std::vector< bool > bitvec1;
Tests::operator_bracket( b1, bitvec1 );
}
{
bitset_type b( "1" );
std::vector< bool > bit_vec( 1, true );
Tests::operator_bracket( b, bit_vec );
}
{
bitset_type b( long_string.c_str() );
std::size_t n = long_string.size();
std::vector< bool > bit_vec( n );
for ( std::size_t i = 0; i < n; ++i )
bit_vec[ i ] = long_string[ n - 1 - i ] == '0' ? 0 : 1;
Tests::operator_bracket( b, bit_vec );
}
//=====================================================================
// Test at
{
bitset_type b1;
std::vector< bool > bitvec1;
Tests::at( b1, bitvec1 );
}
{
bitset_type b( "1" );
std::vector< bool > bit_vec( 1, true );
Tests::at( b, bit_vec );
}
{
bitset_type b( long_string.c_str() );
std::size_t n = long_string.size();
std::vector< bool > bit_vec( n );
for ( std::size_t i = 0; i < n; ++i )
bit_vec[ i ] = long_string[ n - 1 - i ] == '0' ? 0 : 1;
Tests::at( b, bit_vec );
}
//=====================================================================
// Test max_size
#if ! defined( BOOST_NO_CXX11_ALLOCATOR )
{
typedef boost::dynamic_bitset< Block, minimal_allocator< Block > > Bitset;
Bitset b;
bitset_test< Bitset >::max_size( b );
}
#endif
{
typedef boost::dynamic_bitset< Block, small_vector< Block > > Bitset;
Bitset b;
bitset_test< Bitset >::max_size( b );
}
// Test copy-initialize with default constructor
{
bitset_type b[ 1 ] = {};
(void)b;
}
}
int
main()
{
run_test_cases< unsigned char >();
run_test_cases< unsigned char, small_vector< unsigned char > >();
run_test_cases< unsigned short >();
run_test_cases< unsigned short, small_vector< unsigned short > >();
run_test_cases< unsigned int >();
run_test_cases< unsigned int, small_vector< unsigned int > >();
run_test_cases< unsigned long >();
run_test_cases< unsigned long, small_vector< unsigned long > >();
run_test_cases< unsigned long long >();
run_test_cases< unsigned long long, small_vector< unsigned long long > >();
return boost::report_errors();
}

View File

@@ -0,0 +1,387 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006, 2025 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2018 Evgeny Shulgin
//
// 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)
//
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases()
{
typedef boost::dynamic_bitset< Block, AllocatorOrContainer > bitset_type;
typedef bitset_test< bitset_type > Tests;
const int bits_per_block = bitset_type::bits_per_block;
const std::string long_string = get_long_string();
//=====================================================================
// Test operator&=
{
bitset_type lhs, rhs;
Tests::and_assignment( lhs, rhs );
}
{
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::and_assignment( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::and_assignment( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::and_assignment( lhs, rhs );
}
//=====================================================================
// Test operator |=
{
bitset_type lhs, rhs;
Tests::or_assignment( lhs, rhs );
}
{
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::or_assignment( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::or_assignment( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::or_assignment( lhs, rhs );
}
//=====================================================================
// Test operator^=
{
bitset_type lhs, rhs;
Tests::xor_assignment( lhs, rhs );
}
{
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::xor_assignment( lhs, rhs );
}
{
bitset_type lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
Tests::xor_assignment( lhs, rhs );
}
{
bitset_type lhs( long_string ), rhs( long_string );
Tests::xor_assignment( lhs, rhs );
}
//=====================================================================
// Test operator-=
{
bitset_type lhs, rhs;
Tests::sub_assignment( lhs, rhs );
}
{
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::sub_assignment( lhs, rhs );
}
{
bitset_type lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
Tests::sub_assignment( lhs, rhs );
}
{
bitset_type lhs( long_string ), rhs( long_string );
Tests::sub_assignment( lhs, rhs );
}
//=====================================================================
// Test operator<<=
{ // case pos == 0
std::size_t pos = 0;
{
bitset_type b;
Tests::shift_left_assignment( b, pos );
}
{
bitset_type b( std::string( "1010" ) );
Tests::shift_left_assignment( b, pos );
}
{
bitset_type b( long_string );
Tests::shift_left_assignment( b, pos );
}
}
{
// test with both multiple and
// non multiple of bits_per_block
const int how_many = 10;
for ( int i = 1; i <= how_many; ++i ) {
std::size_t multiple = i * bits_per_block;
std::size_t non_multiple = multiple - 1;
bitset_type b( long_string );
Tests::shift_left_assignment( b, multiple );
Tests::shift_left_assignment( b, non_multiple );
}
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
bitset_type b( long_string );
Tests::shift_left_assignment( b, pos );
}
{ // case pos >= n
std::size_t pos = long_string.size();
bitset_type b( long_string );
Tests::shift_left_assignment( b, pos );
}
//=====================================================================
// Test operator>>=
{ // case pos == 0
std::size_t pos = 0;
{
bitset_type b;
Tests::shift_right_assignment( b, pos );
}
{
bitset_type b( std::string( "1010" ) );
Tests::shift_right_assignment( b, pos );
}
{
bitset_type b( long_string );
Tests::shift_right_assignment( b, pos );
}
}
{
// test with both multiple and
// non multiple of bits_per_block
const int how_many = 10;
for ( int i = 1; i <= how_many; ++i ) {
std::size_t multiple = i * bits_per_block;
std::size_t non_multiple = multiple - 1;
bitset_type b( long_string );
Tests::shift_right_assignment( b, multiple );
Tests::shift_right_assignment( b, non_multiple );
}
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
bitset_type b( long_string );
Tests::shift_right_assignment( b, pos );
}
{ // case pos >= n
std::size_t pos = long_string.size();
bitset_type b( long_string );
Tests::shift_right_assignment( b, pos );
}
//=====================================================================
// test b.set()
{
bitset_type b;
Tests::set_all( b );
}
{
bitset_type b( std::string( "0" ) );
Tests::set_all( b );
}
{
bitset_type b( long_string );
Tests::set_all( b );
}
//=====================================================================
// Test b.set(pos)
{ // case pos >= b.size()
bitset_type b;
Tests::set_one( b, 0, true );
Tests::set_one( b, 0, false );
}
{ // case pos < b.size()
bitset_type b( std::string( "0" ) );
Tests::set_one( b, 0, true );
Tests::set_one( b, 0, false );
}
{ // case pos == b.size() / 2
bitset_type b( long_string );
Tests::set_one( b, long_string.size() / 2, true );
Tests::set_one( b, long_string.size() / 2, false );
}
//=====================================================================
// Test b.set(pos, len)
// case size is 0
{
bitset_type b( std::string( "10" ) ) ;
Tests::set_segment( b, 0, 0, true );
Tests::set_segment( b, 0, 0, false );
}
{ // case size is 1
bitset_type b( std::string( "0" ) );
Tests::set_segment( b, 0, 1, true );
Tests::set_segment( b, 0, 1, false );
}
{ // case fill the whole set
bitset_type b( long_string );
Tests::set_segment( b, 0, b.size(), true );
Tests::set_segment( b, 0, b.size(), false );
}
{ // case pos = size / 4, len = size / 2
bitset_type b( long_string );
Tests::set_segment( b, b.size() / 4, b.size() / 2, true );
Tests::set_segment( b, b.size() / 4, b.size() / 2, false );
}
{ // case pos = block_size / 2, len = size - block_size
bitset_type b( long_string );
Tests::set_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block, true );
Tests::set_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block, false );
}
{ // case pos = 1, len = size - 2
bitset_type b( long_string );
Tests::set_segment( b, 1, b.size() - 2, true );
Tests::set_segment( b, 1, b.size() - 2, false );
}
{ // case pos = 3, len = 7
bitset_type b( long_string );
Tests::set_segment( b, 3, 7, true );
Tests::set_segment( b, 3, 7, false );
}
//=====================================================================
// Test b.reset()
{
bitset_type b;
Tests::reset_all( b );
}
{
bitset_type b( std::string( "0" ) );
Tests::reset_all( b );
}
{
bitset_type b( long_string );
Tests::reset_all( b );
}
//=====================================================================
// Test b.reset(pos)
{ // case pos >= b.size()
bitset_type b;
Tests::reset_one( b, 0 );
}
{ // case pos < b.size()
bitset_type b( std::string( "0" ) );
Tests::reset_one( b, 0 );
}
{ // case pos == b.size() / 2
bitset_type b( long_string );
Tests::reset_one( b, long_string.size() / 2 );
}
//=====================================================================
// Test b.reset(pos, len)
{ // case size is 1
bitset_type b( std::string( "0" ) );
Tests::reset_segment( b, 0, 1 );
}
{ // case fill the whole set
bitset_type b( long_string );
Tests::reset_segment( b, 0, b.size() );
}
{ // case pos = size / 4, len = size / 2
bitset_type b( long_string );
Tests::reset_segment( b, b.size() / 4, b.size() / 2 );
}
{ // case pos = block_size / 2, len = size - block_size
bitset_type b( long_string );
Tests::reset_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block );
}
{ // case pos = 1, len = size - 2
bitset_type b( long_string );
Tests::reset_segment( b, 1, b.size() - 2 );
}
{ // case pos = 3, len = 7
bitset_type b( long_string );
Tests::reset_segment( b, 3, 7 );
}
//=====================================================================
// Test ~b
{
bitset_type b;
Tests::operator_flip( b );
}
{
bitset_type b( std::string( "1" ) );
Tests::operator_flip( b );
}
{
bitset_type b( long_string );
Tests::operator_flip( b );
}
//=====================================================================
// Test b.flip()
{
bitset_type b;
Tests::flip_all( b );
}
{
bitset_type b( std::string( "1" ) );
Tests::flip_all( b );
}
{
bitset_type b( long_string );
Tests::flip_all( b );
}
//=====================================================================
// Test b.flip(pos)
{ // case pos >= b.size()
bitset_type b;
Tests::flip_one( b, 0 );
}
{ // case pos < b.size()
bitset_type b( std::string( "0" ) );
Tests::flip_one( b, 0 );
}
{ // case pos == b.size() / 2
bitset_type b( long_string );
Tests::flip_one( b, long_string.size() / 2 );
}
//=====================================================================
// Test b.flip(pos, len)
{ // case size is 1
bitset_type b( std::string( "0" ) );
Tests::flip_segment( b, 0, 1 );
}
{ // case fill the whole set
bitset_type b( long_string );
Tests::flip_segment( b, 0, b.size() );
}
{ // case pos = size / 4, len = size / 2
bitset_type b( long_string );
Tests::flip_segment( b, b.size() / 4, b.size() / 2 );
}
{ // case pos = block_size / 2, len = size - block_size
bitset_type b( long_string );
Tests::flip_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block );
}
{ // case pos = 1, len = size - 2
bitset_type b( long_string );
Tests::flip_segment( b, 1, b.size() - 2 );
}
{ // case pos = 3, len = 7
bitset_type b( long_string );
Tests::flip_segment( b, 3, 7 );
}
}
int
main()
{
run_test_cases< unsigned char >();
run_test_cases< unsigned char, small_vector< unsigned char > >();
run_test_cases< unsigned short >();
run_test_cases< unsigned short, small_vector< unsigned short > >();
run_test_cases< unsigned int >();
run_test_cases< unsigned int, small_vector< unsigned int > >();
run_test_cases< unsigned long >();
run_test_cases< unsigned long, small_vector< unsigned long > >();
run_test_cases< unsigned long long >();
run_test_cases< unsigned long long, small_vector< unsigned long long > >();
return boost::report_errors();
}

View File

@@ -0,0 +1,841 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006, 2025 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
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/limits.hpp"
#include <assert.h>
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases()
{
// a bunch of typedefs which will be handy later on
typedef boost::dynamic_bitset< Block, AllocatorOrContainer > bitset_type;
typedef bitset_test< bitset_type > Tests;
// typedef typename bitset_type::size_type size_type; // unusable with Borland 5.5.1
const std::string long_string = get_long_string();
const std::size_t ul_width = std::numeric_limits< unsigned long >::digits;
//=====================================================================
// Test b.empty()
{
bitset_type b;
Tests::empty( b );
}
{
bitset_type b( 1, 1ul );
Tests::empty( b );
}
{
bitset_type b( bitset_type::bits_per_block + bitset_type::bits_per_block / 2, 15ul );
Tests::empty( b );
}
//=====================================================================
// Test b.to_long()
{
bitset_type b;
Tests::to_ulong( b );
}
{
bitset_type b( std::string( "1" ) );
Tests::to_ulong( b );
}
{
bitset_type b( bitset_type::bits_per_block, static_cast< unsigned long >( -1 ) );
Tests::to_ulong( b );
}
{
std::string str( ul_width - 1, '1' );
bitset_type b( str );
Tests::to_ulong( b );
}
{
std::string ul_str( ul_width, '1' );
bitset_type b( ul_str );
Tests::to_ulong( b );
}
{ // case overflow
bitset_type b( long_string );
Tests::to_ulong( b );
}
//=====================================================================
// Test to_string(b, str)
{
bitset_type b;
Tests::to_string( b );
}
{
bitset_type b( std::string( "0" ) );
Tests::to_string( b );
}
{
bitset_type b( long_string );
Tests::to_string( b );
}
//=====================================================================
// Test b.count()
{
bitset_type b;
Tests::count( b );
}
{
bitset_type b( std::string( "0" ) );
Tests::count( b );
}
{
bitset_type b( std::string( "1" ) );
Tests::count( b );
}
{
bitset_type b( 8, 255ul );
Tests::count( b );
}
{
bitset_type b( long_string );
Tests::count( b );
}
//=====================================================================
// Test b.size()
{
bitset_type b;
Tests::size( b );
}
{
bitset_type b( std::string( "0" ) );
Tests::size( b );
}
{
bitset_type b( long_string );
Tests::size( b );
}
//=====================================================================
// Test b.capacity()
{
bitset_type b;
Tests::capacity( b );
}
{
bitset_type b( 100 );
Tests::capacity( b );
}
//=====================================================================
// Test b.reserve()
{
bitset_type b;
Tests::reserve_test_one( b );
}
{
bitset_type b( 100 );
Tests::reserve_test_two( b );
}
//=====================================================================
// Test b.shrink_to_fit()
{
bitset_type b;
Tests::shrink_to_fit_test_one( b );
}
{
bitset_type b( 100 );
Tests::shrink_to_fit_test_two( b );
}
//=====================================================================
// Test b.all()
{
bitset_type b;
Tests::all( b );
Tests::all( ~b );
Tests::all( b.set() );
Tests::all( b.reset() );
}
{
bitset_type b( std::string( "0" ) );
Tests::all( b );
Tests::all( ~b );
Tests::all( b.set() );
Tests::all( b.reset() );
}
{
bitset_type b( long_string );
Tests::all( b );
Tests::all( ~b );
Tests::all( b.set() );
Tests::all( b.reset() );
}
//=====================================================================
// Test b.any()
{
bitset_type b;
Tests::any( b );
Tests::any( ~b );
Tests::any( b.set() );
Tests::any( b.reset() );
}
{
bitset_type b( std::string( "0" ) );
Tests::any( b );
Tests::any( ~b );
Tests::any( b.set() );
Tests::any( b.reset() );
}
{
bitset_type b( long_string );
Tests::any( b );
Tests::any( ~b );
Tests::any( b.set() );
Tests::any( b.reset() );
}
//=====================================================================
// Test b.none()
{
bitset_type b;
Tests::none( b );
Tests::none( ~b );
Tests::none( b.set() );
Tests::none( b.reset() );
}
{
bitset_type b( std::string( "0" ) );
Tests::none( b );
Tests::none( ~b );
Tests::none( b.set() );
Tests::none( b.reset() );
}
{
bitset_type b( long_string );
Tests::none( b );
Tests::none( ~b );
Tests::none( b.set() );
Tests::none( b.reset() );
}
//=====================================================================
// Test a.is_subset_of(b)
{
bitset_type a, b;
Tests::subset( a, b );
}
{
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::subset( a, b );
}
{
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::subset( a, b );
}
{
bitset_type a( long_string ), b( long_string );
Tests::subset( a, b );
}
{
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::subset( a, b );
}
{
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::subset( a, b );
}
//=====================================================================
// Test a.is_proper_subset_of(b)
{
bitset_type a, b;
Tests::proper_subset( a, b );
}
{
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::proper_subset( a, b );
}
{
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::proper_subset( a, b );
}
{
bitset_type a( long_string ), b( long_string );
Tests::proper_subset( a, b );
}
{
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::proper_subset( a, b );
}
{
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::proper_subset( a, b );
}
//=====================================================================
// Test intersects
{
bitset_type a; // empty
bitset_type b;
Tests::intersects( a, b );
}
{
bitset_type a;
bitset_type b( 5, 8ul );
Tests::intersects( a, b );
}
{
bitset_type a( 8, 0ul );
bitset_type b( 15, 0ul );
b[ 9 ] = 1;
Tests::intersects( a, b );
}
{
bitset_type a( 15, 0ul );
bitset_type b( 22, 0ul );
a[ 14 ] = b[ 14 ] = 1;
Tests::intersects( a, b );
}
//=====================================================================
// Test find_first
{
// empty bitset
bitset_type b;
Tests::find_first( b );
Tests::find_first( b, 0, false );
}
{
// bitset of size 1
bitset_type b( 1, 1ul );
Tests::find_first( b );
Tests::find_first( b, 0, false );
}
{
// all-0s bitset
bitset_type b( 4 * bitset_type::bits_per_block, 0ul );
Tests::find_first( b );
Tests::find_first( b, 0, false );
}
{
// first bit on or off
bitset_type b( 1, 1ul );
Tests::find_first( b );
b.set( 0, false );
Tests::find_first( b, 0, false );
}
{
// last bit on or off
bitset_type b( 4 * bitset_type::bits_per_block - 1, 0ul );
b.set( b.size() - 1 );
Tests::find_first( b );
b.set( b.size() - 1, false );
Tests::find_first( b, 0, false );
}
//=====================================================================
// Test find_next, find_next_off, offset find_first and offset find_first_off
{
// empty bitset
bitset_type b;
// check
Tests::find_pos( b, 0 );
Tests::find_pos( b, 1 );
Tests::find_pos( b, 200 );
Tests::find_pos( b, b.npos );
Tests::find_pos( b, 0, false );
Tests::find_pos( b, 1, false );
Tests::find_pos( b, 200, false );
Tests::find_pos( b, b.npos, false );
}
{
// bitset of size 1 (find_next can never find)
bitset_type b( 1, 1ul );
// check
Tests::find_pos( b, 0 );
Tests::find_pos( b, 1 );
Tests::find_pos( b, 200 );
Tests::find_pos( b, b.npos );
Tests::find_pos( b, 0, false );
Tests::find_pos( b, 1, false );
Tests::find_pos( b, 200, false );
Tests::find_pos( b, b.npos, false );
}
{
// all-1s bitset
bitset_type b( 16 * bitset_type::bits_per_block );
b.set();
// check
const typename bitset_type::size_type larger_than_size = 5 + b.size();
for ( typename bitset_type::size_type i = 0; i <= larger_than_size; ++i ) {
Tests::find_pos( b, i );
Tests::find_pos( b, i, false );
}
Tests::find_pos( b, b.npos );
Tests::find_pos( b, b.npos, false );
}
{
// a bitset with 1s at block boundary only
const int num_blocks = 32;
const int block_width = bitset_type::bits_per_block;
bitset_type b( num_blocks * block_width );
typename bitset_type::size_type i = block_width - 1;
for ( ; i < b.size(); i += block_width ) {
b.set( i );
typename bitset_type::size_type first_in_block = i - ( block_width - 1 );
b.set( first_in_block );
}
// check
const typename bitset_type::size_type larger_than_size = 5 + b.size();
for ( i = 0; i <= larger_than_size; ++i ) {
Tests::find_pos( b, i );
Tests::find_pos( b, i, false );
}
Tests::find_pos( b, b.npos );
Tests::find_pos( b, b.npos, false );
}
{
// bitset with alternate 1s and 0s
const typename bitset_type::size_type sz = 1000;
bitset_type b( sz );
typename bitset_type::size_type i = 0;
for ( ; i < sz; ++i ) {
b[ i ] = ( i % 2 == 0 );
}
// check
const typename bitset_type::size_type larger_than_size = 5 + b.size();
for ( i = 0; i <= larger_than_size; ++i ) {
Tests::find_pos( b, i );
Tests::find_pos( b, i, false );
}
Tests::find_pos( b, b.npos );
Tests::find_pos( b, b.npos, false );
}
//=====================================================================
// Test operator==
{
bitset_type a, b;
Tests::operator_equal( a, b );
}
{
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_equal( a, b );
}
{
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_equal( a, b );
}
{
bitset_type a( long_string ), b( long_string );
Tests::operator_equal( a, b );
}
{
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_equal( a, b );
}
{
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_equal( a, b );
}
//=====================================================================
// Test operator!=
{
bitset_type a, b;
Tests::operator_not_equal( a, b );
}
{
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_not_equal( a, b );
}
{
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_not_equal( a, b );
}
{
bitset_type a( long_string ), b( long_string );
Tests::operator_not_equal( a, b );
}
{
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_not_equal( a, b );
}
{
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_not_equal( a, b );
}
//=====================================================================
// Test operator<
{
bitset_type a, b;
Tests::operator_less_than( a, b );
}
{
bitset_type a;
bitset_type b( std::string( "1" ) );
Tests::operator_less_than( a, b );
}
{
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_less_than( a, b );
}
{
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_less_than( a, b );
}
{
bitset_type a( std::string( "10" ) ), b( std::string( "11" ) );
Tests::operator_less_than( a, b );
}
{
bitset_type a( std::string( "101" ) ), b( std::string( "11" ) );
Tests::operator_less_than( a, b );
}
{
bitset_type a( std::string( "10" ) ), b( std::string( "111" ) );
Tests::operator_less_than( a, b );
}
{
bitset_type a( std::string( "11" ) ), b( std::string( "111" ) );
Tests::operator_less_than( a, b );
}
{
bitset_type a( long_string ), b( long_string );
Tests::operator_less_than( a, b );
}
{
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_less_than( a, b );
}
{
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_less_than( a, b );
}
// check for consistency with ulong behaviour when the sizes are equal
{
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( a < b );
}
{
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( ! ( a < b ) );
}
{
bitset_type a( 3, 5ul ), b( 3, 4ul );
BOOST_TEST( ! ( a < b ) );
}
// when the sizes are not equal lexicographic compare does not necessarily correspond to ulong behavior
{
bitset_type a( 4, 4ul ), b( 3, 5ul );
BOOST_TEST( a < b );
}
{
bitset_type a( 3, 4ul ), b( 4, 5ul );
BOOST_TEST( ! ( a < b ) );
}
{
bitset_type a( 4, 4ul ), b( 3, 4ul );
BOOST_TEST( a < b );
}
{
bitset_type a( 3, 4ul ), b( 4, 4ul );
BOOST_TEST( ! ( a < b ) );
}
{
bitset_type a( 4, 5ul ), b( 3, 4ul );
BOOST_TEST( a < b );
}
{
bitset_type a( 3, 5ul ), b( 4, 4ul );
BOOST_TEST( ! ( a < b ) );
}
//=====================================================================
// Test operator<=
{
bitset_type a, b;
Tests::operator_less_than_eq( a, b );
}
{
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_less_than_eq( a, b );
}
{
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_less_than_eq( a, b );
}
{
bitset_type a( long_string ), b( long_string );
Tests::operator_less_than_eq( a, b );
}
{
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_less_than_eq( a, b );
}
{
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_less_than_eq( a, b );
}
// check for consistency with ulong behaviour
{
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( a <= b );
}
{
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( a <= b );
}
{
bitset_type a( 3, 5ul ), b( 3, 4ul );
BOOST_TEST( ! ( a <= b ) );
}
//=====================================================================
// Test operator>
{
bitset_type a, b;
Tests::operator_greater_than( a, b );
}
{
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_greater_than( a, b );
}
{
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_greater_than( a, b );
}
{
bitset_type a( long_string ), b( long_string );
Tests::operator_greater_than( a, b );
}
{
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_greater_than( a, b );
}
{
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_greater_than( a, b );
}
// check for consistency with ulong behaviour
{
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( ! ( a > b ) );
}
{
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( ! ( a > b ) );
}
{
bitset_type a( 3, 5ul ), b( 3, 4ul );
BOOST_TEST( a > b );
}
//=====================================================================
// Test operator<=
{
bitset_type a, b;
Tests::operator_greater_than_eq( a, b );
}
{
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::operator_greater_than_eq( a, b );
}
{
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_greater_than_eq( a, b );
}
{
bitset_type a( long_string ), b( long_string );
Tests::operator_greater_than_eq( a, b );
}
{
bitset_type a( long_string ), b( long_string );
a[ long_string.size() / 2 ].flip();
Tests::operator_greater_than_eq( a, b );
}
{
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::operator_greater_than_eq( a, b );
}
// check for consistency with ulong behaviour
{
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( ! ( a >= b ) );
}
{
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( a >= b );
}
{
bitset_type a( 3, 5ul ), b( 3, 4ul );
BOOST_TEST( a >= b );
}
//=====================================================================
// Test b.test(pos)
{ // case pos >= b.size()
bitset_type b;
Tests::test_bit( b, 0 );
}
{ // case pos < b.size()
bitset_type b( std::string( "0" ) );
Tests::test_bit( b, 0 );
}
{ // case pos == b.size() / 2
bitset_type b( long_string );
Tests::test_bit( b, long_string.size() / 2 );
}
//=====================================================================
// Test b.test_set(pos)
{ // case pos >= b.size()
bitset_type b;
Tests::test_set_bit( b, 0, true );
Tests::test_set_bit( b, 0, false );
}
{ // case pos < b.size()
bitset_type b( std::string( "0" ) );
Tests::test_set_bit( b, 0, true );
Tests::test_set_bit( b, 0, false );
}
{ // case pos == b.size() / 2
bitset_type 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;
bitset_type b( std::string( "1010" ) );
Tests::operator_shift_left( b, pos );
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
bitset_type b( long_string );
Tests::operator_shift_left( b, pos );
}
{ // case pos >= n
std::size_t pos = long_string.size();
bitset_type b( long_string );
Tests::operator_shift_left( b, pos );
}
//=====================================================================
// Test b >> pos
{ // case pos == 0
std::size_t pos = 0;
bitset_type b( std::string( "1010" ) );
Tests::operator_shift_right( b, pos );
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
bitset_type b( long_string );
Tests::operator_shift_right( b, pos );
}
{ // case pos >= n
std::size_t pos = long_string.size();
bitset_type b( long_string );
Tests::operator_shift_right( b, pos );
}
//=====================================================================
// Test a & b
{
bitset_type lhs, rhs;
Tests::operator_and( lhs, rhs );
}
{
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::operator_and( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::operator_and( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_and( lhs, rhs );
}
//=====================================================================
// Test a | b
{
bitset_type lhs, rhs;
Tests::operator_or( lhs, rhs );
}
{
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::operator_or( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::operator_or( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_or( lhs, rhs );
}
//=====================================================================
// Test a^b
{
bitset_type lhs, rhs;
Tests::operator_xor( lhs, rhs );
}
{
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::operator_xor( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::operator_xor( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_xor( lhs, rhs );
}
//=====================================================================
// Test a-b
{
bitset_type lhs, rhs;
Tests::operator_sub( lhs, rhs );
}
{
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
Tests::operator_sub( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
Tests::operator_sub( lhs, rhs );
}
{
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_sub( lhs, rhs );
}
}
int
main()
{
run_test_cases< unsigned char >();
run_test_cases< unsigned char, small_vector< unsigned char > >();
run_test_cases< unsigned short >();
run_test_cases< unsigned short, small_vector< unsigned short > >();
run_test_cases< unsigned int >();
run_test_cases< unsigned int, small_vector< unsigned int > >();
run_test_cases< unsigned long >();
run_test_cases< unsigned long, small_vector< unsigned long > >();
run_test_cases< unsigned long long >();
run_test_cases< unsigned long long, small_vector< unsigned long long > >();
return boost::report_errors();
}

View File

@@ -0,0 +1,313 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006, 2025 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)
//
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/config.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include <assert.h>
#include <cstddef>
#include <fstream>
#include <stdexcept>
#include <string>
#if ! defined( BOOST_NO_STRINGSTREAM )
# include <sstream>
#endif
#if defined BOOST_NO_STD_WSTRING
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
#endif
#if ! defined BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
std::wstring
widen_string( const std::string & str, const std::locale & loc = std::locale() )
{
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 = std::use_facet< ct_type >( loc );
result.resize( len );
for ( std::size_t i = 0; i < len; ++i )
tr_type::assign( result[ i ], ct.widen( str[ i ] ) );
}
return result;
}
#endif
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases()
{
typedef boost::dynamic_bitset< Block, AllocatorOrContainer > bitset_type;
typedef bitset_test< bitset_type > Tests;
//=====================================================================
// Test stream operator<<
{
// The test "variables" are: the stream type and its state, the
// exception mask, the width, the fill char and the padding side (left/right)
std::ios::iostate masks[] = {
std::ios::goodbit,
std::ios::eofbit,
std::ios::failbit,
std::ios::eofbit | std::ios::failbit
};
static std::string strings[] = {
std::string( "" ),
std::string( "0" ),
std::string( "1" ),
std::string( "11100" ),
get_long_string()
};
char fill_chars[] = { '*', 'x', ' ' };
std::size_t num_masks = sizeof( masks ) / sizeof( masks[ 0 ] );
std::size_t num_strings = sizeof( strings ) / sizeof( strings[ 0 ] );
std::size_t num_chars = sizeof( fill_chars ) / sizeof( fill_chars[ 0 ] );
std::fstream not_good_stream( "dynamic_bitset_tests - this file shouldn't exist", std::ios::in );
for ( std::size_t mi = 0; mi < num_masks; ++mi ) {
for ( std::size_t si = 0; si < num_strings; ++si ) {
std::streamsize slen = (std::streamsize)( strings[ si ].length() );
assert( ( std::numeric_limits< std::streamsize >::max )() >= (std::streamsize)( 1 + slen * 2 ) );
for ( std::size_t ci = 0; ci < num_chars; ++ci ) {
// note how "negative widths" are tested too
const std::streamsize widths[] = { -1 - slen / 2, 0, slen / 2, 1 + slen * 2 };
std::size_t num_widths = sizeof( widths ) / sizeof( widths[ 0 ] );
for ( std::size_t wi = 0; wi < num_widths; ++wi ) {
std::streamsize w = widths[ wi ];
{
// test 0 - stream !good()
if ( not_good_stream.good() )
throw std::logic_error( "Error in operator << tests"
" - please, double check" );
bitset_type b( strings[ si ] );
not_good_stream.width( w );
not_good_stream.fill( fill_chars[ ci ] );
try {
not_good_stream.exceptions( masks[ mi ] );
} catch ( ... ) {
}
Tests::stream_inserter( b, not_good_stream, "<unused_string>" );
}
{
// test 1a - file stream
scoped_temp_file stf;
bitset_type b( strings[ si ] );
std::ofstream file( stf.path().string().c_str(), std::ios::trunc );
file.width( w );
file.fill( fill_chars[ ci ] );
file.exceptions( masks[ mi ] );
Tests::stream_inserter( b, file, stf.path().string().c_str() );
}
{
// NOTE: there are NO string stream tests
}
#if ! defined( BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS )
{
// test 1b - wide file stream
scoped_temp_file stf;
bitset_type b( strings[ si ] );
std::wofstream file( stf.path().string().c_str() );
file.width( w );
file.fill( fill_chars[ ci ] );
file.exceptions( masks[ mi ] );
Tests::stream_inserter( b, file, stf.path().string().c_str() );
}
#endif
}
}
}
} // for (; mi..)
}
//=====================================================================
// Test stream operator>>
{
// The test "variables" are: the stream type, the exception mask,
// the actual contents (and/or state) of the stream, and width.
//
// With few exceptions, each test case consists of writing a different
// assortment of digits and "whitespaces" to a text stream and then checking
// that what was written gets read back unchanged. That's NOT guaranteed by
// the standard, unless the assortment always ends with a '\n' and satisfies
// other conditions (see C99, 7.19.2/2), however it works in practice and is
// 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)
//
// Note how the bitset object is not initially empty. That helps checking
// that it isn't erroneously clear()ed by operator>>.
std::ios::iostate masks[] = {
std::ios::goodbit,
std::ios::eofbit,
std::ios::failbit,
std::ios::eofbit | std::ios::failbit
};
const std::string spaces = "\t\n "; //"\t\n\v\f ";
const std::string long_string = get_long_string();
const static std::string strings[] = {
// empty string
std::string( "" ),
// no bitset
spaces,
// no bitset
std::string( "x" ),
std::string( "\t xyz" ),
// bitset of size 1
std::string( "0" ),
std::string( "1" ),
std::string( " 0 " ),
std::string( " 1 " ),
spaces + "1",
"1" + spaces,
spaces + "1" + spaces,
std::string( " x1x " ),
std::string( " 1x " ),
// long bitset
long_string,
" " + long_string + " xyz",
spaces + long_string,
spaces + long_string + spaces
};
//-----------------------------------------------------
std::stringstream not_good_stream;
not_good_stream << "test";
std::string sink;
not_good_stream >> sink; // now the stream should be in eof state
const std::size_t num_masks = sizeof( masks ) / sizeof( masks[ 0 ] );
const std::size_t num_strings = sizeof( strings ) / sizeof( strings[ 0 ] );
for ( std::size_t mi = 0; mi < num_masks; ++mi ) {
for ( std::size_t si = 0; si < num_strings; ++si ) {
const std::streamsize slen = (std::streamsize)( strings[ si ].length() );
assert( ( std::numeric_limits< std::streamsize >::max )() >= (std::streamsize)( 1 + slen * 2 ) );
std::streamsize widths[] = { -1, 0, slen / 2, slen, 1 + slen * 2 };
std::size_t num_widths = sizeof( widths ) / sizeof( widths[ 0 ] );
for ( std::size_t wi = 0; wi < num_widths; ++wi ) {
const std::streamsize w = widths[ wi ];
// test 0 - !good() stream
{
if ( not_good_stream.good() )
throw std::logic_error( "Error in operator >> tests"
" - please, double check" );
bitset_type b( 1, 15ul ); // note: b is not empty
not_good_stream.width( w );
try {
not_good_stream.exceptions( masks[ mi ] );
} catch ( ... ) {
}
std::string irrelevant;
Tests::stream_extractor( b, not_good_stream, irrelevant );
}
// test 1a - (narrow) file stream
{
scoped_temp_file stf;
bitset_type b( 1, 255ul );
{
std::ofstream f( stf.path().string().c_str() );
f << strings[ si ];
}
std::ifstream f( stf.path().string().c_str() );
f.width( w );
f.exceptions( masks[ mi ] );
Tests::stream_extractor( b, f, strings[ si ] );
}
#if ! defined( BOOST_NO_STRINGSTREAM )
// test 2a - stringstream
{
bitset_type b( 1, 255ul );
std::istringstream stream( strings[ si ] );
stream.width( w );
stream.exceptions( masks[ mi ] );
Tests::stream_extractor( b, stream, strings[ si ] );
}
#endif
#if ! defined( BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS )
// test 1b - wchar_t file stream
{
scoped_temp_file stf;
std::wstring wstr = widen_string( strings[ si ] );
bitset_type b( 1, 255ul );
{
std::basic_ofstream< wchar_t > of( stf.path().string().c_str() );
of << wstr;
}
std::basic_ifstream< wchar_t > f( stf.path().string().c_str() );
f.width( w );
f.exceptions( masks[ mi ] );
Tests::stream_extractor( b, f, wstr );
}
// test 2b - wstringstream
{
bitset_type b( 1, 255ul );
std::wstring wstr = widen_string( strings[ si ] );
std::wistringstream wstream( wstr );
wstream.width( w );
wstream.exceptions( masks[ mi ] );
Tests::stream_extractor( b, wstream, wstr );
}
#endif // BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
}
}
} // for ( mi = 0; ...)
}
//=====================================================================
// << Any other tests go here >>
// .....
}
int
main()
{
run_test_cases< unsigned char >();
run_test_cases< unsigned char, small_vector< unsigned char > >();
run_test_cases< unsigned short >();
run_test_cases< unsigned short, small_vector< unsigned short > >();
run_test_cases< unsigned int >();
run_test_cases< unsigned int, small_vector< unsigned int > >();
run_test_cases< unsigned long >();
run_test_cases< unsigned long, small_vector< unsigned long > >();
run_test_cases< unsigned long long >();
run_test_cases< unsigned long long, small_vector< unsigned long long > >();
return boost::report_errors();
}

View File

@@ -0,0 +1,110 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006, 2025 Gennaro Prota
//
// Copyright (c) 2015 Seth Heeren
//
// 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)
//
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include "boost/archive/xml_iarchive.hpp"
#include "boost/archive/xml_oarchive.hpp"
#include "boost/config.hpp"
#include "boost/dynamic_bitset/serialization.hpp"
#include "boost/serialization/vector.hpp"
#if ! defined( BOOST_NO_STRINGSTREAM )
# include <sstream>
#endif
#if defined BOOST_NO_STD_WSTRING
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
#endif
namespace {
template< typename Block >
struct SerializableType
{
boost::dynamic_bitset< Block > x;
private:
friend class boost::serialization::access;
template< class Archive >
void
serialize( Archive & ar, unsigned int )
{
ar & BOOST_SERIALIZATION_NVP( x );
}
};
template< typename Block, typename IArchive, typename OArchive >
void
test_serialization()
{
SerializableType< Block > a;
for ( int i = 0; i < 128; ++i )
a.x.resize( 11 * i, i % 2 );
#if ! defined( BOOST_NO_STRINGSTREAM )
std::stringstream ss;
// test serialization
{
OArchive oa( ss );
oa << BOOST_SERIALIZATION_NVP( a );
}
// test de-serialization
{
IArchive ia( ss );
SerializableType< Block > b;
ia >> BOOST_SERIALIZATION_NVP( b );
BOOST_TEST( a.x == b.x );
}
#else
# error "TODO implement file-based test path?"
#endif
}
template< typename Block >
void
test_binary_archive()
{
test_serialization< Block, boost::archive::binary_iarchive, boost::archive::binary_oarchive >();
}
template< typename Block >
void
test_xml_archive()
{
test_serialization< Block, boost::archive::xml_iarchive, boost::archive::xml_oarchive >();
}
}
template< typename Block >
void
run_test_cases()
{
test_binary_archive< Block >();
test_xml_archive< Block >();
}
int
main()
{
run_test_cases< unsigned char >();
run_test_cases< unsigned short >();
run_test_cases< unsigned int >();
run_test_cases< unsigned long >();
run_test_cases< unsigned long long >();
return boost::report_errors();
}

View File

@@ -0,0 +1,26 @@
//
// Copyright (C) 2018 James E. King III
//
// 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)
//
#include "boost/core/lightweight_test.hpp"
#include "boost/dynamic_bitset.hpp"
int
main( int, char *[] )
{
boost::dynamic_bitset<> x( 5 ); // all 0's by default
x.set( 1, 2 );
x.set( 3, 1, true );
x.set( 2, 1, false );
BOOST_TEST( ! x.test( 0 ) );
BOOST_TEST( x.test( 1 ) );
BOOST_TEST( ! x.test( 2 ) );
BOOST_TEST( x.test( 3 ) );
BOOST_TEST( ! x.test( 4 ) );
return boost::report_errors();
}

43
test/test_boost_hash.cpp Normal file
View File

@@ -0,0 +1,43 @@
//
// Copyright (C) 2019 James E. King III
//
// 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)
//
#include "boost/config.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/dynamic_bitset.hpp"
#include <set>
int
main( int, char *[] )
{
typedef boost::dynamic_bitset< unsigned long > bitset_type;
const std::string long_string =
"01001110101110110101011010000000000011110101101111111111";
const std::string long_string_prime_begin =
"11001110101110110101011010000000000011110101101111111111";
const std::string long_string_prime_end =
"01001110101110110101011010000000000011110101101111111110";
bitset_type zeroes( long_string.size(), 0 );
bitset_type stuff( long_string );
bitset_type stupb( long_string_prime_begin );
bitset_type stupe( long_string_prime_end );
bitset_type ones( long_string.size(), 1 );
boost::hash< bitset_type > bitset_hasher;
std::set< std::size_t > results;
results.insert( bitset_hasher( zeroes ) );
results.insert( bitset_hasher( stuff ) );
results.insert( bitset_hasher( stupb ) );
results.insert( bitset_hasher( stupe ) );
results.insert( bitset_hasher( ones ) );
// if any hash is identical to another there will be less than 5
BOOST_TEST_EQ( results.size(), 5 );
return boost::report_errors();
}

24
test/test_lowest_bit.cpp Normal file
View File

@@ -0,0 +1,24 @@
//
// Copyright (C) 2018 James E. King III
//
// 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)
//
#include "boost/core/lightweight_test.hpp"
#include "boost/cstdint.hpp"
#include "boost/dynamic_bitset/detail/lowest_bit.hpp"
int
main( int, char *[] )
{
for ( boost::int32_t i = 1; i < 32; ++i ) {
BOOST_TEST_EQ( i, boost::detail::lowest_bit( 1u << i ) );
}
BOOST_TEST_EQ( 2, boost::detail::lowest_bit( 123456788 ) );
BOOST_TEST_EQ( 30, boost::detail::lowest_bit( static_cast< boost::int64_t >( 1507208177123328 ) ) );
return boost::report_errors();
}

40
test/test_std_hash.cpp Normal file
View File

@@ -0,0 +1,40 @@
//
// Copyright (C) 2019 James E. King III
// Copyright (C) 2025 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)
//
#include "boost/core/lightweight_test.hpp"
#include "boost/dynamic_bitset.hpp"
#include <unordered_set>
int
main( int, char *[] )
{
typedef boost::dynamic_bitset< unsigned long > bitset_type;
const std::string long_string =
"01001110101110110101011010000000000011110101101111111111";
// Some bitsets with the same size but different underlying vectors.
const bitset_type zeroes( long_string.size(), 0 );
const bitset_type stuff( long_string );
const bitset_type one( long_string.size(), 1 );
// Some bitsets with different sizes but equal underlying vectors.
const bitset_type zeroes2( 2, 0 );
const bitset_type zeroes3( 3, 0 );
std::unordered_set< bitset_type > bitsets;
bitsets.insert( zeroes );
bitsets.insert( stuff );
bitsets.insert( one );
bitsets.insert( zeroes2 );
bitsets.insert( zeroes3 );
BOOST_TEST_EQ( bitsets.size(), 5 );
return boost::report_errors();
}