Compare commits

..

133 Commits

Author SHA1 Message Date
Gennaro Prota
c13a99640a Try a workaround to have MrDocs document the specialization of std::hash 2025-09-16 10:53:23 +02:00
Gennaro Prota
11088d0d80 Remove extra parentheses in the implementation of operator<()
Reason: Consistency.
2025-09-15 19:23:49 +02:00
Gennaro Prota
fa3cef5485 Add missing spaces in a comment
Reason: Consistency.
2025-09-15 19:23:49 +02:00
Gennaro Prota
4157a327d9 Simplify the implementation of all() 2025-09-15 19:23:49 +02:00
Gennaro Prota
eea6992389 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-09-15 19:23:49 +02:00
Gennaro Prota
87ea757f7b Add trailing periods to the \pre paragraphs that missed them
Reason: Consistency.
2025-09-15 19:22:48 +02:00
Gennaro Prota
8b729ca3ff Fix a few documentation glitches 2025-09-15 17:18:18 +02:00
Gennaro Prota
a6a7ffa9e6 Make the three "from string" constructors explicit
Making them non-explicit was an oversight.
2025-09-15 12:13:43 +02:00
Gennaro Prota
228d39efd2 Settle the documentation of the iterators
We choose to hide the iterator type definitions and just document their
category, which is enough.
2025-09-15 12:07:27 +02:00
Gennaro Prota
09b7ca2135 Improve the encapsulation of bit_iterator_base 2025-09-12 19:48:15 +02:00
Gennaro Prota
71eaf3136b Fix an error in the documentation of operator==() 2025-09-12 18:33:05 +02:00
Gennaro Prota
ca06119e71 Remove the dependency on core/allocator_access.hpp 2025-09-12 16:34:25 +02:00
Gennaro Prota
fae1e7f97a Make the max_size() tests a bit more meaningful 2025-09-12 11:53:01 +02:00
Gennaro Prota
94eef0dd8d Add a missing comment 2025-09-12 11:41:26 +02:00
Gennaro Prota
f3526cb606 Add push_front() and pop_front() 2025-09-12 11:10:33 +02:00
Gennaro Prota
d79c7f992d No longer use BOOST_NO_CXX11_RVALUE_REFERENCES
Reason: We require decent C++11 support anyway.
2025-09-12 10:42:05 +02:00
Gennaro Prota
ce3435f662 Add two blank lines
Reason: Readability, consistency.
2025-09-12 10:25:30 +02:00
Gennaro Prota
c3a0cc2a32 Make the descriptions of the preconditions of the three "from string" constructors more precise 2025-09-12 10:19:51 +02:00
Gennaro Prota
bd36e481d8 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-09-12 10:19:51 +02:00
Gennaro Prota
0d0e881254 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-09-12 10:19:51 +02:00
Gennaro Prota
ba12d33c84 Don't test for Tr::eq( c, one ) twice in init_from_string() 2025-09-12 10:19:51 +02:00
Gennaro Prota
36d52d6b00 No longer use boost::move()
Reason: We require C++11 now, so we can use std::move().
2025-09-12 10:19:51 +02:00
Gennaro Prota
95e06608e1 Actually test the move constructor in the move constructor tests
We were testing the *copy* constructor, instead.
2025-09-12 10:19:51 +02:00
Gennaro Prota
21eda71789 Replace a #include of a deprecated include file 2025-09-12 10:19:51 +02:00
Gennaro Prota
8587d4f97c Remove a superfluous #include directive 2025-09-12 10:19:51 +02:00
Gennaro Prota
c442ecdc90 Add missing const qualifiers 2025-09-12 10:19:51 +02:00
Gennaro Prota
ed2f5281fe Make lowest_bit() more efficient
As a nice bonus, this also removes the dependency on Boost.Integer.
2025-09-12 10:19:51 +02:00
Gennaro Prota
fd95d1b570 Remove a spurious space 2025-09-12 10:19:51 +02:00
Gennaro Prota
a02393bd26 Fix a misleading variable name 2025-09-12 10:19:51 +02:00
Gennaro Prota
d7ba1ffd13 Get rid of BOOST_STATIC_ASSERT() and BOOST_STATIC_CONSTANT()
Reason: They are no longer necessary, given that we require C++11 now.
2025-09-12 10:19:51 +02:00
Gennaro Prota
6ef22fc69c 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-09-12 10:19:51 +02:00
Gennaro Prota
6a5faf3597 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-09-12 10:19:51 +02:00
Gennaro Prota
399230316c Make pop_back() more efficient 2025-09-12 10:19:51 +02:00
Gennaro Prota
f997c1fa7f 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-09-12 10:19:51 +02:00
Gennaro Prota
969c7e0947 Make buffer_type public
Reason: Failures from GCC and Clang. See the new code comment.
2025-09-12 10:19:51 +02:00
Gennaro Prota
7668759686 Remove some outdated macros (workarounds for MSVC 6) 2025-09-12 10:19:51 +02:00
Gennaro Prota
7144965095 Remove another workaround for Codewarrior 8.3
Reason: Obsolete compiler.
2025-09-12 10:19:51 +02:00
Gennaro Prota
b0b94ec560 Add C++20 iterators
Reason: Requested on the mailing list.
2025-09-12 10:19:51 +02:00
Gennaro Prota
1f6e471132 Allow choosing the underlying container type
The user can now choose the underlying container 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-09-12 10:19:51 +02:00
Gennaro Prota
467e121a68 Add find_first_off(), find_first_off( size_type ) and find_next_off( size_type ) 2025-09-12 10:19:51 +02:00
Gennaro Prota
c12ffc8b37 Don't repeat the preprocessing condition to specialize std::hash 2025-09-12 10:19:51 +02:00
Alan de Freitas
dc2a88e9a7 Make the MrDocs documentation multipage 2025-09-12 10:19:51 +02:00
Alan de Freitas
1ead020341 Support CMake root mode 2025-09-12 10:19:51 +02:00
Gennaro Prota
0b177806ce Ensure all #includes are at the top of the source file 2025-09-12 10:19:38 +02:00
Gennaro Prota
055631591a Document our support for std::hash 2025-09-12 10:16:34 +02:00
Gennaro Prota
abbecdb56e Remove some symbol filters from mrdocs.yml
Reason: They no longer seem necessary.
2025-09-11 12:49:13 +02:00
Gennaro Prota
7a01d14918 Reword a comment using singular they 2025-09-11 12:49:13 +02:00
Gennaro Prota
9baffa4887 Document that max_size() doesn't emit exceptions 2025-09-11 12:49:13 +02:00
Gennaro Prota
baf130a7e6 Use noexcept instead of BOOST_NOEXCEPT
Reason: We require C++11 support anyway.
2025-09-11 12:49:13 +02:00
ivanpanch
9ad6687e9a Fix a typo (“slighly”) in a documentation comment 2025-09-11 12:49:13 +02:00
ivanpanch
fd5e2fae75 Remove a spurious comma in a documentation comment 2025-09-11 12:49:13 +02:00
Gennaro Prota
122c4b986d Avoid an interrupted sentence in the \brief documentation of the stream inserter 2025-09-11 12:49:13 +02:00
Gennaro Prota
495aec32a0 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-09-11 12:49:13 +02:00
Gennaro Prota
ba8c408b31 Add a missing const qualifier 2025-09-11 12:49:13 +02:00
Gennaro Prota
c63af26734 Fix an error in the documentation of resize() 2025-09-11 12:49:13 +02:00
Gennaro Prota
ff0b3b97f2 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-09-11 12:49:13 +02:00
Gennaro Prota
e8a570b4b4 Work around some glitches from the MrDocs parser 2025-09-11 12:49:13 +02:00
Gennaro Prota
5bba2b7694 Document our overload of hash_value() 2025-09-11 12:49:13 +02:00
Gennaro Prota
4a5dbf29af Fix two typos in the documentation comments 2025-09-11 12:49:13 +02:00
Gennaro Prota
e93f96cc96 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-09-11 12:49:13 +02:00
Gennaro Prota
edd9091371 Run the Antora workflow on macOS 15, in GitHub Actions 2025-09-11 12:49:13 +02:00
Gennaro Prota
b104747c51 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-09-11 12:49:13 +02:00
Gennaro Prota
2d33df8f43 Simplify a redundant assert condition 2025-09-11 12:49:13 +02:00
Gennaro Prota
8de7c429c3 Reflect some noexcept specifications of std::vector in dynamic_bitset
This closes issue #85.
2025-09-11 12:49:13 +02:00
Gennaro Prota
b06e995e77 Always use braces with for-statements, as well
Reason: Consistency and safety.

See: "Always use braces with if-statements".
2025-09-11 12:49:13 +02:00
Gennaro Prota
e173eb3531 Denote short and long consistently 2025-09-11 12:49:13 +02:00
Gennaro Prota
a4820c1146 Rename dynamic_bitset.tpp to "dynamic_bitset.ipp"
Reason: Having it copied at installation time.
2025-09-11 12:49:13 +02:00
Gennaro Prota
3ed154a1bd Leave inline to the compiler 2025-09-11 12:49:13 +02:00
Gennaro Prota
b18ddca496 Set badbit if an exception is thrown during output
Reason: This is what the standard formatted output functions do.
2025-09-11 12:49:13 +02:00
Gennaro Prota
3d7458554d Remove two erroneous references to the standard 2025-09-11 12:49:13 +02:00
Gennaro Prota
683e160337 Move a few includes to where they are actually used 2025-09-11 12:49:13 +02:00
Gennaro Prota
0187aa3d16 Always use braces with if-statements
Reason: Consistency and safety.
2025-09-11 12:49:13 +02:00
Gennaro Prota
1cb4f79f55 Fix a typo in the documentation of operator>>=() 2025-09-11 12:49:13 +02:00
Gennaro Prota
3b14784fa0 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-09-11 12:49:13 +02:00
Gennaro Prota
915950efb8 Add two missing spaces in a documentation comment 2025-09-11 12:49:13 +02:00
Gennaro Prota
a44af50e30 Also exclude bit_appender from the MrDocs documentation 2025-09-11 12:49:13 +02:00
Gennaro Prota
59c40f1978 Remove a pair of unneeded parentheses 2025-09-11 12:49:13 +02:00
Sébastien Loriot
6aafdcf80e qualify full path 2025-09-11 12:49:13 +02:00
Gennaro Prota
1eea7dc9e9 Fix nav.adoc 2025-09-11 12:49:13 +02:00
Gennaro Prota
f7237d08f2 Add a few links to the reference in the documentation index 2025-09-11 12:49:13 +02:00
Gennaro Prota
13693afa74 Add doc/package.json and doc/package-lock.json 2025-09-11 12:49:13 +02:00
Gennaro Prota
de0d6f1745 Exclude old, failing versions of Clang and GCC from CI 2025-09-11 12:49:13 +02:00
Gennaro Prota
023055938c Also build the documentation in the CI workflow 2025-09-11 12:49:13 +02:00
James E. King III
6a3775e91c 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-09-11 12:49:13 +02:00
Gennaro Prota
3673eb67af Rethrow any exception coming from the underlying vector, in the stream extractor 2025-09-11 12:49:13 +02:00
Gennaro Prota
4bd3dd25d6 Delete unary operator&() for dynamic_bitset::reference
Reason: That's better than declaring it as private and leaving it
undefined.
2025-09-11 12:49:13 +02:00
Gennaro Prota
85678044f2 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-09-11 12:49:13 +02:00
Gennaro Prota
2c5d4dafc5 Add a missing blank line 2025-09-11 12:49:13 +02:00
Gennaro Prota
3cdaaa77df Remove an unnecessary constructor definition 2025-09-11 12:49:13 +02:00
Gennaro Prota
dd5426c4a6 Remove an unnecessary implementation detail 2025-09-11 12:49:13 +02:00
Gennaro Prota
5d321779f8 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-09-11 12:49:13 +02:00
Gennaro Prota
e90c7c5074 Make scoped_temp_file non-copyable, as it should 2025-09-11 12:49:13 +02:00
Gennaro Prota
27c94d5a31 Remove a nonsensical typedef 2025-09-11 12:49:12 +02:00
Gennaro Prota
1cc0ea2d18 Don't use lowerCamelCase for template type parameters 2025-09-11 12:49:12 +02:00
Gennaro Prota
7f88f43c3e Copy edit a comment 2025-09-11 12:49:12 +02:00
Gennaro Prota
e478613276 Remove a few unneeded permission notices 2025-09-11 12:49:12 +02:00
Gennaro Prota
970624a2fe Port the documentation to MrDocs and Antora 2025-09-11 12:49:12 +02:00
Gennaro Prota
9cbb307df1 Reformat all the C++ code (with ClangFormat) 2025-09-11 12:49:12 +02:00
Gennaro Prota
e6eb4d62e7 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-09-11 12:49:12 +02:00
Gennaro Prota
7df7ebd808 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-09-11 12:49:04 +02:00
Gennaro Prota
5bd37d352a Leverage core::popcount() in the implementation of count()
Reason: This significantly simplifies the code, replacing a previous
complex and error-prone implementation.
2025-09-11 12:36:49 +02:00
Gennaro Prota
ad7d867a83 Fix some inconsistent placement of const qualifiers 2025-09-11 12:36:49 +02:00
Gennaro Prota
f56b3dde37 Assert on the precondition to pop_back() 2025-09-11 12:36:49 +02:00
Gennaro Prota
32ae43ef6d Make the swap() functions noexcept 2025-09-11 12:36:49 +02:00
Gennaro Prota
92789a9f61 Remove a misleading comment 2025-09-11 12:36:49 +02:00
Gennaro Prota
f801c2ced8 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-09-11 12:36:49 +02:00
Gennaro Prota
6e17428110 Remove a top-level const qualifier for a function parameter 2025-09-11 12:36:49 +02:00
Gennaro Prota
0f3612bd4a Add a missing const qualifier in a test function 2025-09-11 12:36:49 +02:00
Gennaro Prota
be94d262e4 Use BOOST_TEST(), not assert(), for test cases 2025-09-11 12:36:49 +02:00
Gennaro Prota
8235c9c523 Remove other workarounds for obsolete compilers 2025-09-11 12:36:49 +02:00
Gennaro Prota
072714abdc 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-09-11 12:36:49 +02:00
Gennaro Prota
a87502c04f Clean up detail/lowest_bit.hpp (mostly, reformat) 2025-09-11 12:36:49 +02:00
Gennaro Prota
98964c77c9 Remove a naive comment
If you are asserting on it at the beginning of the function, it's
clearly a precondition :-).
2025-09-11 12:36:49 +02:00
Gennaro Prota
68e48485b2 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-09-11 12:36:49 +02:00
Gennaro Prota
2c31089bb2 Remove inconsistent uses of title case 2025-09-11 12:36:49 +02:00
Gennaro Prota
cdbcfd3853 Remove trailing whitespace 2025-09-11 12:36:48 +02:00
Gennaro Prota
55ca6c1449 Remove an unneeded #include directive in a test file 2025-09-11 12:36:48 +02:00
Gennaro Prota
20a866a032 Remove a tab character in a test file 2025-09-11 12:36:48 +02:00
Gennaro Prota
bf53144cd7 Remove a superfluous #include directive 2025-09-11 12:36:48 +02:00
Gennaro Prota
8d5dee07be Remove superfluous parentheses around a macro name 2025-09-11 12:36:48 +02:00
Gennaro Prota
e16b7bf01a Copy edit the readme
Note how I removed the "Directories" paragraph, as it just stated the
obvious.
2025-09-11 12:36:48 +02:00
Gennaro Prota
0a3198a2f0 Remove an unused, junk function template 2025-09-11 12:36:48 +02:00
Gennaro Prota
17bf6c27c8 Consistently use BOOST_ASSERT() in the implementation
Note: Not in the unit tests, which better do without the dependency.
2025-09-11 12:36:48 +02:00
Gennaro Prota
174050bee8 Remove a workaround for CodeWarrior 8 2025-09-11 12:36:48 +02:00
Gennaro Prota
9e164b9db7 Remove a spurious #undef directive
The #undef'd macro wasn't actually defined anywhere.
2025-09-11 12:36:48 +02:00
Gennaro Prota
b051052884 Declare some internal details as private
They had been accidentally made public.
2025-09-11 12:36:48 +02:00
Gennaro Prota
f2db3e80d6 Remove some redundant access specifiers 2025-09-11 12:36:48 +02:00
Gennaro Prota
a9a0d152d9 Remove a hopefully outdated workaround 2025-09-11 12:36:48 +02:00
Gennaro Prota
240c721d88 Remove a nonsensical usage of boost::addressof
Because `dynamic_bitset` doesn't overload unary `operator &`.
2025-09-11 12:36:48 +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
20 changed files with 3468 additions and 2298 deletions

View File

@@ -27,7 +27,6 @@ on:
- feature/**
- fix/**
- pr/**
- experiments/**
paths-ignore:
- LICENSE
- meta/**
@@ -52,7 +51,7 @@ jobs:
include:
- { name: Windows, os: windows-latest }
- { name: Ubuntu, os: ubuntu-latest }
- { name: macOS, os: macos-latest }
- { name: macOS, os: macos-15 }
runs-on: ${{ matrix.os }}
defaults:
run:

View File

@@ -7,26 +7,64 @@
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 (NOT DYNAMIC_BITSET_MRDOCS_BUILD)
target_link_libraries(boost_dynamic_bitset
INTERFACE
Boost::assert
Boost::config
Boost::container_hash
Boost::core
Boost::integer
Boost::move
Boost::static_assert
Boost::throw_exception
)
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)
@@ -44,6 +82,9 @@ if (DYNAMIC_BITSET_MRDOCS_BUILD)
# 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)

View File

@@ -10,9 +10,6 @@ constant boost_dependencies :
/boost/config//boost_config
/boost/container_hash//boost_container_hash
/boost/core//boost_core
/boost/integer//boost_integer
/boost/move//boost_move
/boost/static_assert//boost_static_assert
/boost/throw_exception//boost_throw_exception ;
project /boost/dynamic_bitset

View File

@@ -39,7 +39,6 @@ antora:
using-namespaces:
- 'boost::'
- require: '@cppalliance/antora-cpp-reference-extension'
version: 'develop'
dependencies:
- name: 'boost'
repo: 'https://github.com/boostorg/boost.git'

View File

@@ -1,5 +1,9 @@
// ===========================================================================
// Copyright 2025 Gennaro Prota.
// 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
@@ -42,22 +46,12 @@ an unsigned long `n`, the bit at position `i` of the bitset has the same value
as `(n >> i) & 1`.
== Rationale
`dynamic_bitset` is not a <a
Because of the proxy reference type, `dynamic_bitset` is not a <a
href="https://en.cppreference.com/w/cpp/named_req/Container.html">Container</a>
and does not provide iterators for the following reason:
A container with a proxy reference type can not fulfill the container
requirements as specified in the C++ standard (unless one resorts to strange
iterator semantics). `std::vector<bool>` has a proxy reference type and does not
fulfill the container requirements and as a result has caused many problems. One
common problem is when people try to use iterators from `std::vector<bool>` with
a standard algorithm such as `std::search()`. The `std::search()` requirements
say that the iterator must be a LegacyForwardIterator, but
`std::vector<bool>::iterator` does not meet this requirement because of the
proxy reference. Depending on the implementation, they may or not be a compile
error or even a run-time error due to this misuse. For further discussion of the
problem see "Effective STL" by Scott Meyers. So `dynamic_bitset` tries to avoid
these problems by not pretending to be a 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

View File

@@ -12,15 +12,15 @@ 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'
- 'std'
- 'std::**'
# Why does MrDocs pick up ::size_t?
- 'size_t'
- 'boost::dynamic_bitset::buffer_type'
file-patterns:
- '*.hpp'
multipage: false
multipage: true
generator: adoc

View File

@@ -56,4 +56,12 @@ make_non_const( T t )
#endif
#if ! defined( BOOST_NO_CXX11_HDR_FUNCTIONAL ) && ! defined( BOOST_DYNAMIC_BITSET_NO_STD_HASH )
# define BOOST_DYNAMIC_BITSET_SPECIALIZE_STD_HASH
#endif
#if ( defined( _MSVC_LANG ) && _MSVC_LANG >= 201703L ) || __cplusplus >= 201703L
# define BOOST_DYNAMIC_BITSET_USE_CPP17_OR_LATER
#endif
#endif // include guard

View File

@@ -1,7 +1,7 @@
// -----------------------------------------------------------
//
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
// Copyright (c) 2003-2006, 2008, 2025 Gennaro Prota
// Copyright (c) 2014 Glen Joseph Fernandes
// (glenjofe@gmail.com)
// Copyright (c) 2018 Evgeny Shulgin
@@ -17,15 +17,64 @@
#define BOOST_DETAIL_DYNAMIC_BITSET_HPP
#include "boost/config.hpp"
#include "boost/core/allocator_access.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, typename Block, bool IsContainer >
class allocator_type_extractor_impl;
template< typename AllocatorOrContainer, typename Block >
class allocator_type_extractor_impl< AllocatorOrContainer, Block, false >
{
public:
typedef AllocatorOrContainer type;
};
template< typename AllocatorOrContainer, typename Block >
class allocator_type_extractor_impl< AllocatorOrContainer, Block, 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,
Block,
is_container< AllocatorOrContainer, Block >::value
>::type type;
};
template< typename T, int amount, int width /* = default */ >
struct shifter
{
@@ -51,16 +100,16 @@ struct value_to_type
// meaningful info.
//
template< typename T >
inline typename T::size_type
typename T::size_type
vector_max_size_workaround( const T & v )
BOOST_NOEXCEPT
noexcept
{
typedef typename T::allocator_type allocator_type;
const allocator_type & alloc = v.get_allocator();
typename boost::allocator_size_type< allocator_type >::type alloc_max =
boost::allocator_max_size( alloc );
typename std::allocator_traits< allocator_type >::size_type alloc_max =
std::allocator_traits< allocator_type >::max_size( alloc );
const typename T::size_type container_max = v.max_size();
return alloc_max < container_max ? alloc_max : container_max;
@@ -112,9 +161,9 @@ BOOST_dynamic_bitset_is_numeric( wchar_t );
#endif
BOOST_dynamic_bitset_is_numeric( signed char );
BOOST_dynamic_bitset_is_numeric( short int );
BOOST_dynamic_bitset_is_numeric( short );
BOOST_dynamic_bitset_is_numeric( int );
BOOST_dynamic_bitset_is_numeric( long int );
BOOST_dynamic_bitset_is_numeric( long );
BOOST_dynamic_bitset_is_numeric( unsigned char );
BOOST_dynamic_bitset_is_numeric( unsigned short );

View File

@@ -3,7 +3,7 @@
//
// Position of the lowest bit that is set.
//
// Copyright (c) 2003-2004, 2008 Gennaro Prota
// 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
@@ -15,7 +15,8 @@
#define BOOST_LOWEST_BIT_HPP_GP_20030301
#include "boost/assert.hpp"
#include "boost/integer/integer_log2.hpp"
#include "boost/core/bit.hpp"
#include <type_traits>
namespace boost {
namespace detail {
@@ -26,10 +27,7 @@ lowest_bit( T x )
{
BOOST_ASSERT( x >= 1 );
// Clear all the bits that are set except the rightmost one,
// then calculate the logarithm to base 2.
//
return boost::integer_log2< T >( x - ( x & ( x - 1 ) ) );
return boost::core::countr_zero( static_cast< typename std::make_unsigned< T >::type >( x ) );
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -16,7 +16,7 @@
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;
}

View File

@@ -1,6 +1,6 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
// Copyright (c) 2003-2006, 2008, 2025 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2014 Riccardo Marcangelo
// Copyright (c) 2018 Evgeny Shulgin
@@ -15,6 +15,7 @@
#define BOOST_BITSET_TEST_HPP_GP_20040319
#include "boost/config.hpp"
#include "boost/container/small_vector.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/filesystem.hpp"
@@ -28,8 +29,12 @@
# include <locale>
#endif
template< typename T >
using small_vector = boost::container::small_vector< T, 8 >;
template< typename Block >
inline bool
bool
nth_bit( Block num, std::size_t n )
{
#ifndef NDEBUG
@@ -129,7 +134,7 @@ template< typename Bitset >
struct bitset_test
{
typedef typename Bitset::block_type Block;
BOOST_STATIC_CONSTANT( int, bits_per_block = Bitset::bits_per_block );
static constexpr int bits_per_block = Bitset::bits_per_block;
// from unsigned long
//
@@ -203,6 +208,55 @@ struct bitset_test
// If M < N, remaining bit positions are zero
for ( ; j < actual_size; ++j )
BOOST_TEST( b[ j ] == 0 );
#if defined( BOOST_DYNAMIC_BITSET_USE_CPP17_OR_LATER )
BOOST_TEST( Bitset( std::basic_string_view< Ch, Tr >( str ).substr( pos, rlen ), num_bits ) == b );
#endif
}
static void
iterate_forward( const Bitset & b )
{
std::ptrdiff_t i = 0;
for ( auto it = b.begin(); it != b.end(); ++it ) {
BOOST_TEST( *it == b[ i ] );
++i;
}
}
static void
iterate_backward( const Bitset & b )
{
std::ptrdiff_t i = static_cast< std::ptrdiff_t >( b.size() ) - 1;
for ( auto it = b.rbegin(); it != b.rend(); ++it ) {
BOOST_TEST( *it == b[ i ] );
--i;
}
}
static void
iterator_operations( const Bitset & b )
{
if ( b.size() >= 1 ) {
BOOST_TEST( *( b.end() - 1 ) == b[ b.size() - 1 ] );
BOOST_TEST( b.begin() < b.end() );
BOOST_TEST( b.begin() <= b.end() );
BOOST_TEST( b.end() > b.begin() );
BOOST_TEST( b.end() >= b.begin() );
typename Bitset::const_iterator it = b.begin();
it += b.size() / 2;
BOOST_TEST( *it == b[ b.size() / 2 ] );
it -= b.size() / 2;
BOOST_TEST( *it == b[ 0 ] );
} else {
BOOST_TEST( b.begin() == b.end() );
}
if ( b.size() > 1 ) {
BOOST_TEST( *( b.begin() + 1 ) == b[ 1 ] );
BOOST_TEST( *( 1 + b.begin() ) == b[ 1 ] );
BOOST_TEST( *( b.end() - 1 ) == b[ b.size() - 1 ] );
}
}
static void
@@ -300,16 +354,17 @@ struct bitset_test
max_size( const Bitset & b )
{
BOOST_TEST( b.max_size() > 0 );
BOOST_TEST( b.max_size() >= b.size() );
BOOST_TEST( b.max_size() / Bitset::bits_per_block <= std::allocator_traits< typename Bitset::allocator_type >::max_size( b.get_allocator() ) );
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
// move constructor (absent from std::bitset)
static void
move_constructor( const Bitset & b )
{
Bitset copy( boost::move( b ) );
BOOST_TEST( b == copy );
Bitset copy( b );
Bitset b2( std::move( copy ) );
BOOST_TEST( b2 == b );
}
// move assignment operator (absent from std::bitset)
@@ -318,13 +373,11 @@ struct bitset_test
{
Bitset b( lhs );
Bitset c( rhs );
b = boost::move( c );
b = boost::move( b ); // self assignment check
b = std::move( c );
b = std::move( b ); // self assignment check
BOOST_TEST( b == rhs );
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
static void
swap( const Bitset & lhs, const Bitset & rhs )
{
@@ -347,8 +400,11 @@ struct bitset_test
b1.swap( b2 );
BOOST_TEST( b2[ i ] == x ); // now it must be equal..
b2.flip( i );
BOOST_TEST( ref == b2[ i ] ); // .. and ref must be into b2
BOOST_TEST( ref == ! x );
// Since we transformed the Allocator parameter into
// AllocatorOrContainer, the following is no longer true (think e.g.
// of boost::container::small_vector).
// BOOST_TEST( ref == b2[ i ] ); // .. and ref must be into b2
// BOOST_TEST( ref == ! x );
}
}
@@ -399,6 +455,21 @@ struct bitset_test
BOOST_TEST( b[ j ] == lhs[ j ] );
}
static void
pop_front( const Bitset & lhs )
{
Bitset b( lhs );
b.pop_front();
BOOST_TEST( b.size() == lhs.size() - 1 );
for ( std::size_t i = 0; i < b.size(); ++i )
BOOST_TEST( b[ i ] == lhs[ i + 1 ] );
b.pop_front();
BOOST_TEST( b.size() == lhs.size() - 2 );
for ( std::size_t j = 0; j < b.size(); ++j )
BOOST_TEST( b[ j ] == lhs[ j + 2 ] );
}
static void
append_bit( const Bitset & lhs )
{
@@ -417,6 +488,23 @@ struct bitset_test
BOOST_TEST( b[ j ] == lhs[ j ] );
}
static void
prepend_bit( const Bitset & lhs )
{
Bitset b( lhs );
b.push_front( true );
BOOST_TEST( b.size() == lhs.size() + 1 );
BOOST_TEST( b[ 0 ] == true );
for ( std::size_t i = 0; i < lhs.size(); ++i )
BOOST_TEST( b[ i + 1 ] == lhs[ i ] );
b.push_front( false );
BOOST_TEST( b.size() == lhs.size() + 2 );
BOOST_TEST( b[ 0 ] == false );
BOOST_TEST( b[ 1 ] == true );
for ( std::size_t j = 0; j < lhs.size(); ++j )
BOOST_TEST( b[ j + 2 ] == lhs[ j ] );
}
static void
append_block( const Bitset & lhs )
{
@@ -817,19 +905,9 @@ struct bitset_test
}
static void
capacity_test_one( const Bitset & lhs )
capacity( const Bitset & lhs )
{
// empty bitset
Bitset b( lhs );
BOOST_TEST( b.capacity() == 0 );
}
static void
capacity_test_two( const Bitset & lhs )
{
// bitset constructed with size "100"
Bitset b( lhs );
BOOST_TEST( b.capacity() >= 100 );
b.resize( 200 );
BOOST_TEST( b.capacity() >= 200 );
}
@@ -864,7 +942,7 @@ struct bitset_test
Bitset b( lhs );
b.shrink_to_fit();
BOOST_TEST( b.size() == 0 );
BOOST_TEST( b.capacity() == 0 );
BOOST_TEST( b.capacity() == Bitset().capacity() );
}
static void
@@ -875,11 +953,11 @@ struct bitset_test
b.shrink_to_fit();
BOOST_TEST( b.capacity() >= 100 );
BOOST_TEST( b.size() == 100 );
b.reserve( 200 );
BOOST_TEST( b.capacity() >= 200 );
b.reserve( 550 );
BOOST_TEST( b.capacity() >= 550 );
BOOST_TEST( b.size() == 100 );
b.shrink_to_fit();
BOOST_TEST( b.capacity() < 200 );
BOOST_TEST( b.capacity() < 550 );
BOOST_TEST( b.size() == 100 );
}
@@ -994,26 +1072,34 @@ struct bitset_test
}
static void
find_first( const Bitset & b, typename Bitset::size_type offset = 0 )
find_first( const Bitset & b, typename Bitset::size_type offset = 0, bool value = true )
{
// find first non-null bit from offset onwards, if any
const typename Bitset::size_type result = value
? b.find_first( offset )
: b.find_first_off( offset );
// find first bit with value `value` from offset onwards, if any
typename Bitset::size_type i = offset;
while ( i < b.size() && b[ i ] == 0 )
while ( i < b.size() && b[ i ] != value )
++i;
if ( i >= b.size() )
BOOST_TEST( b.find_first( offset ) == Bitset::npos ); // not found;
BOOST_TEST( result == Bitset::npos ); // not found;
else {
BOOST_TEST( b.find_first( offset ) == i );
BOOST_TEST( b.test( i ) == true );
BOOST_TEST( result == i );
BOOST_TEST( b.test( i ) == value );
}
}
static void
find_pos( const Bitset & b, typename Bitset::size_type pos )
find_pos( const Bitset & b, typename Bitset::size_type pos, bool value = true )
{
find_first( b, pos );
BOOST_TEST( next_bit_on( b, pos ) == b.find_next( pos ) );
find_first( b, pos, value);
if ( value ) {
BOOST_TEST( next_bit_on( b, pos ) == b.find_next( pos ) );
} else {
BOOST_TEST( next_bit_off( b, pos ) == b.find_next_off( pos ) );
}
}
static void
@@ -1106,6 +1192,32 @@ struct bitset_test
return i == b.size() ? Bitset::npos : i;
}
static typename Bitset::size_type
next_bit_off( const Bitset & b, typename Bitset::size_type prev )
{
// helper function for find_pos()
//
if ( b.all() || prev == Bitset::npos ) {
return Bitset::npos;
}
++prev;
if ( prev >= b.size() ) {
return Bitset::npos;
}
typename Bitset::size_type i = prev;
while ( i < b.size() && b[ i ] ) {
++i;
}
return i == b.size()
? Bitset::npos
: i;
}
static void
operator_less_than( const Bitset & a, const Bitset & b )
{

View File

@@ -1,6 +1,6 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// Copyright (c) 2003-2006, 2025 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2014 Riccardo Marcangelo
//
@@ -15,7 +15,6 @@
#include "bitset_test.hpp"
#include "boost/config.hpp"
#include "boost/config/workaround.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/limits.hpp"
@@ -57,15 +56,9 @@ public:
#define BOOST_BITSET_TEST_COUNT( x ) ( sizeof( x ) / sizeof( x[ 0 ] ) )
// Codewarrior 8.3 for Win fails without this.
// Thanks Howard Hinnant ;)
#if defined __MWERKS__ && 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 ) )
run_string_tests( const String & s )
{
const std::size_t len = s.length();
const std::size_t step = len / 4 ? len / 4 : 1;
@@ -91,8 +84,7 @@ run_string_tests( const String & s BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE( Tests )
// tests the do-the-right-thing constructor dispatch
template< typename Tests, typename T >
void
run_numeric_ctor_tests( BOOST_EXPLICIT_TEMPLATE_TYPE( Tests )
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE( T ) )
run_numeric_ctor_tests()
{
const int bits_per_block = Tests::bits_per_block;
const int width = std::numeric_limits< T >::digits;
@@ -132,11 +124,12 @@ run_numeric_ctor_tests( BOOST_EXPLICIT_TEMPLATE_TYPE( Tests )
}
}
template< typename Block >
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
run_test_cases()
{
typedef boost::dynamic_bitset< Block > bitset_type;
typedef boost::dynamic_bitset< Block, AllocatorOrContainer >
bitset_type;
typedef bitset_test< bitset_type > Tests;
const int bits_per_block = bitset_type::bits_per_block;
@@ -232,6 +225,34 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
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
{
@@ -250,15 +271,15 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test copy constructor
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::copy_constructor( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( "0" );
Tests::copy_constructor( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b ( long_string );
Tests::copy_constructor( b );
}
//=====================================================================
@@ -268,7 +289,7 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
Tests::copy_assignment_operator( a, b );
}
{
bitset_type a( std::string( "1" ) ), b( std::string( "0" ) );
bitset_type a( "1" ), b( "0" );
Tests::copy_assignment_operator( a, b );
}
{
@@ -281,24 +302,23 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
Tests::copy_assignment_operator( a, b );
}
{
bitset_type a( std::string( "0" ) );
bitset_type a( "0" );
bitset_type b( long_string ); // b greater than a
Tests::copy_assignment_operator( a, b );
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
//=====================================================================
// Test move constructor
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::move_constructor( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( "0" );
Tests::move_constructor( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::move_constructor( b );
}
//=====================================================================
@@ -308,7 +328,7 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
Tests::move_assignment_operator( a, b );
}
{
bitset_type a( std::string( "1" ) ), b( std::string( "0" ) );
bitset_type a( "1" ), b( "0" );
Tests::move_assignment_operator( a, b );
}
{
@@ -321,16 +341,15 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
Tests::move_assignment_operator( a, b );
}
{
bitset_type a( std::string( "0" ) );
bitset_type a( "0" );
bitset_type b( long_string ); // b greater than a
Tests::move_assignment_operator( a, b );
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
//=====================================================================
// Test swap
{
bitset_type a;
bitset_type b( std::string( "1" ) );
bitset_type b( "1" );
Tests::swap( a, b );
Tests::swap( b, a );
Tests::swap( a, a );
@@ -342,7 +361,7 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
Tests::swap( b, a );
}
{
bitset_type a( std::string( "0" ) );
bitset_type a( "0" );
bitset_type b( long_string );
Tests::swap( a, b );
Tests::swap( b, a );
@@ -352,121 +371,163 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test resize
{
boost::dynamic_bitset< Block > a;
bitset_type a;
Tests::resize( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) );
bitset_type a( "0" );
Tests::resize( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) );
bitset_type a( "1" );
Tests::resize( a );
}
{
boost::dynamic_bitset< Block > a( long_string );
bitset_type a( long_string );
Tests::resize( a );
}
//=====================================================================
// Test clear
{
boost::dynamic_bitset< Block > a;
bitset_type a;
Tests::clear( a );
}
{
boost::dynamic_bitset< Block > a( long_string );
bitset_type a( long_string );
Tests::clear( a );
}
//=====================================================================
// Test pop back
{
boost::dynamic_bitset< Block > a( std::string( "01" ) );
bitset_type a( "01" );
Tests::pop_back( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "10" ) );
bitset_type a( "10" );
Tests::pop_back( a );
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
boost::dynamic_bitset< Block > a( size_to_fill_all_blocks, 255ul );
const int size_to_fill_all_blocks = 4 * bits_per_block;
bitset_type a( size_to_fill_all_blocks, 255ul );
Tests::pop_back( a );
}
{
boost::dynamic_bitset< Block > a( long_string );
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
{
boost::dynamic_bitset< Block > a;
bitset_type a;
Tests::append_bit( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) );
bitset_type a( "0" );
Tests::append_bit( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) );
bitset_type a( "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 );
const int size_to_fill_all_blocks = 4 * bits_per_block;
bitset_type a( size_to_fill_all_blocks, 255ul );
Tests::append_bit( a );
}
{
boost::dynamic_bitset< Block > a( long_string );
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
{
boost::dynamic_bitset< Block > a;
bitset_type a;
Tests::append_block( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) );
bitset_type a( "0" );
Tests::append_block( a );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) );
bitset_type a( "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 );
const int size_to_fill_all_blocks = 4 * bits_per_block;
bitset_type a( size_to_fill_all_blocks, 15ul );
Tests::append_block( a );
}
{
boost::dynamic_bitset< Block > a( long_string );
bitset_type a( long_string.c_str() );
Tests::append_block( a );
}
//=====================================================================
// Test append block range
{
boost::dynamic_bitset< Block > a;
std::vector< Block > blocks;
bitset_type a;
std::vector< Block > blocks;
Tests::append_block_range( a, blocks );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) );
std::vector< Block > blocks( 3 );
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 );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) );
const unsigned int n = ( std::numeric_limits< unsigned char >::max )();
std::vector< Block > blocks( n );
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 );
}
{
boost::dynamic_bitset< Block > a;
bitset_type a;
a.append( Block( 1 ) );
a.append( Block( 2 ) );
Block x[] = { 3, 4, 5 };
@@ -475,8 +536,8 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
Tests::append_block_range( a, blocks );
}
{
boost::dynamic_bitset< Block > a( long_string );
std::vector< Block > blocks( 3 );
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;
@@ -485,19 +546,19 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test bracket operator
{
boost::dynamic_bitset< Block > b1;
std::vector< bool > bitvec1;
bitset_type 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 );
bitset_type b( "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 );
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 );
@@ -505,23 +566,25 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test at
{
boost::dynamic_bitset< Block > b1;
std::vector< bool > bitvec1;
bitset_type b1;
std::vector< bool > bitvec1;
Tests::at( b1, bitvec1 );
}
{
boost::dynamic_bitset< Block > b( std::string( "1" ) );
std::vector< bool > bit_vec( 1, true );
bitset_type b( "1" );
std::vector< bool > bit_vec( 1, true );
Tests::at( b, bit_vec );
}
{
boost::dynamic_bitset< Block > b( long_string );
std::size_t n = long_string.size();
std::vector< bool > bit_vec( n );
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;
@@ -531,7 +594,7 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
#endif
// Test copy-initialize with default constructor
{
boost::dynamic_bitset< Block > b[ 1 ] = {};
bitset_type b[ 1 ] = {};
(void)b;
}
}
@@ -540,11 +603,16 @@ 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 > >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type >();
run_test_cases< ::boost::ulong_long_type, small_vector< ::boost::ulong_long_type > >();
#endif
return boost::report_errors();

View File

@@ -1,6 +1,6 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// Copyright (c) 2003-2006, 2025 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2018 Evgeny Shulgin
//
@@ -14,11 +14,11 @@
#include "boost/config.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
template< typename Block >
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
run_test_cases()
{
typedef boost::dynamic_bitset< Block > bitset_type;
typedef boost::dynamic_bitset< Block, AllocatorOrContainer > bitset_type;
typedef bitset_test< bitset_type > Tests;
const int bits_per_block = bitset_type::bits_per_block;
@@ -27,73 +27,73 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test operator&=
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::and_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type 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 );
bitset_type 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 );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::and_assignment( lhs, rhs );
}
//=====================================================================
// Test operator |=
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::or_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type 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 );
bitset_type 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 );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::or_assignment( lhs, rhs );
}
//=====================================================================
// Test operator^=
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::xor_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type 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" ) );
bitset_type lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
Tests::xor_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string ), rhs( long_string );
bitset_type lhs( long_string ), rhs( long_string );
Tests::xor_assignment( lhs, rhs );
}
//=====================================================================
// Test operator-=
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::sub_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type 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" ) );
bitset_type lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
Tests::sub_assignment( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( long_string ), rhs( long_string );
bitset_type lhs( long_string ), rhs( long_string );
Tests::sub_assignment( lhs, rhs );
}
//=====================================================================
@@ -101,15 +101,15 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{ // case pos == 0
std::size_t pos = 0;
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::shift_left_assignment( b, pos );
}
{
boost::dynamic_bitset< Block > b( std::string( "1010" ) );
bitset_type b( std::string( "1010" ) );
Tests::shift_left_assignment( b, pos );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::shift_left_assignment( b, pos );
}
}
@@ -120,7 +120,7 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
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 );
bitset_type b( long_string );
Tests::shift_left_assignment( b, multiple );
Tests::shift_left_assignment( b, non_multiple );
@@ -128,12 +128,12 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset< Block > b( long_string );
bitset_type 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 );
bitset_type b( long_string );
Tests::shift_left_assignment( b, pos );
}
//=====================================================================
@@ -141,15 +141,15 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
{ // case pos == 0
std::size_t pos = 0;
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::shift_right_assignment( b, pos );
}
{
boost::dynamic_bitset< Block > b( std::string( "1010" ) );
bitset_type b( std::string( "1010" ) );
Tests::shift_right_assignment( b, pos );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::shift_right_assignment( b, pos );
}
}
@@ -160,7 +160,7 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
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 );
bitset_type b( long_string );
Tests::shift_right_assignment( b, multiple );
Tests::shift_right_assignment( b, non_multiple );
@@ -168,197 +168,197 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
}
{ // case pos == size()/2
std::size_t pos = long_string.size() / 2;
boost::dynamic_bitset< Block > b( long_string );
bitset_type 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 );
bitset_type b( long_string );
Tests::shift_right_assignment( b, pos );
}
//=====================================================================
// test b.set()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::set_all( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::set_all( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::set_all( b );
}
//=====================================================================
// Test b.set(pos)
{ // case pos >= b.size()
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::set_one( b, 0, true );
Tests::set_one( b, 0, false );
}
{ // case pos < b.size()
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::set_one( b, 0, true );
Tests::set_one( b, 0, false );
}
{ // case pos == b.size() / 2
boost::dynamic_bitset< Block > b( long_string );
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 1
boost::dynamic_bitset< Block > b( std::string( "0" ) );
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
boost::dynamic_bitset< Block > b( long_string );
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
boost::dynamic_bitset< Block > b( long_string );
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
boost::dynamic_bitset< Block > b( long_string );
Tests::set_segment( b, boost::dynamic_bitset< Block >::bits_per_block / 2, b.size() - boost::dynamic_bitset< Block >::bits_per_block, true );
Tests::set_segment( b, boost::dynamic_bitset< Block >::bits_per_block / 2, b.size() - boost::dynamic_bitset< Block >::bits_per_block, false );
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
boost::dynamic_bitset< Block > b( long_string );
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
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::set_segment( b, 3, 7, true );
Tests::set_segment( b, 3, 7, false );
}
//=====================================================================
// Test b.reset()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::reset_all( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::reset_all( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_all( b );
}
//=====================================================================
// Test b.reset(pos)
{ // case pos >= b.size()
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::reset_one( b, 0 );
}
{ // case pos < b.size()
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::reset_one( b, 0 );
}
{ // case pos == b.size() / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_one( b, long_string.size() / 2 );
}
//=====================================================================
// Test b.reset(pos, len)
{ // case size is 1
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::reset_segment( b, 0, 1 );
}
{ // case fill the whole set
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_segment( b, 0, b.size() );
}
{ // case pos = size / 4, len = size / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_segment( b, b.size() / 4, b.size() / 2 );
}
{ // case pos = block_size / 2, len = size - block_size
boost::dynamic_bitset< Block > b( long_string );
Tests::reset_segment( b, boost::dynamic_bitset< Block >::bits_per_block / 2, b.size() - boost::dynamic_bitset< Block >::bits_per_block );
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
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_segment( b, 1, b.size() - 2 );
}
{ // case pos = 3, len = 7
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::reset_segment( b, 3, 7 );
}
//=====================================================================
// Test ~b
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::operator_flip( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "1" ) );
bitset_type b( std::string( "1" ) );
Tests::operator_flip( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::operator_flip( b );
}
//=====================================================================
// Test b.flip()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::flip_all( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "1" ) );
bitset_type b( std::string( "1" ) );
Tests::flip_all( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_all( b );
}
//=====================================================================
// Test b.flip(pos)
{ // case pos >= b.size()
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::flip_one( b, 0 );
}
{ // case pos < b.size()
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::flip_one( b, 0 );
}
{ // case pos == b.size() / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_one( b, long_string.size() / 2 );
}
//=====================================================================
// Test b.flip(pos, len)
{ // case size is 1
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::flip_segment( b, 0, 1 );
}
{ // case fill the whole set
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_segment( b, 0, b.size() );
}
{ // case pos = size / 4, len = size / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_segment( b, b.size() / 4, b.size() / 2 );
}
{ // case pos = block_size / 2, len = size - block_size
boost::dynamic_bitset< Block > b( long_string );
Tests::flip_segment( b, boost::dynamic_bitset< Block >::bits_per_block / 2, b.size() - boost::dynamic_bitset< Block >::bits_per_block );
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
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_segment( b, 1, b.size() - 2 );
}
{ // case pos = 3, len = 7
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::flip_segment( b, 3, 7 );
}
}
@@ -367,11 +367,16 @@ 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 > >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type >();
run_test_cases< ::boost::ulong_long_type, small_vector< ::boost::ulong_long_type > >();
#endif
return boost::report_errors();

View File

@@ -1,6 +1,6 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// Copyright (c) 2003-2006, 2025 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2014 Riccardo Marcangelo
//
@@ -16,12 +16,12 @@
#include "boost/limits.hpp"
#include <assert.h>
template< typename Block >
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
run_test_cases()
{
// a bunch of typedefs which will be handy later on
typedef boost::dynamic_bitset< Block > bitset_type;
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
@@ -45,129 +45,129 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test b.to_long()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::to_ulong( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "1" ) );
bitset_type b( std::string( "1" ) );
Tests::to_ulong( b );
}
{
boost::dynamic_bitset< Block > b( bitset_type::bits_per_block, static_cast< unsigned long >( -1 ) );
bitset_type b( bitset_type::bits_per_block, static_cast< unsigned long >( -1 ) );
Tests::to_ulong( b );
}
{
std::string str( ul_width - 1, '1' );
boost::dynamic_bitset< Block > b( str );
bitset_type b( str );
Tests::to_ulong( b );
}
{
std::string ul_str( ul_width, '1' );
boost::dynamic_bitset< Block > b( ul_str );
bitset_type b( ul_str );
Tests::to_ulong( b );
}
{ // case overflow
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::to_ulong( b );
}
//=====================================================================
// Test to_string(b, str)
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::to_string( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::to_string( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::to_string( b );
}
//=====================================================================
// Test b.count()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::count( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::count( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "1" ) );
bitset_type b( std::string( "1" ) );
Tests::count( b );
}
{
boost::dynamic_bitset< Block > b( 8, 255ul );
bitset_type b( 8, 255ul );
Tests::count( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::count( b );
}
//=====================================================================
// Test b.size()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::size( b );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::size( b );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::size( b );
}
//=====================================================================
// Test b.capacity()
{
boost::dynamic_bitset< Block > b;
Tests::capacity_test_one( b );
bitset_type b;
Tests::capacity( b );
}
{
boost::dynamic_bitset< Block > b( 100 );
Tests::capacity_test_two( b );
bitset_type b( 100 );
Tests::capacity( b );
}
//=====================================================================
// Test b.reserve()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::reserve_test_one( b );
}
{
boost::dynamic_bitset< Block > b( 100 );
bitset_type b( 100 );
Tests::reserve_test_two( b );
}
//=====================================================================
// Test b.shrink_to_fit()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::shrink_to_fit_test_one( b );
}
{
boost::dynamic_bitset< Block > b( 100 );
bitset_type b( 100 );
Tests::shrink_to_fit_test_two( b );
}
//=====================================================================
// Test b.all()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::all( b );
Tests::all( ~b );
Tests::all( b.set() );
Tests::all( b.reset() );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::all( b );
Tests::all( ~b );
Tests::all( b.set() );
Tests::all( b.reset() );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::all( b );
Tests::all( ~b );
Tests::all( b.set() );
@@ -176,21 +176,21 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test b.any()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::any( b );
Tests::any( ~b );
Tests::any( b.set() );
Tests::any( b.reset() );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::any( b );
Tests::any( ~b );
Tests::any( b.set() );
Tests::any( b.reset() );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::any( b );
Tests::any( ~b );
Tests::any( b.set() );
@@ -199,21 +199,21 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test b.none()
{
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::none( b );
Tests::none( ~b );
Tests::none( b.set() );
Tests::none( b.reset() );
}
{
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::none( b );
Tests::none( ~b );
Tests::none( b.set() );
Tests::none( b.reset() );
}
{
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::none( b );
Tests::none( ~b );
Tests::none( b.set() );
@@ -222,56 +222,56 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
//=====================================================================
// Test a.is_subset_of(b)
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::subset( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
Tests::subset( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "1" ) ), b( std::string( "1" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::subset( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::subset( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type 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 );
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)
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::proper_subset( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type 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" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::proper_subset( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::proper_subset( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type 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 );
bitset_type a( long_string ), b( long_string );
b[ long_string.size() / 2 ].flip();
Tests::proper_subset( a, b );
}
@@ -305,30 +305,35 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
// 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
// first bit on or off
bitset_type b( 1, 1ul );
Tests::find_first( b );
Tests::find_first( b, 0, false );
}
{
// last bit on
// 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 );
Tests::find_first( b, 0, false );
}
//=====================================================================
// Test find_next and offset find_first
// Test find_next, find_next_off, offset find_first and offset find_first_off
{
// empty bitset
bitset_type b;
@@ -338,6 +343,10 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
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)
@@ -348,6 +357,10 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
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
@@ -358,8 +371,10 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
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
@@ -378,8 +393,10 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
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
@@ -395,294 +412,296 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
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==
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::operator_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type 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" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::operator_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type 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 );
bitset_type 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;
bitset_type a, b;
Tests::operator_not_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type 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" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_not_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::operator_not_equal( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type 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 );
bitset_type 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;
bitset_type a, b;
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type 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" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "10" ) ), b( std::string( "11" ) );
bitset_type a( std::string( "10" ) ), b( std::string( "11" ) );
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "101" ) ), b( std::string( "11" ) );
bitset_type a( std::string( "101" ) ), b( std::string( "11" ) );
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "10" ) ), b( std::string( "111" ) );
bitset_type a( std::string( "10" ) ), b( std::string( "111" ) );
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::operator_less_than( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type 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 );
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
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 5ul );
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( a < b );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 4ul );
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( ! ( a < b ) );
}
{
boost::dynamic_bitset< Block > a( 3, 5ul ), b( 3, 4ul );
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
{
boost::dynamic_bitset< Block > a( 4, 4ul ), b( 3, 5ul );
bitset_type a( 4, 4ul ), b( 3, 5ul );
BOOST_TEST( a < b );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 4, 5ul );
bitset_type a( 3, 4ul ), b( 4, 5ul );
BOOST_TEST( ! ( a < b ) );
}
{
boost::dynamic_bitset< Block > a( 4, 4ul ), b( 3, 4ul );
bitset_type a( 4, 4ul ), b( 3, 4ul );
BOOST_TEST( a < b );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 4, 4ul );
bitset_type a( 3, 4ul ), b( 4, 4ul );
BOOST_TEST( ! ( a < b ) );
}
{
boost::dynamic_bitset< Block > a( 4, 5ul ), b( 3, 4ul );
bitset_type a( 4, 5ul ), b( 3, 4ul );
BOOST_TEST( a < b );
}
{
boost::dynamic_bitset< Block > a( 3, 5ul ), b( 4, 4ul );
bitset_type a( 3, 5ul ), b( 4, 4ul );
BOOST_TEST( ! ( a < b ) );
}
//=====================================================================
// Test operator<=
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::operator_less_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type 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" ) );
bitset_type 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 );
bitset_type a( long_string ), b( long_string );
Tests::operator_less_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type 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 );
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
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 5ul );
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( a <= b );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 4ul );
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( a <= b );
}
{
boost::dynamic_bitset< Block > a( 3, 5ul ), b( 3, 4ul );
bitset_type a( 3, 5ul ), b( 3, 4ul );
BOOST_TEST( ! ( a <= b ) );
}
//=====================================================================
// Test operator>
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::operator_greater_than( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type 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" ) );
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
Tests::operator_greater_than( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type a( long_string ), b( long_string );
Tests::operator_greater_than( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type 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 );
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
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 5ul );
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( ! ( a > b ) );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 4ul );
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( ! ( a > b ) );
}
{
boost::dynamic_bitset< Block > a( 3, 5ul ), b( 3, 4ul );
bitset_type a( 3, 5ul ), b( 3, 4ul );
BOOST_TEST( a > b );
}
//=====================================================================
// Test operator<=
{
boost::dynamic_bitset< Block > a, b;
bitset_type a, b;
Tests::operator_greater_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( std::string( "0" ) ), b( std::string( "0" ) );
bitset_type 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" ) );
bitset_type 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 );
bitset_type a( long_string ), b( long_string );
Tests::operator_greater_than_eq( a, b );
}
{
boost::dynamic_bitset< Block > a( long_string ), b( long_string );
bitset_type 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 );
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
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 5ul );
bitset_type a( 3, 4ul ), b( 3, 5ul );
BOOST_TEST( ! ( a >= b ) );
}
{
boost::dynamic_bitset< Block > a( 3, 4ul ), b( 3, 4ul );
bitset_type a( 3, 4ul ), b( 3, 4ul );
BOOST_TEST( a >= b );
}
{
boost::dynamic_bitset< Block > a( 3, 5ul ), b( 3, 4ul );
bitset_type a( 3, 5ul ), b( 3, 4ul );
BOOST_TEST( a >= b );
}
//=====================================================================
// Test b.test(pos)
{ // case pos >= b.size()
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::test_bit( b, 0 );
}
{ // case pos < b.size()
boost::dynamic_bitset< Block > b( std::string( "0" ) );
bitset_type b( std::string( "0" ) );
Tests::test_bit( b, 0 );
}
{ // case pos == b.size() / 2
boost::dynamic_bitset< Block > b( long_string );
bitset_type b( long_string );
Tests::test_bit( b, long_string.size() / 2 );
}
//=====================================================================
// Test b.test_set(pos)
{ // case pos >= b.size()
boost::dynamic_bitset< Block > b;
bitset_type b;
Tests::test_set_bit( b, 0, true );
Tests::test_set_bit( b, 0, false );
}
{ // case pos < b.size()
boost::dynamic_bitset< Block > b( std::string( "0" ) );
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
boost::dynamic_bitset< Block > b( long_string );
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 );
}
@@ -690,106 +709,106 @@ run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
// Test b << pos
{ // case pos == 0
std::size_t pos = 0;
boost::dynamic_bitset< Block > b( std::string( "1010" ) );
bitset_type 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 );
bitset_type 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 );
bitset_type 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" ) );
bitset_type 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 );
bitset_type 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 );
bitset_type b( long_string );
Tests::operator_shift_right( b, pos );
}
//=====================================================================
// Test a & b
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::operator_and( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type 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 );
bitset_type 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 );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_and( lhs, rhs );
}
//=====================================================================
// Test a | b
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::operator_or( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type 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 );
bitset_type 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 );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_or( lhs, rhs );
}
//=====================================================================
// Test a^b
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::operator_xor( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type 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 );
bitset_type 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 );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_xor( lhs, rhs );
}
//=====================================================================
// Test a-b
{
boost::dynamic_bitset< Block > lhs, rhs;
bitset_type lhs, rhs;
Tests::operator_sub( lhs, rhs );
}
{
boost::dynamic_bitset< Block > lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
bitset_type 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 );
bitset_type 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 );
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
Tests::operator_sub( lhs, rhs );
}
}
@@ -798,11 +817,16 @@ 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 > >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type >();
run_test_cases< ::boost::ulong_long_type, small_vector< ::boost::ulong_long_type > >();
#endif
return boost::report_errors();

View File

@@ -1,6 +1,6 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// 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
@@ -45,11 +45,11 @@ widen_string( const std::string & str, const std::locale & loc = std::locale() )
}
#endif
template< typename Block >
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
run_test_cases()
{
typedef boost::dynamic_bitset< Block > bitset_type;
typedef boost::dynamic_bitset< Block, AllocatorOrContainer > bitset_type;
typedef bitset_test< bitset_type > Tests;
//=====================================================================
@@ -300,11 +300,16 @@ 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 > >();
#ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type >();
run_test_cases< ::boost::ulong_long_type, small_vector< ::boost::ulong_long_type > >();
#endif
return boost::report_errors();

View File

@@ -1,6 +1,6 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// Copyright (c) 2003-2006, 2025 Gennaro Prota
//
// Copyright (c) 2015 Seth Heeren
//
@@ -46,7 +46,7 @@ private:
template< typename Block, typename IArchive, typename OArchive >
void
test_serialization( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
test_serialization()
{
SerializableType< Block > a;
@@ -77,14 +77,14 @@ test_serialization( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
template< typename Block >
void
test_binary_archive( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
test_binary_archive()
{
test_serialization< Block, boost::archive::binary_iarchive, boost::archive::binary_oarchive >();
}
template< typename Block >
void
test_xml_archive( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
test_xml_archive()
{
test_serialization< Block, boost::archive::xml_iarchive, boost::archive::xml_oarchive >();
}
@@ -92,7 +92,7 @@ test_xml_archive( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
template< typename Block >
void
run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE( Block ) )
run_test_cases()
{
test_binary_archive< Block >();
test_xml_archive< Block >();

View File

@@ -6,8 +6,7 @@
// http://www.boost.org/LICENSE_1_0.txt)
//
#include "boost/config.hpp"
#include "boost/detail/lightweight_test.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/dynamic_bitset.hpp"
#include <unordered_set>
@@ -18,14 +17,14 @@ main( int, char *[] )
const std::string long_string =
"01001110101110110101011010000000000011110101101111111111";
bitset_type zeroes( long_string.size(), 0 );
bitset_type stuff( long_string );
bitset_type ones( long_string.size(), 1 );
const bitset_type zeroes( long_string.size(), 0 );
const bitset_type stuff( long_string );
const bitset_type one( long_string.size(), 1 );
std::unordered_set< bitset_type > bitsets;
bitsets.insert( zeroes );
bitsets.insert( stuff );
bitsets.insert( ones );
bitsets.insert( one );
BOOST_TEST_EQ( bitsets.size(), 3 );