Compare commits

...

173 Commits

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

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

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

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

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

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

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

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

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

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



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

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

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



[SVN r53050]
2009-05-16 14:58:33 +00:00
Hartmut Kaiser
ed32df5ad2 Minor comment edit
[SVN r52881]
2009-05-10 16:59:27 +00:00
Hartmut Kaiser
da0b582703 Fixing the fix by taking into account __GNUC_PATCHLEVEL__ as well
[SVN r52880]
2009-05-10 16:55:07 +00:00
Hartmut Kaiser
622c8d8fd5 Applying patch fixing problem on certain patch levels for gcc.4.3.3/Ubuntu
[SVN r52879]
2009-05-10 16:52:14 +00:00
Michael A. Jackson
97d2bff3b6 Updating dependency information for modularized libraries.
[SVN r49628]
2008-11-07 17:05:27 +00:00
Michael A. Jackson
a143af6e2f Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use.
[SVN r49627]
2008-11-07 17:02:56 +00:00
Gennaro Prota
59825bc8db dynamic_bitset:
* removed use of BOOST_WORKAROUND in #if for gcc bug c++/8419, as recent
      changes to the implementation of BOOST_WORKAROUND broke its usage with
      arguments such as ( (__GNUC__) * 100 * 100 + (__GNUC_MINOR__) * 100 )


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

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


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

    * comment fixes in detail/dynamic_bitset.hpp


[SVN r49345]
2008-10-15 12:33:37 +00:00
Gennaro Prota
180aa15c44 dynamic_bitset: in reference constructor, assert() before it is (eventually) too late!
[SVN r48730]
2008-09-11 09:46:54 +00:00
Gennaro Prota
7ed46a6667 dynamic_bitset: in dyn_bitset_unit_tests1.cpp, replaced very ill-thought assert() with more sensible code to check for "negative sizes"
[SVN r48729]
2008-09-11 09:35:49 +00:00
Gennaro Prota
24d2081a73 added specific tests for constructor dispatch and clarified the corresponding comments a bit; minor formatting consistency fixes; updated documentation and added license reference text to it
[SVN r48695]
2008-09-10 10:07:46 +00:00
Gennaro Prota
f6ce97de67 dynamic_bitset: added spaces in the definition of BOOST_dynamic_bitset_is_numeric (detail/dynamic_bitset.hpp), to avoid getting an unintended alternative token "<:" when invoking the macro with argument "::boost::[u]long_long_type"
[SVN r48664]
2008-09-08 10:20:49 +00:00
Gennaro Prota
7530a40476 dynamic_bitset: changed a using directive to a set of using declarations, in the hope that this will fix regressions of Intel and others; (very minor) changed comment text
[SVN r48663]
2008-09-08 10:10:02 +00:00
Gennaro Prota
c05a47b50d dynamic_bitset:
* added user-declared default constructor to value_to_type<bool> (yeah, the
      usual "initializing a const instance of an empty class" problem, which
      also affected S. Meyers' null)
    * explicitly qualified occurrence of "bits_per_block" in count() member
      function, to let gcc 3.4.x understand that it *is* a constant expression
    * fixed namespace qualification for vector_max_size_workaround (should've
      been done in the previous commit, sorry)


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

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


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


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

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

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

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


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

113
.appveyor.yml Normal file
View File

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

31
.codecov.yml Normal file
View File

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

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

@@ -0,0 +1,334 @@
# Copyright 2020-2021 Peter Dimov
# Copyright 2021 Andrey Semashev
# Copyright 2021 Alexander Grund
# Copyright 2022 James E. King III
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
---
name: CI
on:
pull_request:
push:
branches:
- master
- develop
- bugfix/**
- feature/**
- fix/**
- pr/**
concurrency:
group: ${{format('{0}:{1}', github.repository, github.ref)}}
cancel-in-progress: true
env:
GIT_FETCH_JOBS: 8
NET_RETRY_COUNT: 5
B2_CI_VERSION: 1
B2_VARIANT: debug,release
B2_LINK: shared,static
LCOV_BRANCH_COVERAGE: 0
CODECOV_NAME: Github Actions
jobs:
posix:
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include:
# Linux, gcc
- { compiler: gcc-4.8, cxxstd: '03,11', os: ubuntu-18.04 }
- { compiler: gcc-5, cxxstd: '03,11,14,1z', os: ubuntu-18.04 }
- { compiler: gcc-6, cxxstd: '03,11,14,17', os: ubuntu-18.04 }
- { compiler: gcc-7, cxxstd: '03,11,14,17', os: ubuntu-18.04 }
- { compiler: gcc-8, cxxstd: '03,11,14,17,2a', os: ubuntu-18.04 }
- { compiler: gcc-9, cxxstd: '03,11,14,17,2a', os: ubuntu-18.04 }
- { compiler: gcc-10, cxxstd: '03,11,14,17,20', os: ubuntu-20.04 }
- { compiler: gcc-11, cxxstd: '03,11,14,17,20', os: ubuntu-20.04 }
- { name: GCC w/ sanitizers, sanitize: yes,
compiler: gcc-11, cxxstd: '03,11,14,17,20', os: ubuntu-20.04 }
- { name: Collect coverage, coverage: yes,
compiler: gcc-10, cxxstd: '03,11', os: ubuntu-20.04, install: 'g++-10-multilib', address-model: '32,64' }
# Linux, clang
- { compiler: clang-3.5, cxxstd: '03,11', os: ubuntu-20.04, container: 'ubuntu:16.04' }
- { compiler: clang-3.6, cxxstd: '03,11,14', os: ubuntu-20.04, container: 'ubuntu:16.04' }
- { compiler: clang-3.7, cxxstd: '03,11,14', os: ubuntu-20.04, container: 'ubuntu:16.04' }
- { compiler: clang-3.8, cxxstd: '03,11,14', os: ubuntu-20.04, container: 'ubuntu:16.04' }
- { compiler: clang-3.9, cxxstd: '03,11,14', os: ubuntu-18.04 }
- { compiler: clang-4.0, cxxstd: '03,11,14', os: ubuntu-18.04 }
- { compiler: clang-5.0, cxxstd: '03,11,14,1z', os: ubuntu-18.04 }
- { compiler: clang-6.0, cxxstd: '03,11,14,17', os: ubuntu-18.04 }
- { compiler: clang-7, cxxstd: '03,11,14,17', os: ubuntu-18.04 }
# Note: clang-8 does not fully support C++20, so it is not compatible with some libstdc++ versions in this mode
- { compiler: clang-8, cxxstd: '03,11,14,17,2a', os: ubuntu-18.04, install: 'clang-8 g++-7', gcc_toolchain: 7 }
- { compiler: clang-9, cxxstd: '03,11,14,17,2a', os: ubuntu-20.04 }
- { compiler: clang-10, cxxstd: '03,11,14,17,20', os: ubuntu-20.04 }
- { compiler: clang-11, cxxstd: '03,11,14,17,20', os: ubuntu-20.04 }
- { name: Clang w/ valgrind, valgrind: yes,
compiler: clang-12, cxxstd: '03,11,14,17,20', os: ubuntu-20.04, install: 'valgrind' }
# libc++
- { compiler: clang-6.0, cxxstd: '03,11,14', os: ubuntu-18.04, stdlib: libc++, install: 'clang-6.0 libc++-dev libc++abi-dev' }
- { compiler: clang-12, cxxstd: '03,11,14,17,20', os: ubuntu-20.04, stdlib: libc++, install: 'clang-12 libc++-12-dev libc++abi-12-dev' }
- { name: Clang w/ sanitizers, sanitize: yes,
compiler: clang-12, cxxstd: '03,11,14,17,20', os: ubuntu-20.04, stdlib: libc++, install: 'clang-12 libc++-12-dev libc++abi-12-dev' }
# OSX, clang
- { compiler: clang, cxxstd: '03,11,14,17,2a', os: macos-10.15, sanitize: yes }
# Coverity Scan
# requires two github secrets in repo to activate; see ci/github/coverity.sh
# does not run on pull requests, only on pushes into develop and master
- { name: Coverity, coverity: yes,
compiler: clang-10, cxxstd: '17', os: ubuntu-20.04, ccache: no }
# multiarch (bigendian testing) - does not support coverage yet
- { name: Big-endian, multiarch: yes,
compiler: clang, cxxstd: '17', os: ubuntu-20.04, ccache: no, distro: fedora, edition: 34, arch: s390x }
timeout-minutes: 120
runs-on: ${{matrix.os}}
container: ${{matrix.container}}
env: {B2_USE_CCACHE: 1}
steps:
- name: Setup environment
run: |
if [ -f "/etc/debian_version" ]; then
echo "DEBIAN_FRONTEND=noninteractive" >> $GITHUB_ENV
export DEBIAN_FRONTEND=noninteractive
fi
if [ -n "${{matrix.container}}" ] && [ -f "/etc/debian_version" ]; then
apt-get -o Acquire::Retries=$NET_RETRY_COUNT update
apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y sudo software-properties-common
# Need (newer) git
for i in {1..${NET_RETRY_COUNT:-3}}; do sudo -E add-apt-repository -y ppa:git-core/ppa && break || sleep 10; done
apt-get -o Acquire::Retries=$NET_RETRY_COUNT update
apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y g++ python libpython-dev git
fi
# multiple job types are not compatible with ccache, they use "ccache: no" in the matrix
if [[ "${{ matrix.ccache }}" == "no" ]]; then
echo "B2_USE_CCACHE=0" >> $GITHUB_ENV
fi
if [[ "${{ matrix.valgrind }}" == "yes" ]]; then
echo "B2_DEFINES=BOOST_NO_STRESS_TEST=1" >> $GITHUB_ENV
echo "B2_TESTFLAGS=testing.launcher=valgrind" >> $GITHUB_ENV
echo "B2_FLAGS=define=BOOST_USE_VALGRIND=1" >> $GITHUB_ENV
echo "VALGRIND_OPTS=--error-exitcode=1" >> $GITHUB_ENV
fi
git config --global pack.threads 0
- uses: actions/checkout@v3
with:
# For coverage builds fetch the whole history, else only 1 commit using a 'fake ternary'
fetch-depth: ${{ matrix.coverage && '0' || '1' }}
- name: Cache ccache
uses: actions/cache@v3
if: env.B2_USE_CCACHE
with:
path: ~/.ccache
key: ${{matrix.os}}-${{matrix.container}}-${{matrix.compiler}}-${{github.sha}}
restore-keys: |
${{matrix.os}}-${{matrix.container}}-${{matrix.compiler}}-
${{matrix.os}}-${{matrix.container}}-${{matrix.compiler}}
- name: Fetch Boost.CI
uses: actions/checkout@v3
with:
repository: boostorg/boost-ci
ref: master
path: boost-ci-cloned
- name: Get CI scripts folder
run: |
# Copy ci folder if not testing Boost.CI
[[ "$GITHUB_REPOSITORY" =~ "boost-ci" ]] || cp -r boost-ci-cloned/ci .
rm -rf boost-ci-cloned
- name: Install packages
if: startsWith(matrix.os, 'ubuntu')
run: |
SOURCE_KEYS=(${{join(matrix.source_keys, ' ')}})
SOURCES=(${{join(matrix.sources, ' ')}})
# Add this by default
SOURCES+=(ppa:ubuntu-toolchain-r/test)
for key in "${SOURCE_KEYS[@]}"; do
for i in {1..$NET_RETRY_COUNT}; do
wget -O - "$key" | sudo apt-key add - && break || sleep 10
done
done
for source in "${SOURCES[@]}"; do
for i in {1..$NET_RETRY_COUNT}; do
sudo add-apt-repository $source && break || sleep 10
done
done
sudo apt-get -o Acquire::Retries=$NET_RETRY_COUNT update
if [[ -z "${{matrix.install}}" ]]; then
pkgs="${{matrix.compiler}}"
pkgs="${pkgs/gcc-/g++-}"
else
pkgs="${{matrix.install}}"
fi
sudo apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y $pkgs
- name: Setup GCC Toolchain
if: matrix.gcc_toolchain
run: |
GCC_TOOLCHAIN_ROOT="$HOME/gcc-toolchain"
echo "GCC_TOOLCHAIN_ROOT=$GCC_TOOLCHAIN_ROOT" >> $GITHUB_ENV
MULTIARCH_TRIPLET="$(dpkg-architecture -qDEB_HOST_MULTIARCH)"
mkdir -p "$GCC_TOOLCHAIN_ROOT"
ln -s /usr/include "$GCC_TOOLCHAIN_ROOT/include"
ln -s /usr/bin "$GCC_TOOLCHAIN_ROOT/bin"
mkdir -p "$GCC_TOOLCHAIN_ROOT/lib/gcc/$MULTIARCH_TRIPLET"
ln -s "/usr/lib/gcc/$MULTIARCH_TRIPLET/${{matrix.gcc_toolchain}}" "$GCC_TOOLCHAIN_ROOT/lib/gcc/$MULTIARCH_TRIPLET/${{matrix.gcc_toolchain}}"
- name: Setup multiarch
if: matrix.multiarch
run: |
sudo apt-get install --no-install-recommends -y binfmt-support qemu-user-static
sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
git clone https://github.com/jeking3/bdde.git
echo "$(pwd)/bdde/bin/linux" >> ${GITHUB_PATH}
echo "BDDE_DISTRO=${{ matrix.distro }}" >> ${GITHUB_ENV}
echo "BDDE_EDITION=${{ matrix.edition }}" >> ${GITHUB_ENV}
echo "BDDE_ARCH=${{ matrix.arch }}" >> ${GITHUB_ENV}
echo "B2_DEFINES=BOOST_NO_STRESS_TEST=1" >> ${GITHUB_ENV}
echo "B2_WRAPPER=bdde" >> ${GITHUB_ENV}
- name: Setup Boost
env:
B2_ADDRESS_MODEL: ${{matrix.address-model}}
B2_COMPILER: ${{matrix.compiler}}
B2_CXXSTD: ${{matrix.cxxstd}}
B2_SANITIZE: ${{matrix.sanitize}}
B2_STDLIB: ${{matrix.stdlib}}
run: source ci/github/install.sh
- name: Setup coverage collection
if: matrix.coverage
run: ci/github/codecov.sh "setup"
- name: Run tests
if: '!matrix.coverity'
run: ci/build.sh
- name: Upload coverage
if: matrix.coverage
run: ci/codecov.sh "upload"
- name: Run coverity
if: matrix.coverity && github.event_name == 'push' && (github.ref_name == 'develop' || github.ref_name == 'master')
run: ci/github/coverity.sh
env:
COVERITY_SCAN_NOTIFICATION_EMAIL: ${{ secrets.COVERITY_SCAN_NOTIFICATION_EMAIL }}
COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
windows:
defaults:
run:
shell: cmd
strategy:
fail-fast: false
matrix:
include:
- { toolset: msvc-14.2, cxxstd: '14,17,20', addrmd: '32,64', os: windows-2019 }
- { name: Collect coverage, coverage: yes,
toolset: msvc-14.3, cxxstd: '14,17,20', addrmd: '32,64', os: windows-2022 }
- { toolset: gcc, cxxstd: '03,11,14,17,2a', addrmd: '64', os: windows-2019 }
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Fetch Boost.CI
uses: actions/checkout@v2
with:
repository: boostorg/boost-ci
ref: master
path: boost-ci-cloned
- name: Get CI scripts folder
run: |
REM Copy ci folder if not testing Boost.CI
if "%GITHUB_REPOSITORY%" == "%GITHUB_REPOSITORY:boost-ci=%" xcopy /s /e /q /i /y boost-ci-cloned\ci .\ci
rmdir /s /q boost-ci-cloned
- name: Setup Boost
run: ci\github\install.bat
- name: Run tests
if: '!matrix.coverage'
run: ci\build.bat
env:
B2_TOOLSET: ${{matrix.toolset}}
B2_CXXSTD: ${{matrix.cxxstd}}
B2_ADDRESS_MODEL: ${{matrix.addrmd}}
- name: Collect coverage
shell: powershell
if: matrix.coverage
run: ci\opencppcoverage.ps1
env:
B2_TOOLSET: ${{matrix.toolset}}
B2_CXXSTD: ${{matrix.cxxstd}}
B2_ADDRESS_MODEL: ${{matrix.addrmd}}
- name: Upload coverage
if: matrix.coverage
uses: codecov/codecov-action@v2
with:
files: __out/cobertura.xml
CMake:
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include:
- { os: ubuntu-20.04, build_shared: ON, build_type: Release, generator: 'Unix Makefiles' }
- { os: ubuntu-20.04, build_shared: OFF, build_type: Debug, generator: 'Unix Makefiles' }
- { os: windows-2019, build_shared: ON, build_type: Release, generator: 'Visual Studio 16 2019' }
- { os: windows-2019, build_shared: OFF, build_type: Debug, generator: 'Visual Studio 16 2019' }
timeout-minutes: 120
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Fetch Boost.CI
uses: actions/checkout@v2
with:
repository: boostorg/boost-ci
ref: master
path: boost-ci-cloned
- name: Get CI scripts folder
run: |
# Copy ci folder if not testing Boost.CI
[[ "$GITHUB_REPOSITORY" =~ "boost-ci" ]] || cp -r boost-ci-cloned/ci .
rm -rf boost-ci-cloned
- name: Setup Boost
env: {B2_DONT_BOOTSTRAP: 1}
run: source ci/github/install.sh
- name: Run CMake
run: |
cd "$BOOST_ROOT"
mkdir __build_cmake_test__ && cd __build_cmake_test__
cmake -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DBOOST_INCLUDE_LIBRARIES=$SELF -DBUILD_SHARED_LIBS=${{matrix.build_shared}} -DBUILD_TESTING=ON -DBoost_VERBOSE=ON ..
cmake --build . --config ${{matrix.build_type}}

32
CMakeLists.txt Normal file
View File

@@ -0,0 +1,32 @@
# Generated by `boostdep --cmake dynamic_bitset`
# Copyright 2020 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.16)
project(boost_dynamic_bitset VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
add_library(boost_dynamic_bitset INTERFACE)
add_library(Boost::dynamic_bitset ALIAS boost_dynamic_bitset)
target_include_directories(boost_dynamic_bitset INTERFACE include)
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(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
endif()

11
Jamfile Normal file
View File

@@ -0,0 +1,11 @@
# Boost.DynamicBitset Library Jamfile
#
# Copyright (c) 2018 James E. King III
#
# Use, modification, and distribution are subject to the
# Boost Software License, Version 1.0. (See accompanying file
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
# please order by name to ease maintenance
build-project example ;
build-project test ;

View File

@@ -1,14 +0,0 @@
#
# Copyright Vladimir Prus 2004
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
test-suite dynamic_bitset :
[ run dyn_bitset_unit_tests1.cpp ]
[ run dyn_bitset_unit_tests2.cpp ]
[ run dyn_bitset_unit_tests3.cpp ]
[ run dyn_bitset_unit_tests4.cpp ]
;

23
LICENSE Normal file
View File

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

34
README.md Normal file
View File

@@ -0,0 +1,34 @@
DynamicBitset, part of collection of the [Boost C++ Libraries](http://github.com/boostorg), is similar to std::bitset however the size is specified at run-time instead of at compile-time.
### License
Distributed under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt).
### Properties
* C++03
* Header-only
### Build Status
Branch | GHA CI | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests |
:-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- |
[`master`](https://github.com/boostorg/dynamic_bitset/tree/master) | [![Build Status](https://github.com/boostorg/dynamic_bitset/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/boostorg/dynamic_bitset/actions?query=branch:master) | [![Build status](https://ci.appveyor.com/api/projects/status/keyn57y5d3sl1gw5/branch/master?svg=true)](https://ci.appveyor.com/project/jeking3/dynamic_bitset-jv17p/branch/master) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16167/badge.svg)](https://scan.coverity.com/projects/boostorg-dynamic_bitset) | [![codecov](https://codecov.io/gh/boostorg/dynamic_bitset/branch/master/graph/badge.svg)](https://codecov.io/gh/boostorg/dynamic_bitset/branch/master)| [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/dynamic_bitset.html) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](http://www.boost.org/doc/libs/master/doc/html/dynamic_bitset.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](http://www.boost.org/development/tests/master/developer/dynamic_bitset.html)
[`develop`](https://github.com/boostorg/dynamic_bitset/tree/develop) | [![Build Status](https://github.com/boostorg/dynamic_bitset/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/boostorg/dynamic_bitset/actions?query=branch:develop) | [![Build status](https://ci.appveyor.com/api/projects/status/keyn57y5d3sl1gw5/branch/develop?svg=true)](https://ci.appveyor.com/project/jeking3/dynamic_bitset-jv17p/branch/develop) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16167/badge.svg)](https://scan.coverity.com/projects/boostorg-dynamic_bitset) | [![codecov](https://codecov.io/gh/boostorg/dynamic_bitset/branch/develop/graph/badge.svg)](https://codecov.io/gh/boostorg/dynamic_bitset/branch/develop) | [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/dynamic_bitset.html) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](http://www.boost.org/doc/libs/develop/doc/html/dynamic_bitset.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](http://www.boost.org/development/tests/develop/developer/dynamic_bitset.html)
### Directories
| Name | Purpose |
| ----------- | ------------------------------ |
| `example` | examples |
| `doc` | documentation |
| `include` | headers |
| `test` | unit tests |
### More information
* [Ask questions](http://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-dynamic_bitset)
* [Report bugs](https://github.com/boostorg/dynamic_bitset/issues): Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well.
* Submit your patches as pull requests against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt).
* Discussions about the library are held on the [Boost developers mailing list](http://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](http://www.boost.org/community/policy.html) before posting and add the `[dynamic_bitset]` tag at the beginning of the subject line.

1
doc/readme Normal file
View File

@@ -0,0 +1 @@
The documentation for the dynamic_bitset library is the top-level index.html file.

View File

@@ -6,6 +6,9 @@
<!--
Copyright (c) 2001 Jeremy Siek
Copyright (c) 2003-2004, 2008 Gennaro Prota
Copyright (c) 2014 Ahmed Charles
Copyright (c) 2014 Riccardo Marcangelo
Copyright (c) 2018 Evgeny Shulgin
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
@@ -88,7 +91,7 @@ constructor of the <tt>dynamic_bitset</tt>.</p>
<p>The <tt>dynamic_bitset</tt> class is nearly identical to the
<a href=
"http://www.sgi.com/tech/stl/bitset.html"><tt>std::bitset</tt></a>
"https://boost.org/sgi/stl/bitset.html"><tt>std::bitset</tt></a>
class. The difference is that the size of the
<tt>dynamic_bitset</tt> (the number of bits) is specified at
run-time during the construction of a <tt>dynamic_bitset</tt>
@@ -141,8 +144,11 @@ public:
typedef bool <a href="#const_reference">const_reference</a>;
<a href=
"#cons0">dynamic_bitset</a>();
explicit <a href=
"#cons1">dynamic_bitset</a>(const Allocator&amp; alloc = Allocator());
"#cons1">dynamic_bitset</a>(const Allocator&amp; alloc);
explicit <a href=
"#cons2">dynamic_bitset</a>(size_type num_bits, unsigned long value = 0,
@@ -163,16 +169,23 @@ public:
<a href=
"#cons5">dynamic_bitset</a>(const dynamic_bitset&amp; b);
<a href=
"#move-cons">dynamic_bitset</a>(dynamic_bitset&amp;&amp; b);
void <a href="#swap">swap</a>(dynamic_bitset&amp; b);
dynamic_bitset&amp; <a href=
"#assign">operator=</a>(const dynamic_bitset&amp; b);
dynamic_bitset&amp; <a href=
"#move-assign">operator=</a>(dynamic_bitset&amp;&amp; b);
allocator_type <a href="#get_allocator">get_allocator()</a> const;
void <a href=
"#resize">resize</a>(size_type num_bits, bool value = false);
void <a href="#clear">clear</a>();
void <a href="#pop_back">pop_back</a>();
void <a href="#push_back">push_back</a>(bool bit);
void <a href="#append1">append</a>(Block block);
@@ -188,30 +201,41 @@ public:
dynamic_bitset <a href="#op-sl">operator&lt;&lt;</a>(size_type n) const;
dynamic_bitset <a href="#op-sr">operator&gt;&gt;</a>(size_type n) const;
dynamic_bitset&amp; <a href="#set3">set</a>(size_type n, size_type len, bool val);
dynamic_bitset&amp; <a href="#set2">set</a>(size_type n, bool val = true);
dynamic_bitset&amp; <a href="#set1">set</a>();
dynamic_bitset&amp; <a href="#reset3">reset</a>(size_type n, size_type len);
dynamic_bitset&amp; <a href="#reset2">reset</a>(size_type n);
dynamic_bitset&amp; <a href="#reset1">reset</a>();
dynamic_bitset&amp; <a href="#flip3">flip</a>(size_type n, size_type len);
dynamic_bitset&amp; <a href="#flip2">flip</a>(size_type n);
dynamic_bitset&amp; <a href="#flip1">flip</a>();
reference <a href="#at">at</a>(size_type n);
bool <a href="#const-at">at</a>(size_type n) const;
bool <a href="#test">test</a>(size_type n) const;
bool <a href="#test">test_set</a>(size_type n, bool val = true);
bool <a href="#all">all</a>() const;
bool <a href="#any">any</a>() const;
bool <a href="#none">none</a>() const;
dynamic_bitset <a href="#op-not">operator~</a>() const;
size_type <a href="#count">count</a>() const;
size_type <a href="#count">count</a>() const noexcept;
reference <a href="#bracket">operator[]</a>(size_type pos);
bool <a href="#const-bracket">operator[]</a>(size_type pos) const;
unsigned long <a href="#to_ulong">to_ulong</a>() const;
size_type <a href="#size">size</a>() const;
size_type <a href="#num_blocks">num_blocks</a>() const;
size_type <a href="#max_size">max_size</a>() const;
bool <a href="#empty">empty</a>() const;
size_type <a href="#size">size</a>() const noexcept;
size_type <a href="#num_blocks">num_blocks</a>() const noexcept;
size_type <a href="#max_size">max_size</a>() const noexcept;
bool <a href="#empty">empty</a>() const noexcept;
size_type <a href="#capacity">capacity</a>() const noexcept;
void <a href="#reserve">reserve</a>(size_type num_bits);
void <a href="#shrink_to_fit">shrink_to_fit</a>();
bool <a href="#is_subset_of">is_subset_of</a>(const dynamic_bitset&amp; a) const;
bool <a href="#is_proper_subset_of">is_proper_subset_of</a>(const dynamic_bitset&amp; a) const;
bool <a href="#intersects">intersects</a>(const dynamic_bitset&amp; a) const;
size_type <a href="#find_first">find_first</a>() const;
size_type <a href="#find_next">find_next</a>(size_type pos) const;
@@ -321,7 +345,7 @@ input/output and some bitwise operations).
<h3><a id="rationale">Rationale</a></h3>
<p>
<tt>dynamic_bitset</tt> is not a <a href=
"http://www.sgi.com/tech/stl/Container.html">Container</a> and
"https://boost.org/sgi/stl/Container.html">Container</a> and
does not provide iterators for the following reason:
</p>
@@ -336,7 +360,7 @@ people try to use iterators from <tt>std::vector&lt;bool&gt;</tt>
with a Standard algorithm such as <tt>std::search</tt>. The
<tt>std::search</tt> requirements say that the iterator must be a
<a href=
"http://www.sgi.com/tech/stl/ForwardIterator.html">Forward
"https://boost.org/sgi/stl/ForwardIterator.html">Forward
Iterator</a>, but the <tt>std::vector&lt;bool&gt;::iterator</tt>
does not meet this requirement because of the proxy reference.
Depending on the implementation, they may or not be a compile
@@ -348,14 +372,14 @@ by not pretending to be a container.</li>
<p>Some people prefer the name "toggle" to "flip". The name
"flip" was chosen because that is the name used in <a href=
"http://www.sgi.com/tech/stl/bitset.html"><tt>std::bitset</tt></a>.
"https://boost.org/sgi/stl/bitset.html"><tt>std::bitset</tt></a>.
In fact, most of the function names for <tt>dynamic_bitset</tt>
were chosen for this reason.</p>
<p><tt>dynamic_bitset</tt> does not throw exceptions when a
precondition is violated (as is done in <tt>std::bitset</tt>).
Instead <tt>assert</tt> is used. See the guidelines for <a href=
"http://www.boost.org/more/error_handling.html">Error and Exception Handling</a>
"http://www.boost.org/community/error_handling.html">Error and Exception Handling</a>
for the explanation.</p>
<h3><a id="header-files">Header Files</a></h3>
@@ -390,13 +414,13 @@ in the header <a href=
</table>
<h3><a id="concepts-modeled">Concepts Modeled</a></h3>
<a href=
"http://www.sgi.com/tech/stl/Assignable.html">Assignable</a>, <a
"https://boost.org/sgi/stl/Assignable.html">Assignable</a>, <a
href=
"http://www.sgi.com/tech/stl/DefaultConstructible.html">Default
"https://boost.org/sgi/stl/DefaultConstructible.html">Default
Constructible</a>, <a href=
"http://www.sgi.com/tech/stl/EqualityComparable.html">Equality
"https://boost.org/sgi/stl/EqualityComparable.html">Equality
Comparable</a>, <a href=
"http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan
"https://boost.org/sgi/stl/LessThanComparable.html">LessThan
Comparable</a>.
<h3><a id="type-requirements">Type requirements</a></h3>
@@ -551,19 +575,30 @@ The maximum value of <tt>size_type</tt>.
<hr />
<pre>
<a id=
"cons1">dynamic_bitset</a>(const Allocator&amp; alloc = Allocator())
"cons0">dynamic_bitset</a>()
</pre>
<b>Effects:</b> Constructs a bitset of size zero. The allocator
for this bitset is a default-constructed object of type
<tt>Allocator</tt>.<br />
<b>Postconditions:</b> <tt>this-&gt;size() == 0</tt>.<br />
<b>Throws:</b> Nothing unless the default constructor of
<tt>Allocator</tt> throws an exception.<br />
(Required by <a href=
"https://boost.org/sgi/stl/DefaultConstructible.html">Default
Constructible</a>.)
<hr />
<pre>
<a id=
"cons1">dynamic_bitset</a>(const Allocator&amp; alloc)
</pre>
<b>Effects:</b> Constructs a bitset of size zero. A copy of the
<tt>alloc</tt> object will be used in subsequent bitset
operations such as <tt>resize</tt> to allocate memory.<br />
<b>Postconditions:</b> <tt>this-&gt;size() == 0</tt>.<br />
<b>Throws:</b> An allocation error if memory is exhausted
(<tt>std::bad_alloc</tt> if
<tt>Allocator=std::allocator</tt>).<br />
(Required by <a href=
"http://www.sgi.com/tech/stl/DefaultConstructible.html">Default
Constructible</a>.)
<b>Throws:</b> nothing.
<hr />
<pre>
@@ -618,7 +653,21 @@ allocator in <tt>x</tt>. <br />
(<tt>std::bad_alloc</tt> if
<tt>Allocator=std::allocator</tt>).<br />
(Required by <a href=
"http://www.sgi.com/tech/stl/Assignable.html">Assignable</a>.)
"https://boost.org/sgi/stl/Assignable.html">Assignable</a>.)
<hr />
<pre>
<a id="move-cons">dynamic_bitset</a>(dynamic_bitset&amp;&amp; x)
</pre>
<b>Effects:</b> Constructs a bitset that is the same as the bitset
<tt>x</tt>, while using the resources from <tt>x</tt>. The allocator
for this bitset is moved from the allocator in <tt>x</tt>. <br />
<b>Postconditions:</b> For all <tt>i</tt> in the range
<tt>[0,x.size())</tt>, <tt>(*this)[i] == x[i]</tt>.<br />
<b>Throws:</b> An allocation error if memory is exhausted
(<tt>std::bad_alloc</tt> if
<tt>Allocator=std::allocator</tt>).
<hr />
<pre>
@@ -687,7 +736,7 @@ position <tt>(b * bits_per_block + i)</tt> in the bitset (where
<br />
<b>Requires:</b> <tt>BlockInputIterator</tt> must be either an
integral type or a model of <a href=
"http://www.sgi.com/tech/stl/InputIterator.html">Input
"https://boost.org/sgi/stl/InputIterator.html">Input
Iterator</a> whose <tt>value_type</tt> is the same type as
<tt>Block</tt>.<br /> <b>Throws:</b> An allocation error if
memory is exhausted (<tt>std::bad_alloc</tt> if
@@ -698,11 +747,11 @@ memory is exhausted (<tt>std::bad_alloc</tt> if
template&lt;typename Char, typename Traits, typename Alloc&gt;
explicit
<a id="cons3">dynamic_bitset</a>(const <a href=
"http://www.sgi.com/tech/stl/basic_string.html">std::basic_string</a>&lt;Char,Traits,Alloc&gt;&amp; s,
"https://boost.org/sgi/stl/basic_string.html">std::basic_string</a>&lt;Char,Traits,Alloc&gt;&amp; s,
typename std::basic_string&lt;CharT, Traits, Alloc&gt;::size_type pos = 0,
typename std::basic_string&lt;CharT, Traits, Alloc&gt;::size_type n = <a
href=
"http://www.sgi.com/tech/stl/basic_string.html">std::basic_string</a>&lt;Char,Traits,Alloc&gt;::npos,
"https://boost.org/sgi/stl/basic_string.html">std::basic_string</a>&lt;Char,Traits,Alloc&gt;::npos,
const Allocator&amp; alloc = Allocator())
</pre>
@@ -761,7 +810,21 @@ dynamic_bitset&amp; <a id=
<b>Returns:</b> <tt>*this</tt>.<br />
<b>Throws:</b> nothing. <br />
(Required by <a href=
"http://www.sgi.com/tech/stl/Assignable.html">Assignable</a>.)
"https://boost.org/sgi/stl/Assignable.html">Assignable</a>.)
<hr />
<pre>
dynamic_bitset&amp; <a id=
"move-assign">operator=</a>(dynamic_bitset&amp;&amp; x)
</pre>
<b>Effects:</b> This bitset becomes the same as the bitset
<tt>x</tt>, while using the resources from <tt>x</tt>.<br />
<b>Postconditions:</b> For all <tt>i</tt> in the range
<tt>[0,x.size())</tt>, <tt>(*this)[i] == x[i]</tt>.<br />
<b>Returns:</b> <tt>*this</tt>.<br />
<b>Throws:</b> An allocation error if memory is exhausted
(<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
<hr />
<pre>
@@ -796,6 +859,15 @@ void <a id="clear">clear</a>()
<b>Effects:</b> The size of the bitset becomes zero.<br />
<b>Throws:</b> nothing.
<hr />
<pre>
void <a id="pop_back">pop_back</a>();
</pre>
<b>Precondition:</b> <tt>!this-&gt;empty()</tt>.<br />
<b>Effects:</b> Decreases the size of the bitset by one.<br />
<b>Throws:</b> nothing.
<hr />
<pre>
void <a id="push_back">push_back</a>(bool value);
@@ -841,7 +913,7 @@ for (; first != last; ++first)
<b>Requires:</b> The <tt>BlockInputIterator</tt> type must be a
model of <a href=
"http://www.sgi.com/tech/stl/InputIterator.html">Input
"https://boost.org/sgi/stl/InputIterator.html">Input
Iterator</a> and the <tt>value_type</tt> must be the same type as
<tt>Block</tt>.<br />
<b>Throws:</b> An allocation error if memory is exhausted
@@ -1010,6 +1082,18 @@ dynamic_bitset&amp; <a id="reset1">reset</a>()
<b>Returns:</b> <tt>*this</tt><br />
<b>Throws:</b> nothing.
<hr />
<pre>
dynamic_bitset&amp; <a id=
"set3">set</a>(size_type n, size_type len, bool val);
</pre>
<b>Precondition:</b> <tt>n + len &lt; this-&gt;size()</tt>.<br />
<b>Effects:</b> Sets every bit indexed from <tt>n</tt> to
<tt>n + len - 1</tt> inclusively if <tt>val</tt> is <tt>true</tt>, and
clears them if <tt>val</tt> is <tt>false</tt>. <br />
<b>Returns:</b> <tt>*this</tt>
<hr />
<pre>
dynamic_bitset&amp; <a id=
@@ -1022,6 +1106,17 @@ dynamic_bitset&amp; <a id=
<tt>false</tt>. <br />
<b>Returns:</b> <tt>*this</tt>
<hr />
<pre>
dynamic_bitset&amp; <a id=
"reset3">reset</a>(size_type n, size_type len);
</pre>
<b>Precondition:</b> <tt>n + len &lt; this-&gt;size()</tt>.<br />
<b>Effects:</b> Clears every bit indexed from <tt>n</tt> to
<tt>n + len - 1</tt> inclusively.<br />
<b>Returns:</b> <tt>*this</tt>
<hr />
<pre>
dynamic_bitset&amp; <a id="reset2">reset</a>(size_type n)
@@ -1031,6 +1126,16 @@ dynamic_bitset&amp; <a id="reset2">reset</a>(size_type n)
<b>Effects:</b> Clears bit <tt>n</tt>.<br />
<b>Returns:</b> <tt>*this</tt>
<hr />
<pre>
dynamic_bitset&amp; <a id="flip3">flip</a>(size_type n, size_type len)
</pre>
<b>Precondition:</b> <tt>n + len &lt; this-&gt;size()</tt>.<br />
<b>Effects:</b> Flips every bit indexed from <tt>n</tt> to
<tt>n + len - 1</tt> inclusively.<br />
<b>Returns:</b> <tt>*this</tt>
<hr />
<pre>
dynamic_bitset&amp; <a id="flip2">flip</a>(size_type n)
@@ -1077,6 +1182,40 @@ bool <a id="empty">empty</a>() const;
otherwise. <i>Note</i>: not to be confused with <tt>none()</tt>, that has
different semantics.
<hr />
<pre>
size_type <a id="capacity">capacity</a>() const;
</pre>
<b>Returns:</b> The total number of elements that <tt>*this</tt> can hold without requiring
reallocation.<br />
<b>Throws:</b> nothing.
<hr />
<pre>
void <a id="reserve">reserve</a>(size_type num_bits);
</pre>
<b>Effects:</b> A directive that informs the bitset of a planned change in size, so that it can
manage the storage allocation accordingly. After reserve(), capacity() is greater or equal to the
argument of reserve() if reallocation happens; and equal to the previous value of capacity() otherwise.
Reallocation happens at this point if and only if the current capacity is less than the argument of
reserve(). <br />
<i>Note:</i> It does not change the size() of the bitset.<br />
<b>Postcondtitions:</b> <tt>this->capacity() >= num_bits</tt>.<br />
<b>Throws:</b> An allocation error if memory is exhausted
(<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
<hr />
<pre>
void <a id="shrink_to_fit">shrink_to_fit</a>();
</pre>
<b>Effects:</b> shrink_to_fit() is a request to reduce memory use by removing unused capacity.<br />
<i>Note:</i> It does not change the size() of the bitset.<br />
<b>Throws:</b> An allocation error if memory is exhausted
(<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
<hr />
<pre>
size_type <a id="count">count</a>() const
@@ -1086,6 +1225,15 @@ size_type <a id="count">count</a>() const
set.<br />
<b>Throws:</b> nothing.
<hr />
<pre>
bool <a id="all">all</a>() const
</pre>
<b>Returns:</b> <tt>true</tt> if all bits in this bitset are set or
if <tt>size() == 0</tt>, and otherwise returns <tt>false</tt>.<br />
<b>Throws:</b> nothing.
<hr />
<pre>
bool <a id="any">any</a>() const
@@ -1104,6 +1252,24 @@ bool <a id="none">none</a>() const
returns <tt>false</tt>.<br />
<b>Throws:</b> nothing.
<hr />
<pre>
reference <a id="at">at</a>(size_type n)
</pre>
<b>Precondition:</b> <tt>n &lt; this-&gt;size()</tt>.<br />
<b>Returns:</b> The same as <tt>operator[](n)</tt>.<br />
<b>Throws:</b> <tt>std::out_of_range</tt> if that <tt>n</tt> is not within the range of the bitset.
<hr />
<pre>
bool <a id="const-at">at</a>(size_type n) const
</pre>
<b>Precondition:</b> <tt>n &lt; this-&gt;size()</tt>.<br />
<b>Returns:</b> The same as <tt>operator[](n)</tt>.<br />
<b>Throws:</b> <tt>std::out_of_range</tt> if that <tt>n</tt> is not within the range of the bitset.
<hr />
<pre>
bool <a id="test">test</a>(size_type n) const
@@ -1113,6 +1279,18 @@ bool <a id="test">test</a>(size_type n) const
<b>Returns:</b> <tt>true</tt> if bit <tt>n</tt> is set and
<tt>false</tt> is bit <tt>n</tt> is 0.
<hr />
<pre>
bool <a id="test">test_set</a>(size_type n, bool val = true)
</pre>
<b>Precondition:</b> <tt>n &lt; this-&gt;size()</tt>.<br />
<b>Effects:</b> Sets bit <tt>n</tt> if <tt>val</tt> is
<tt>true</tt>, and clears bit <tt>n</tt> if <tt>val</tt> is
<tt>false</tt>. <br />
<b>Returns:</b> <tt>true</tt> if the previous state of bit
<tt>n</tt> was set and <tt>false</tt> is bit <tt>n</tt> is 0.
<hr />
<pre>
reference <a id="bracket">operator[]</a>(size_type n)
@@ -1174,6 +1352,19 @@ also set and if <tt>this-&gt;count() &lt; a.count()</tt>.
Otherwise this function returns false.<br />
<b>Throws:</b> nothing.
<hr />
<pre>
bool <a id=
"intersects">intersects</a>(const dynamic_bitset&amp; a) const
</pre>
<b>Requires:</b> <tt>this-&gt;size() == a.size()</tt><br />
<b>Returns:</b> true if this bitset and <tt>a</tt> intersect.
That is, it returns true if, there is a bit which is set in this
bitset, such that the corresponding bit in bitset <tt>a</tt> is
also set. Otherwise this function returns false.<br />
<b>Throws:</b> nothing.
<hr />
<pre>
size_type <a id = "find_first">find_first</a>() const;
@@ -1203,7 +1394,7 @@ rhs.size()</tt> and if for all <tt>i</tt> in the range
returns <tt>false</tt>.<br />
<b>Throws:</b> nothing.<br />
(Required by <a href=
"http://www.sgi.com/tech/stl/EqualityComparable.html">Equality
"https://boost.org/sgi/stl/EqualityComparable.html">Equality
Comparable</a>.)
<hr />
@@ -1215,7 +1406,7 @@ bool <a id=
<b>Returns:</b> <tt>!((*this) == rhs)</tt><br />
<b>Throws:</b> nothing.<br />
(Required by <a href=
"http://www.sgi.com/tech/stl/EqualityComparable.html">Equality
"https://boost.org/sgi/stl/EqualityComparable.html">Equality
Comparable</a>.)
<hr />
@@ -1227,11 +1418,11 @@ bool <a id=
<b>Returns:</b> <tt>true</tt> if this bitset is lexicographically
less than <tt>rhs</tt>, and returns <tt>false</tt> otherwise.
(See the description of <a href=
"http://www.sgi.com/tech/stl/lexicographical_compare.html">lexicographical_compare</a>
"https://boost.org/sgi/stl/lexicographical_compare.html">lexicographical_compare</a>
for a definition of lexicographic ordering). <br />
<b>Throws:</b> nothing.<br />
(Required by <a href=
"http://www.sgi.com/tech/stl/LessThanComparable.html">Less Than
"https://boost.org/sgi/stl/LessThanComparable.html">Less Than
Comparable</a>.)
<hr />
@@ -1244,7 +1435,7 @@ bool <a id=
rhs)</tt><br />
<b>Throws:</b> nothing.<br />
(Required by <a href=
"http://www.sgi.com/tech/stl/LessThanComparable.html">Less Than
"https://boost.org/sgi/stl/LessThanComparable.html">Less Than
Comparable</a>.)
<hr />
@@ -1256,7 +1447,7 @@ bool <a id=
<b>Returns:</b> <tt>(*this) &lt; rhs || (*this) == rhs</tt><br />
<b>Throws:</b> nothing.<br />
(Required by <a href=
"http://www.sgi.com/tech/stl/LessThanComparable.html">Less Than
"https://boost.org/sgi/stl/LessThanComparable.html">Less Than
Comparable</a>.)
<hr />
@@ -1268,7 +1459,7 @@ bool <a id=
<b>Returns:</b> <tt>(*this) &gt; rhs || (*this) == rhs</tt><br />
<b>Throws:</b> nothing.<br />
(Required by <a href=
"http://www.sgi.com/tech/stl/LessThanComparable.html">Less Than
"https://boost.org/sgi/stl/LessThanComparable.html">Less Than
Comparable</a>.)
<hr />
@@ -1328,7 +1519,7 @@ template &lt;typename CharT, typename Alloc&gt;
void <a id=
"to_string">to_string</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; b,
<a href=
"http://www.sgi.com/tech/stl/basic_string.html">std::basic_string</a>&lt;Char,Traits,Alloc&gt;&amp; s)
"https://boost.org/sgi/stl/basic_string.html">std::basic_string</a>&lt;Char,Traits,Alloc&gt;&amp; s)
</pre>
<b>Effects:</b> Copies a representation of <tt>b</tt> into the
@@ -1366,7 +1557,7 @@ block <tt>bval</tt> written, the bit <tt>(bval &gt;&gt; i) &amp;
+ i)</tt> in the bitset.<br />
<b>Requires:</b> The type <tt>BlockOutputIterator</tt> must be a
model of <a href=
"http://www.sgi.com/tech/stl/OutputIterator.html">Output
"https://boost.org/sgi/stl/OutputIterator.html">Output
Iterator</a> and its <tt>value_type</tt> must be the same type as
<tt>Block</tt>. Further, the size of the output range must be
greater or equal <tt>b.num_blocks()</tt>.
@@ -1382,7 +1573,7 @@ void <a id=
<b>Effects:</b> Reads blocks from the iterator range into the
bitset. <br />
<b>Requires:</b> The type <tt>BlockIterator</tt> must be a model
of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input
of <a href="https://boost.org/sgi/stl/InputIterator.html">Input
Iterator</a> and its <tt>value_type</tt> must be the same type as
<tt>Block</tt>. The size of the iterator range must be less or
equal to <tt>b.num_blocks()</tt>.
@@ -1495,6 +1686,14 @@ exception guarantee.
<hr />
<h3><a id="changes-from-previous-ver">Changes from previous version(s)</a></h3>
<h4><i>Changes in Boost 1.56.0</i></h4>
<ul>
<li>Support for C++11 move constructors.</li>
<li>Warning fixes on MSVC 2013.</li>
<li>Support for C++11 minimal allocators.</li>
<li>Add noexcept specifications.</li>
</ul>
<h4><i>Changes in Boost 1.37.0</i></h4>
<ul>
<li>The constructor from a block range implements a "do the right thing"
@@ -1547,17 +1746,20 @@ applied to their corresponding <tt>dynamic_bitset</tt>s.
</li>
</ul>
<i>General improvements</i>
<br /><br />
<ul>
<li>
Several optimizations to member and non-member functions and to the
nested class <tt>reference</tt>.
</li>
</ul>
<hr />
<h3><a id="see-also">See also</a></h3>
<tt><a href=
"http://www.sgi.com/tech/stl/bitset.html">std::bitset</a></tt>,
"https://boost.org/sgi/stl/bitset.html">std::bitset</a></tt>,
<tt><a href=
"http://www.sgi.com/tech/stl/Vector.html">std::vector</a></tt>,
"https://boost.org/sgi/stl/Vector.html">std::vector</a></tt>,
<h3><a id="acknowledgements">Acknowledgements</a></h3>
@@ -1581,6 +1783,18 @@ href="mailto:cda@freshsources.com">cda@freshsources.com</a>)<br
href="http://gennaro-prota.50webs.com/">Gennaro Prota</a>
(name.surname yahoo.com)</td>
</tr>
<tr>
<td>Copyright &copy; 2014</td>
<td>Ahmed Charles (<a href="mailto:acharles@outlook.com">acharles@outlook.com</a>)</td>
</tr>
<tr>
<td>Copyright &copy; 2014</td>
<td>Glen Fernandes (<a href="mailto:glenjofe@gmail.com">glenjofe@gmail.com</a>)</td>
</tr>
<tr>
<td>Copyright &copy; 2014</td>
<td>Riccardo Marcangelo (<a href="mailto:ricky.65@outlook.com">ricky.65@outlook.com</a>)</td>
</tr>
</table>
<br />
<div class="legalnotice">

View File

@@ -1,13 +1,15 @@
// -----------------------------------------------------------
// Copyright (c) 2002 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
# -----------------------------------------------------------
# Copyright (c) 2002 Gennaro Prota
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# -----------------------------------------------------------
exe timing_tests
: timing_tests.cpp
../../timer/build//boost_timer
;
exe example1

View File

@@ -23,6 +23,10 @@
// table in detail/dynamic_bitset.hpp and report any interesting
// discovery on the list as well.
// You might also want to try both counting methods (by_bytes vs.
// by_blocks) to see if the one that is selected automatically is
// actually the fastest on your system.
//
//
// -----------------------------------------------------------------------//
@@ -45,7 +49,7 @@
#include "boost/cstdlib.hpp"
#include "boost/version.hpp"
#include "boost/timer.hpp"
#include "boost/timer/timer.hpp"
#include "boost/dynamic_bitset.hpp"
@@ -55,9 +59,9 @@ namespace {
// see http://gcc.gnu.org/ml/gcc-bugs/1999-03n/msg00884.html
//
class boost_version {
const int m_major;
const int m_minor;
const int m_subminor;
int m_major;
int m_minor;
int m_subminor;
public:
boost_version(unsigned long v = BOOST_VERSION):
@@ -90,12 +94,15 @@ void prologue()
template <typename T>
void timing_test(T* = 0) // dummy parameter to workaround VC6
{
const unsigned long num = 100000;
#ifndef BOOST_NO_STRESS_TEST
const unsigned long num = 30 * 100000;
#else
const unsigned long num = 30 * 1000;
#endif
// This variable is printed at the end of the test,
// to prevent the optimizer eliminating the call to
// to prevent the optimizer from removing the call to
// count() in the loop below.
typename boost::dynamic_bitset<T>::size_type dummy = 0;
@@ -104,16 +111,13 @@ void timing_test(T* = 0) // dummy parameter to workaround VC6
std::cout << "--------------------------------------------------\n";
{
boost::timer time;
boost::timer::auto_cpu_timer time;
const typename boost::dynamic_bitset<T>::size_type sz = 5000;
for (unsigned long i = 0; i < num; ++i) {
boost::dynamic_bitset<T> bs(sz, i);
dummy += bs.count();
}
const double elaps = time.elapsed();
std::cout << "Elapsed: " << elaps << '\n';
}
std::cout << "(total count: " << dummy << ")\n\n";
@@ -123,7 +127,6 @@ void timing_test(T* = 0) // dummy parameter to workaround VC6
int main()
{
prologue();
timing_test<unsigned char>();

View File

@@ -1,229 +0,0 @@
// -----------------------------------------------------------
//
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
#ifndef BOOST_DETAIL_DYNAMIC_BITSET_HPP
#define BOOST_DETAIL_DYNAMIC_BITSET_HPP
#include <cstddef>
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
namespace boost {
namespace detail {
namespace dynamic_bitset_impl {
// Gives (read-)access to the object representation
// of an object of type T (3.9p4). CANNOT be used
// on a base sub-object
//
template <typename T>
inline const unsigned char * object_representation (T* p)
{
return static_cast<const unsigned char *>(static_cast<const void *>(p));
}
template<typename T, int amount, int width /* = default */>
struct shifter
{
static void left_shift(T & v) {
amount >= width ? (v = 0)
: (v >>= BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(amount));
}
};
// ------- count function implementation --------------
typedef unsigned char byte_type;
// These two entities
//
// enum mode { access_by_bytes, access_by_blocks };
// template <mode> struct mode_to_type {};
//
// were removed, since the regression logs (as of 24 Aug 2008)
// showed that several compilers had troubles with recognizing
//
// const mode m = access_by_bytes
//
// as a constant expression
//
// * So, we'll use bool, instead of enum *.
//
template <bool value>
struct value_to_type
{
value_to_type() {}
};
const bool access_by_bytes = true;
const bool access_by_blocks = false;
// the table: wrapped in a class template, so
// that it is only instantiated if/when needed
//
template <bool dummy_name = true>
struct count_table { static const byte_type table[]; };
template <>
struct count_table<false> { /* no table */ };
const unsigned int table_width = 8;
template <bool b>
const byte_type count_table<b>::table[] =
{
// Automatically generated by GPTableGen.exe v.1.0
//
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
};
// overload for access by bytes
//
template <typename Iterator>
inline std::size_t do_count(Iterator first, std::size_t length,
int /*dummy param*/,
value_to_type<access_by_bytes>* )
{
std::size_t num = 0;
if (length)
{
const byte_type * p = object_representation(&*first);
length *= sizeof(*first);
do {
num += count_table<>::table[*p];
++p;
--length;
} while (length);
}
return num;
}
// overload for access by blocks
//
template <typename Iterator, typename ValueType>
inline std::size_t do_count(Iterator first, std::size_t length, ValueType,
value_to_type<access_by_blocks>*)
{
std::size_t num = 0;
while (length){
ValueType value = *first;
while (value) {
num += count_table<>::table[value & ((1u<<table_width) - 1)];
value >>= table_width;
}
++first;
--length;
}
return num;
}
// -------------------------------------------------------
// Some library implementations simply return a dummy
// value such as
//
// size_type(-1) / sizeof(T)
//
// from vector<>::max_size. This tries to get more
// meaningful info.
//
template <typename T>
typename T::size_type vector_max_size_workaround(const T & v) {
typedef typename T::allocator_type allocator_type;
const typename allocator_type::size_type alloc_max =
v.get_allocator().max_size();
const typename T::size_type container_max = v.max_size();
return alloc_max < container_max?
alloc_max :
container_max;
}
// for static_asserts
template <typename T>
struct allowed_block_type {
enum { value = T(-1) > 0 }; // ensure T has no sign
};
template <>
struct allowed_block_type<bool> {
enum { value = false };
};
template <typename T>
struct is_numeric {
enum { value = false };
};
# define BOOST_dynamic_bitset_is_numeric(x) \
template<> \
struct is_numeric< x > { \
enum { value = true }; \
} /**/
BOOST_dynamic_bitset_is_numeric(bool);
BOOST_dynamic_bitset_is_numeric(char);
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
BOOST_dynamic_bitset_is_numeric(wchar_t);
#endif
BOOST_dynamic_bitset_is_numeric(signed char);
BOOST_dynamic_bitset_is_numeric(short int);
BOOST_dynamic_bitset_is_numeric(int);
BOOST_dynamic_bitset_is_numeric(long int);
BOOST_dynamic_bitset_is_numeric(unsigned char);
BOOST_dynamic_bitset_is_numeric(unsigned short);
BOOST_dynamic_bitset_is_numeric(unsigned int);
BOOST_dynamic_bitset_is_numeric(unsigned long);
#if defined(BOOST_HAS_LONG_LONG)
BOOST_dynamic_bitset_is_numeric(::boost::long_long_type);
BOOST_dynamic_bitset_is_numeric(::boost::ulong_long_type);
#endif
// intentionally omitted
//BOOST_dynamic_bitset_is_numeric(float);
//BOOST_dynamic_bitset_is_numeric(double);
//BOOST_dynamic_bitset_is_numeric(long double);
#undef BOOST_dynamic_bitset_is_numeric
} // dynamic_bitset_impl
} // namespace detail
} // namespace boost
#endif // include guard

View File

@@ -34,7 +34,7 @@ namespace boost { namespace detail {
#endif
//
#if (defined __BORLANDC__ && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))) \
#if (defined BOOST_BORLANDC && BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))) \
|| (defined BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
#define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
#endif

View File

@@ -0,0 +1,307 @@
// -----------------------------------------------------------
//
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
// Copyright (c) 2014 Glen Joseph Fernandes
// (glenjofe@gmail.com)
// Copyright (c) 2018 Evgeny Shulgin
// Copyright (c) 2019 Andrey Semashev
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
#ifndef BOOST_DETAIL_DYNAMIC_BITSET_HPP
#define BOOST_DETAIL_DYNAMIC_BITSET_HPP
#include <memory>
#include <cstddef>
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
#include <boost/core/allocator_access.hpp>
#if ((defined(BOOST_MSVC) && (BOOST_MSVC >= 1600)) || (defined(__clang__) && defined(__c2__)) || (defined(BOOST_INTEL) && defined(_MSC_VER))) && (defined(_M_IX86) || defined(_M_X64))
#include <intrin.h>
#endif
namespace boost {
namespace detail {
namespace dynamic_bitset_impl {
template<class T>
struct max_limit {
BOOST_STATIC_CONSTEXPR T value = static_cast<T>(-1);
};
template<class T>
BOOST_CONSTEXPR_OR_CONST T max_limit<T>::value;
// Gives (read-)access to the object representation
// of an object of type T (3.9p4). CANNOT be used
// on a base sub-object
//
template <typename T>
inline const unsigned char * object_representation (T* p)
{
return static_cast<const unsigned char *>(static_cast<const void *>(p));
}
template<typename T, int amount, int width /* = default */>
struct shifter
{
static void left_shift(T & v) {
amount >= width ? (v = 0)
: (v >>= BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(amount));
}
};
// ------- count function implementation --------------
typedef unsigned char byte_type;
// These two entities
//
// enum mode { access_by_bytes, access_by_blocks };
// template <mode> struct mode_to_type {};
//
// were removed, since the regression logs (as of 24 Aug 2008)
// showed that several compilers had troubles with recognizing
//
// const mode m = access_by_bytes
//
// as a constant expression
//
// * So, we'll use bool, instead of enum *.
//
template <bool value>
struct value_to_type
{
value_to_type() {}
};
const bool access_by_bytes = true;
const bool access_by_blocks = false;
// the table: wrapped in a class template, so
// that it is only instantiated if/when needed
//
template <bool dummy_name = true>
struct count_table { static const byte_type table[]; };
template <>
struct count_table<false> { /* no table */ };
const unsigned int table_width = 8;
template <bool b>
const byte_type count_table<b>::table[] =
{
// Automatically generated by GPTableGen.exe v.1.0
//
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
};
// Some platforms have fast popcount operation, that allow us to implement
// counting bits much more efficiently
//
template <typename ValueType>
BOOST_FORCEINLINE std::size_t popcount(ValueType value) BOOST_NOEXCEPT
{
std::size_t num = 0u;
while (value) {
num += count_table<>::table[value & ((1u<<table_width) - 1)];
value >>= table_width;
}
return num;
}
#if (((defined(BOOST_MSVC) && (BOOST_MSVC >= 1600)) || (defined(__clang__) && defined(__c2__)) || (defined(BOOST_INTEL) && defined(_MSC_VER))) && (defined(_M_IX86) || defined(_M_X64))) \
&& (defined(__POPCNT__) || defined(__AVX__))
template <>
BOOST_FORCEINLINE std::size_t popcount<unsigned short>(unsigned short value) BOOST_NOEXCEPT
{
return static_cast<std::size_t>(__popcnt16(value));
}
template <>
BOOST_FORCEINLINE std::size_t popcount<unsigned int>(unsigned int value) BOOST_NOEXCEPT
{
return static_cast<std::size_t>(__popcnt(value));
}
template <>
BOOST_FORCEINLINE std::size_t popcount<unsigned __int64>(unsigned __int64 value) BOOST_NOEXCEPT
{
#if defined(_M_X64)
return static_cast<std::size_t>(__popcnt64(value));
#else
return static_cast<std::size_t>(__popcnt(static_cast< unsigned int >(value))) + static_cast<std::size_t>(__popcnt(static_cast< unsigned int >(value >> 32)));
#endif
}
#elif defined(BOOST_GCC) || defined(__clang__) || (defined(BOOST_INTEL) && defined(__GNUC__))
// Note: gcc builtins are implemented by compiler runtime when the target CPU may not support the necessary instructions
template <>
BOOST_FORCEINLINE std::size_t popcount<unsigned short>(unsigned short value) BOOST_NOEXCEPT
{
return static_cast<unsigned int>(__builtin_popcount(static_cast<unsigned int>(value)));
}
template <>
BOOST_FORCEINLINE std::size_t popcount<unsigned int>(unsigned int value) BOOST_NOEXCEPT
{
return static_cast<unsigned int>(__builtin_popcount(value));
}
template <>
BOOST_FORCEINLINE std::size_t popcount<unsigned long>(unsigned long value) BOOST_NOEXCEPT
{
return static_cast<unsigned int>(__builtin_popcountl(value));
}
template <>
BOOST_FORCEINLINE std::size_t popcount<boost::ulong_long_type>(boost::ulong_long_type value) BOOST_NOEXCEPT
{
return static_cast<unsigned int>(__builtin_popcountll(value));
}
#endif
// overload for access by blocks
//
template <typename Iterator, typename ValueType>
inline std::size_t do_count(Iterator first, std::size_t length, ValueType,
value_to_type<access_by_blocks>*)
{
std::size_t num1 = 0u, num2 = 0u;
while (length >= 2u) {
num1 += popcount<ValueType>(*first);
++first;
num2 += popcount<ValueType>(*first);
++first;
length -= 2u;
}
if (length > 0u)
num1 += popcount<ValueType>(*first);
return num1 + num2;
}
// overload for access by bytes
//
template <typename Iterator>
inline std::size_t do_count(Iterator first, std::size_t length,
int /*dummy param*/,
value_to_type<access_by_bytes>*)
{
if (length > 0u) {
const byte_type* p = object_representation(&*first);
length *= sizeof(*first);
return do_count(p, length, static_cast<byte_type>(0u),
static_cast< value_to_type<access_by_blocks>* >(0));
}
return 0u;
}
// -------------------------------------------------------
// Some library implementations simply return a dummy
// value such as
//
// size_type(-1) / sizeof(T)
//
// from vector<>::max_size. This tries to get more
// meaningful info.
//
template <typename T>
inline typename T::size_type vector_max_size_workaround(const T & v)
BOOST_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);
const typename T::size_type container_max = v.max_size();
return alloc_max < container_max ? alloc_max : container_max;
}
// for static_asserts
template <typename T>
struct allowed_block_type {
enum { value = T(-1) > 0 }; // ensure T has no sign
};
template <>
struct allowed_block_type<bool> {
enum { value = false };
};
template <typename T>
struct is_numeric {
enum { value = false };
};
# define BOOST_dynamic_bitset_is_numeric(x) \
template<> \
struct is_numeric< x > { \
enum { value = true }; \
} /**/
BOOST_dynamic_bitset_is_numeric(bool);
BOOST_dynamic_bitset_is_numeric(char);
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
BOOST_dynamic_bitset_is_numeric(wchar_t);
#endif
BOOST_dynamic_bitset_is_numeric(signed char);
BOOST_dynamic_bitset_is_numeric(short int);
BOOST_dynamic_bitset_is_numeric(int);
BOOST_dynamic_bitset_is_numeric(long int);
BOOST_dynamic_bitset_is_numeric(unsigned char);
BOOST_dynamic_bitset_is_numeric(unsigned short);
BOOST_dynamic_bitset_is_numeric(unsigned int);
BOOST_dynamic_bitset_is_numeric(unsigned long);
#if defined(BOOST_HAS_LONG_LONG)
BOOST_dynamic_bitset_is_numeric(::boost::long_long_type);
BOOST_dynamic_bitset_is_numeric(::boost::ulong_long_type);
#endif
// intentionally omitted
//BOOST_dynamic_bitset_is_numeric(float);
//BOOST_dynamic_bitset_is_numeric(double);
//BOOST_dynamic_bitset_is_numeric(long double);
#undef BOOST_dynamic_bitset_is_numeric
} // dynamic_bitset_impl
} // namespace detail
} // namespace boost
#endif // include guard

View File

@@ -14,16 +14,16 @@
#ifndef BOOST_LOWEST_BIT_HPP_GP_20030301
#define BOOST_LOWEST_BIT_HPP_GP_20030301
#include <assert.h>
#include "boost/pending/integer_log2.hpp"
#include "boost/integer/integer_log2.hpp"
#include "boost/assert.hpp"
namespace boost {
namespace detail {
template <typename T>
int lowest_bit(T x) {
assert(x >= 1); // PRE
BOOST_ASSERT(x >= 1); // PRE
// clear all bits on except the rightmost one,
// then calculate the logarithm base 2
@@ -32,7 +32,7 @@ namespace boost {
}
}
}

View File

@@ -2,6 +2,13 @@
//
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
//
// Copyright (c) 2014 Glen Joseph Fernandes
// (glenjofe@gmail.com)
//
// Copyright (c) 2014 Riccardo Marcangelo
// Copyright (c) 2018 Evgeny Shulgin
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -16,6 +23,7 @@
#include <string>
#include <stdexcept>
#include <algorithm>
#include <iterator> // used to implement append(Iter, Iter)
#include <vector>
#include <climits> // for CHAR_BIT
@@ -34,11 +42,15 @@
#endif
#include "boost/dynamic_bitset_fwd.hpp"
#include "boost/detail/dynamic_bitset.hpp"
#include "boost/detail/iterator.hpp" // used to implement append(Iter, Iter)
#include "boost/static_assert.hpp"
#include "boost/dynamic_bitset/detail/dynamic_bitset.hpp"
#include "boost/dynamic_bitset/detail/lowest_bit.hpp"
#include "boost/move/move.hpp"
#include "boost/limits.hpp"
#include "boost/pending/lowest_bit.hpp"
#include "boost/static_assert.hpp"
#include "boost/core/addressof.hpp"
#include "boost/core/no_exceptions_support.hpp"
#include "boost/throw_exception.hpp"
#include "boost/functional/hash/hash.hpp"
namespace boost {
@@ -46,21 +58,22 @@ namespace boost {
template <typename Block, typename Allocator>
class dynamic_bitset
{
// Portability note: member function templates are defined inside
// this class definition to avoid problems with VC++. Similarly,
// with the member functions of nested classes.
//
// [October 2008: the note above is mostly historical; new versions
// of VC++ are likely able to digest a more drinking form of the
// code; but changing it now is probably not worth the risks...]
// Portability note: member function templates are defined inside
// this class definition to avoid problems with VC++. Similarly,
// with the member functions of nested classes.
//
// [October 2008: the note above is mostly historical; new versions
// of VC++ are likely able to digest a more drinking form of the
// code; but changing it now is probably not worth the risks...]
BOOST_STATIC_ASSERT(detail::dynamic_bitset_impl::allowed_block_type<Block>::value);
BOOST_STATIC_ASSERT((bool)detail::dynamic_bitset_impl::allowed_block_type<Block>::value);
typedef std::vector<Block, Allocator> buffer_type;
public:
typedef Block block_type;
typedef Allocator allocator_type;
typedef std::size_t size_type;
typedef block_type block_width_type;
typedef typename buffer_type::size_type block_width_type;
BOOST_STATIC_CONSTANT(block_width_type, bits_per_block = (std::numeric_limits<Block>::digits));
BOOST_STATIC_CONSTANT(size_type, npos = static_cast<size_type>(-1));
@@ -76,7 +89,7 @@ public:
// the one and only non-copy ctor
reference(block_type & b, block_type pos)
reference(block_type & b, block_width_type pos)
:m_block(b),
m_mask( (assert(pos < bits_per_block),
block_type(1) << pos )
@@ -115,8 +128,10 @@ public:
typedef bool const_reference;
// constructors, etc.
dynamic_bitset() : m_num_bits(0) {}
explicit
dynamic_bitset(const Allocator& alloc = Allocator());
dynamic_bitset(const Allocator& alloc);
explicit
dynamic_bitset(size_type num_bits, unsigned long value = 0,
@@ -207,12 +222,18 @@ public:
void swap(dynamic_bitset& b);
dynamic_bitset& operator=(const dynamic_bitset& b);
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
dynamic_bitset(dynamic_bitset&& src);
dynamic_bitset& operator=(dynamic_bitset&& src);
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
allocator_type get_allocator() const;
// size changing operations
void resize(size_type num_bits, bool value = false);
void clear();
void push_back(bool bit);
void pop_back();
void append(Block block);
template <typename BlockInputIterator>
@@ -226,7 +247,7 @@ public:
{
assert(first != last);
block_width_type r = count_extra_bits();
std::size_t d = boost::detail::distance(first, last);
std::size_t d = std::distance(first, last);
m_bits.reserve(num_blocks() + d);
if (r == 0) {
for( ; first != last; ++first)
@@ -246,7 +267,7 @@ public:
void append(BlockInputIterator first, BlockInputIterator last) // strong guarantee
{
if (first != last) {
typename detail::iterator_traits<BlockInputIterator>::iterator_category cat;
typename std::iterator_traits<BlockInputIterator>::iterator_category cat;
m_append(first, last, cat);
}
}
@@ -263,17 +284,24 @@ public:
dynamic_bitset operator>>(size_type n) const;
// basic bit operations
dynamic_bitset& set(size_type n, size_type len, bool val /* = true */); // default would make it ambiguous
dynamic_bitset& set(size_type n, bool val = true);
dynamic_bitset& set();
dynamic_bitset& reset(size_type n, size_type len);
dynamic_bitset& reset(size_type n);
dynamic_bitset& reset();
dynamic_bitset& flip(size_type n, size_type len);
dynamic_bitset& flip(size_type n);
dynamic_bitset& flip();
reference at(size_type n);
bool at(size_type n) const;
bool test(size_type n) const;
bool test_set(size_type n, bool val = true);
bool all() const;
bool any() const;
bool none() const;
dynamic_bitset operator~() const;
size_type count() const;
size_type count() const BOOST_NOEXCEPT;
// subscript
reference operator[](size_type pos) {
@@ -283,10 +311,13 @@ public:
unsigned long to_ulong() const;
size_type size() const;
size_type num_blocks() const;
size_type max_size() const;
bool empty() const;
size_type size() const BOOST_NOEXCEPT;
size_type num_blocks() const BOOST_NOEXCEPT;
size_type max_size() const BOOST_NOEXCEPT;
bool empty() const BOOST_NOEXCEPT;
size_type capacity() const BOOST_NOEXCEPT;
void reserve(size_type num_bits);
void shrink_to_fit();
bool is_subset_of(const dynamic_bitset& a) const;
bool is_proper_subset_of(const dynamic_bitset& a) const;
@@ -307,6 +338,10 @@ public:
friend bool operator<(const dynamic_bitset<B, A>& a,
const dynamic_bitset<B, A>& b);
template <typename B, typename A>
friend bool oplessthan(const dynamic_bitset<B, A>& a,
const dynamic_bitset<B, A>& b);
template <typename B, typename A, typename BlockOutputIterator>
friend void to_block_range(const dynamic_bitset<B, A>& b,
@@ -324,23 +359,76 @@ public:
template <typename B, typename A, typename stringT>
friend void to_string_helper(const dynamic_bitset<B, A> & b, stringT & s, bool dump_all);
template <typename B, typename A>
friend std::size_t hash_value(const dynamic_bitset<B, A>& a);
#endif
public:
// forward declaration for optional zero-copy serialization support
class serialize_impl;
friend class serialize_impl;
private:
BOOST_STATIC_CONSTANT(block_width_type, ulong_width = std::numeric_limits<unsigned long>::digits);
typedef std::vector<block_type, allocator_type> buffer_type;
dynamic_bitset& range_operation(size_type pos, size_type len,
Block (*partial_block_operation)(Block, size_type, size_type),
Block (*full_block_operation)(Block));
void m_zero_unused_bits();
bool m_check_invariants() const;
static bool m_not_empty(Block x){ return x != Block(0); };
size_type m_do_find_from(size_type first_block) const;
block_width_type count_extra_bits() const { return bit_index(size()); }
static size_type block_index(size_type pos) { return pos / bits_per_block; }
static block_width_type bit_index(size_type pos) { return static_cast<block_width_type>(pos % bits_per_block); }
static Block bit_mask(size_type pos) { return Block(1) << bit_index(pos); }
block_width_type count_extra_bits() const BOOST_NOEXCEPT { return bit_index(size()); }
static size_type block_index(size_type pos) BOOST_NOEXCEPT { return pos / bits_per_block; }
static block_width_type bit_index(size_type pos) BOOST_NOEXCEPT { return static_cast<block_width_type>(pos % bits_per_block); }
static Block bit_mask(size_type pos) BOOST_NOEXCEPT { return Block(1) << bit_index(pos); }
static Block bit_mask(size_type first, size_type last) BOOST_NOEXCEPT
{
Block res = (last == bits_per_block - 1)
? detail::dynamic_bitset_impl::max_limit<Block>::value
: ((Block(1) << (last + 1)) - 1);
res ^= (Block(1) << first) - 1;
return res;
}
static Block set_block_bits(Block block, size_type first,
size_type last, bool val) BOOST_NOEXCEPT
{
if (val)
return block | bit_mask(first, last);
else
return block & static_cast<Block>(~bit_mask(first, last));
}
// Functions for operations on ranges
inline static Block set_block_partial(Block block, size_type first,
size_type last) BOOST_NOEXCEPT
{
return set_block_bits(block, first, last, true);
}
inline static Block set_block_full(Block) BOOST_NOEXCEPT
{
return detail::dynamic_bitset_impl::max_limit<Block>::value;
}
inline static Block reset_block_partial(Block block, size_type first,
size_type last) BOOST_NOEXCEPT
{
return set_block_bits(block, first, last, false);
}
inline static Block reset_block_full(Block) BOOST_NOEXCEPT
{
return 0;
}
inline static Block flip_block_partial(Block block, size_type first,
size_type last) BOOST_NOEXCEPT
{
return block ^ bit_mask(first, last);
}
inline static Block flip_block_full(Block block) BOOST_NOEXCEPT
{
return ~block;
}
template <typename CharT, typename Traits, typename Alloc>
void init_from_string(const std::basic_string<CharT, Traits, Alloc>& s,
@@ -633,6 +721,34 @@ operator=(const dynamic_bitset<Block, Allocator>& b)
return *this;
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename Block, typename Allocator>
inline dynamic_bitset<Block, Allocator>::
dynamic_bitset(dynamic_bitset<Block, Allocator>&& b)
: m_bits(boost::move(b.m_bits)), m_num_bits(boost::move(b.m_num_bits))
{
// Required so that assert(m_check_invariants()); works.
assert((b.m_bits = buffer_type()).empty());
b.m_num_bits = 0;
}
template <typename Block, typename Allocator>
inline dynamic_bitset<Block, Allocator>& dynamic_bitset<Block, Allocator>::
operator=(dynamic_bitset<Block, Allocator>&& b)
{
if (boost::addressof(b) == this) { return *this; }
m_bits = boost::move(b.m_bits);
m_num_bits = boost::move(b.m_num_bits);
// Required so that assert(m_check_invariants()); works.
assert((b.m_bits = buffer_type()).empty());
b.m_num_bits = 0;
return *this;
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::allocator_type
dynamic_bitset<Block, Allocator>::get_allocator() const
@@ -651,7 +767,7 @@ resize(size_type num_bits, bool value) // strong guarantee
const size_type old_num_blocks = num_blocks();
const size_type required_blocks = calc_num_blocks(num_bits);
const block_type v = value? ~Block(0) : Block(0);
const block_type v = value? detail::dynamic_bitset_impl::max_limit<Block>::value : Block(0);
if (required_blocks != old_num_blocks) {
m_bits.resize(required_blocks, v); // s.g. (copy)
@@ -670,7 +786,7 @@ resize(size_type num_bits, bool value) // strong guarantee
if (value && (num_bits > m_num_bits)) {
const size_type extra_bits = count_extra_bits();
const block_width_type extra_bits = count_extra_bits();
if (extra_bits) {
assert(old_num_blocks >= 1 && old_num_blocks <= m_bits.size());
@@ -703,6 +819,22 @@ push_back(bool bit)
set(sz, bit);
}
template <typename Block, typename Allocator>
void dynamic_bitset<Block, Allocator>::
pop_back()
{
const size_type old_num_blocks = num_blocks();
const size_type required_blocks = calc_num_blocks(m_num_bits - 1);
if (required_blocks != old_num_blocks) {
m_bits.pop_back();
}
--m_num_bits;
m_zero_unused_bits();
}
template <typename Block, typename Allocator>
void dynamic_bitset<Block, Allocator>::
append(Block value) // strong guarantee
@@ -807,7 +939,7 @@ dynamic_bitset<Block, Allocator>::operator<<=(size_type n)
}
// zero out div blocks at the less significant end
std::fill_n(b, div, static_cast<block_type>(0));
std::fill_n(m_bits.begin(), div, static_cast<block_type>(0));
// zero out any 1 bit that flowed into the unused part
m_zero_unused_bits(); // thanks to Lester Gong
@@ -860,7 +992,7 @@ dynamic_bitset<B, A> & dynamic_bitset<B, A>::operator>>=(size_type n) {
// div blocks are zero filled at the most significant end
std::fill_n(b + (num_blocks()-div), div, static_cast<block_type>(0));
std::fill_n(m_bits.begin() + (num_blocks()-div), div, static_cast<block_type>(0));
}
return *this;
@@ -887,6 +1019,17 @@ dynamic_bitset<Block, Allocator>::operator>>(size_type n) const
//-----------------------------------------------------------------------------
// basic bit operations
template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>&
dynamic_bitset<Block, Allocator>::set(size_type pos,
size_type len, bool val)
{
if (val)
return range_operation(pos, len, set_block_partial, set_block_full);
else
return range_operation(pos, len, reset_block_partial, reset_block_full);
}
template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>&
dynamic_bitset<Block, Allocator>::set(size_type pos, bool val)
@@ -905,11 +1048,18 @@ template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>&
dynamic_bitset<Block, Allocator>::set()
{
std::fill(m_bits.begin(), m_bits.end(), ~Block(0));
std::fill(m_bits.begin(), m_bits.end(), detail::dynamic_bitset_impl::max_limit<Block>::value);
m_zero_unused_bits();
return *this;
}
template <typename Block, typename Allocator>
inline dynamic_bitset<Block, Allocator>&
dynamic_bitset<Block, Allocator>::reset(size_type pos, size_type len)
{
return range_operation(pos, len, reset_block_partial, reset_block_full);
}
template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>&
dynamic_bitset<Block, Allocator>::reset(size_type pos)
@@ -934,6 +1084,13 @@ dynamic_bitset<Block, Allocator>::reset()
return *this;
}
template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>&
dynamic_bitset<Block, Allocator>::flip(size_type pos, size_type len)
{
return range_operation(pos, len, flip_block_partial, flip_block_full);
}
template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>&
dynamic_bitset<Block, Allocator>::flip(size_type pos)
@@ -959,6 +1116,25 @@ bool dynamic_bitset<Block, Allocator>::m_unchecked_test(size_type pos) const
return (m_bits[block_index(pos)] & bit_mask(pos)) != 0;
}
template <typename Block, typename Allocator>
typename dynamic_bitset<Block, Allocator>::reference
dynamic_bitset<Block, Allocator>::at(size_type pos)
{
if (pos >= m_num_bits)
BOOST_THROW_EXCEPTION(std::out_of_range("boost::dynamic_bitset::at out_of_range"));
return (*this)[pos];
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::at(size_type pos) const
{
if (pos >= m_num_bits)
BOOST_THROW_EXCEPTION(std::out_of_range("boost::dynamic_bitset::at out_of_range"));
return (*this)[pos];
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::test(size_type pos) const
{
@@ -966,6 +1142,46 @@ bool dynamic_bitset<Block, Allocator>::test(size_type pos) const
return m_unchecked_test(pos);
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::test_set(size_type pos, bool val)
{
bool const b = test(pos);
if (b != val) {
set(pos, val);
}
return b;
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::all() const
{
if (empty()) {
return true;
}
const block_width_type extra_bits = count_extra_bits();
block_type const all_ones = detail::dynamic_bitset_impl::max_limit<Block>::value;
if (extra_bits == 0) {
for (size_type i = 0, e = num_blocks(); i < e; ++i) {
if (m_bits[i] != all_ones) {
return false;
}
}
} else {
for (size_type i = 0, e = num_blocks() - 1; i < e; ++i) {
if (m_bits[i] != all_ones) {
return false;
}
}
const block_type mask = (block_type(1) << extra_bits) - 1;
if (m_highest_block() != mask) {
return false;
}
}
return true;
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::any() const
{
@@ -992,7 +1208,7 @@ dynamic_bitset<Block, Allocator>::operator~() const
template <typename Block, typename Allocator>
typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::count() const
dynamic_bitset<Block, Allocator>::count() const BOOST_NOEXCEPT
{
using detail::dynamic_bitset_impl::table_width;
using detail::dynamic_bitset_impl::access_by_bytes;
@@ -1013,7 +1229,17 @@ dynamic_bitset<Block, Allocator>::count() const
enum { enough_table_width = table_width >= CHAR_BIT };
enum { mode = (no_padding && enough_table_width)
#if ((defined(BOOST_MSVC) && (BOOST_MSVC >= 1600)) || (defined(__clang__) && defined(__c2__)) || (defined(BOOST_INTEL) && defined(_MSC_VER))) && (defined(_M_IX86) || defined(_M_X64))
// Windows popcount is effective starting from the unsigned short type
enum { uneffective_popcount = sizeof(Block) < sizeof(unsigned short) };
#elif defined(BOOST_GCC) || defined(__clang__) || (defined(BOOST_INTEL) && defined(__GNUC__))
// GCC popcount is effective starting from the unsigned int type
enum { uneffective_popcount = sizeof(Block) < sizeof(unsigned int) };
#else
enum { uneffective_popcount = true };
#endif
enum { mode = (no_padding && enough_table_width && uneffective_popcount)
? access_by_bytes
: access_by_blocks };
@@ -1101,17 +1327,17 @@ to_ulong() const
// Check for overflows. This may be a performance burden on very
// large bitsets but is required by the specification, sorry
if (find_next(ulong_width - 1) != npos)
throw std::overflow_error("boost::dynamic_bitset::to_ulong overflow");
BOOST_THROW_EXCEPTION(std::overflow_error("boost::dynamic_bitset::to_ulong overflow"));
// Ok, from now on we can be sure there's no "on" bit
// beyond the "allowed" positions
typedef unsigned long result_type;
const size_type max_size =
const size_type maximum_size =
(std::min)(m_num_bits, static_cast<size_type>(ulong_width));
const size_type last_block = block_index( max_size - 1 );
const size_type last_block = block_index( maximum_size - 1 );
assert((last_block * bits_per_block) < static_cast<size_type>(ulong_width));
@@ -1126,21 +1352,21 @@ to_ulong() const
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::size() const
dynamic_bitset<Block, Allocator>::size() const BOOST_NOEXCEPT
{
return m_num_bits;
}
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::num_blocks() const
dynamic_bitset<Block, Allocator>::num_blocks() const BOOST_NOEXCEPT
{
return m_bits.size();
}
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::max_size() const
dynamic_bitset<Block, Allocator>::max_size() const BOOST_NOEXCEPT
{
// Semantics of vector<>::max_size() aren't very clear
// (see lib issue 197) and many library implementations
@@ -1161,11 +1387,32 @@ dynamic_bitset<Block, Allocator>::max_size() const
}
template <typename Block, typename Allocator>
inline bool dynamic_bitset<Block, Allocator>::empty() const
inline bool dynamic_bitset<Block, Allocator>::empty() const BOOST_NOEXCEPT
{
return size() == 0;
}
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::capacity() const BOOST_NOEXCEPT
{
return m_bits.capacity() * bits_per_block;
}
template <typename Block, typename Allocator>
inline void dynamic_bitset<Block, Allocator>::reserve(size_type num_bits)
{
m_bits.reserve(calc_num_blocks(num_bits));
}
template <typename Block, typename Allocator>
void dynamic_bitset<Block, Allocator>::shrink_to_fit()
{
if (m_bits.size() < m_bits.capacity()) {
buffer_type(m_bits).swap(m_bits);
}
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::
is_subset_of(const dynamic_bitset<Block, Allocator>& a) const
@@ -1213,25 +1460,22 @@ bool dynamic_bitset<Block, Allocator>::intersects(const dynamic_bitset & b) cons
// --------------------------------
// lookup
// look for the first bit "on", starting
// from the block with index first_block
//
template <typename Block, typename Allocator>
typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::m_do_find_from(size_type first_block) const
{
size_type i = first_block;
// skip null blocks
while (i < num_blocks() && m_bits[i] == 0)
++i;
size_type i = std::distance(m_bits.begin(),
std::find_if(m_bits.begin() + first_block, m_bits.end(), m_not_empty) );
if (i >= num_blocks())
return npos; // not found
return i * bits_per_block + boost::lowest_bit(m_bits[i]);
return i * bits_per_block + static_cast<size_type>(detail::lowest_bit(m_bits[i]));
}
@@ -1257,11 +1501,11 @@ dynamic_bitset<Block, Allocator>::find_next(size_type pos) const
const size_type blk = block_index(pos);
const block_width_type ind = bit_index(pos);
// mask out bits before pos
const Block fore = m_bits[blk] & ( ~Block(0) << ind );
// shift bits upto one immediately after current
const Block fore = m_bits[blk] >> ind;
return fore?
blk * bits_per_block + lowest_bit(fore)
pos + static_cast<size_type>(detail::lowest_bit(fore))
:
m_do_find_from(blk + 1);
@@ -1291,23 +1535,95 @@ template <typename Block, typename Allocator>
bool operator<(const dynamic_bitset<Block, Allocator>& a,
const dynamic_bitset<Block, Allocator>& b)
{
assert(a.size() == b.size());
typedef typename dynamic_bitset<Block, Allocator>::size_type size_type;
// assert(a.size() == b.size());
//if (a.size() == 0)
// return false;
typedef BOOST_DEDUCED_TYPENAME dynamic_bitset<Block, Allocator>::size_type size_type;
size_type asize(a.size());
size_type bsize(b.size());
// Since we are storing the most significant bit
// at pos == size() - 1, we need to do the comparisons in reverse.
//
for (size_type ii = a.num_blocks(); ii > 0; --ii) {
size_type i = ii-1;
if (a.m_bits[i] < b.m_bits[i])
return true;
else if (a.m_bits[i] > b.m_bits[i])
if (!bsize)
{
return false;
}
return false;
}
else if (!asize)
{
return true;
}
else if (asize == bsize)
{
for (size_type ii = a.num_blocks(); ii > 0; --ii)
{
size_type i = ii-1;
if (a.m_bits[i] < b.m_bits[i])
return true;
else if (a.m_bits[i] > b.m_bits[i])
return false;
}
return false;
}
else
{
size_type leqsize(std::min BOOST_PREVENT_MACRO_SUBSTITUTION(asize,bsize));
for (size_type ii = 0; ii < leqsize; ++ii,--asize,--bsize)
{
size_type i = asize-1;
size_type j = bsize-1;
if (a[i] < b[j])
return true;
else if (a[i] > b[j])
return false;
}
return (a.size() < b.size());
}
}
template <typename Block, typename Allocator>
bool oplessthan(const dynamic_bitset<Block, Allocator>& a,
const dynamic_bitset<Block, Allocator>& b)
{
// assert(a.size() == b.size());
typedef BOOST_DEDUCED_TYPENAME dynamic_bitset<Block, Allocator>::size_type size_type;
size_type asize(a.num_blocks());
size_type bsize(b.num_blocks());
assert(asize == 3);
assert(bsize == 4);
if (!bsize)
{
return false;
}
else if (!asize)
{
return true;
}
else
{
size_type leqsize(std::min BOOST_PREVENT_MACRO_SUBSTITUTION(asize,bsize));
assert(leqsize == 3);
//if (a.size() == 0)
// return false;
// Since we are storing the most significant bit
// at pos == size() - 1, we need to do the comparisons in reverse.
//
for (size_type ii = 0; ii < leqsize; ++ii,--asize,--bsize)
{
size_type i = asize-1;
size_type j = bsize-1;
if (a.m_bits[i] < b.m_bits[j])
return true;
else if (a.m_bits[i] > b.m_bits[j])
return false;
}
return (a.num_blocks() < b.num_blocks());
}
}
template <typename Block, typename Allocator>
@@ -1331,6 +1647,17 @@ inline bool operator>=(const dynamic_bitset<Block, Allocator>& a,
return !(a < b);
}
//-----------------------------------------------------------------------------
// hash operations
template <typename Block, typename Allocator>
inline std::size_t hash_value(const dynamic_bitset<Block, Allocator>& a)
{
std::size_t res = hash_value(a.m_num_bits);
boost::hash_combine(res, a.m_bits);
return res;
}
//-----------------------------------------------------------------------------
// stream operations
@@ -1422,19 +1749,20 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
const Ch zero = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '0');
const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1');
try {
BOOST_TRY {
typedef typename dynamic_bitset<Block, Alloc>::size_type bitsetsize_type;
typedef typename dynamic_bitset<Block, Alloc>::size_type bitset_size_type;
typedef basic_streambuf<Ch, Tr> buffer_type;
buffer_type * buf = os.rdbuf();
size_t npad = os.width() <= 0 // careful: os.width() is signed (and can be < 0)
|| (bitsetsize_type) os.width() <= b.size()? 0 : os.width() - b.size();
// careful: os.width() is signed (and can be < 0)
const bitset_size_type width = (os.width() <= 0) ? 0 : static_cast<bitset_size_type>(os.width());
streamsize npad = (width <= b.size()) ? 0 : width - b.size();
const Ch fill_char = os.fill();
const ios_base::fmtflags adjustfield = os.flags() & ios_base::adjustfield;
// if needed fill at left; pad is decresed along the way
// if needed fill at left; pad is decreased along the way
if (adjustfield != ios_base::left) {
for (; 0 < npad; --npad)
if (Tr::eq_int_type(Tr::eof(), buf->sputc(fill_char))) {
@@ -1445,7 +1773,7 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
if (err == ok) {
// output the bitset
for (bitsetsize_type i = b.size(); 0 < i; --i) {
for (bitset_size_type i = b.size(); 0 < i; --i) {
typename buffer_type::int_type
ret = buf->sputc(b.test(i-1)? one : zero);
if (Tr::eq_int_type(Tr::eof(), ret)) {
@@ -1468,13 +1796,14 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
os.width(0);
} catch (...) { // see std 27.6.1.1/4
} BOOST_CATCH (...) { // see std 27.6.1.1/4
bool rethrow = false;
try { os.setstate(ios_base::failbit); } catch (...) { rethrow = true; }
BOOST_TRY { os.setstate(ios_base::failbit); } BOOST_CATCH (...) { rethrow = true; } BOOST_CATCH_END
if (rethrow)
throw;
BOOST_RETHROW;
}
BOOST_CATCH_END
}
if(err != ok)
@@ -1520,7 +1849,7 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
const std::streamsize w = is.width();
const size_type limit = w > 0 && static_cast<size_type>(w) < b.max_size()
? w : b.max_size();
? static_cast<size_type>(w) : b.max_size();
typename bitset_type::bit_appender appender(b);
std::streambuf * buf = is.rdbuf();
for(int c = buf->sgetc(); appender.get_count() < limit; c = buf->snextc() ) {
@@ -1533,13 +1862,14 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
break; // non digit character
else {
try {
BOOST_TRY {
appender.do_append(char(c) == '1');
}
catch(...) {
BOOST_CATCH(...) {
is.setstate(std::ios::failbit); // assume this can't throw
throw;
BOOST_RETHROW;
}
BOOST_CATCH_END
}
} // for
@@ -1568,7 +1898,7 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
const streamsize w = is.width();
const size_type limit = 0 < w && static_cast<size_type>(w) < b.max_size()?
w : b.max_size();
static_cast<size_type>(w) : b.max_size();
ios_base::iostate err = ios_base::goodbit;
typename basic_istream<Ch, Tr>::sentry cerberos(is); // skips whitespaces
@@ -1580,7 +1910,7 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1');
b.clear();
try {
BOOST_TRY {
typename bitset_type::bit_appender appender(b);
basic_streambuf <Ch, Tr> * buf = is.rdbuf();
typename Tr::int_type c = buf->sgetc();
@@ -1603,7 +1933,7 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
} // for
}
catch (...) {
BOOST_CATCH (...) {
// catches from stream buf, or from vector:
//
// bits_stored bits have been extracted and stored, and
@@ -1611,13 +1941,15 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
// append to the underlying vector (out of memory)
bool rethrow = false; // see std 27.6.1.1/4
try { is.setstate(ios_base::badbit); }
catch(...) { rethrow = true; }
BOOST_TRY { is.setstate(ios_base::badbit); }
BOOST_CATCH(...) { rethrow = true; }
BOOST_CATCH_END
if (rethrow)
throw;
BOOST_RETHROW;
}
BOOST_CATCH_END
}
is.width(0);
@@ -1694,7 +2026,7 @@ inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::calc_num_blocks(size_type num_bits)
{
return num_bits / bits_per_block
+ static_cast<int>( num_bits % bits_per_block != 0 );
+ static_cast<size_type>( num_bits % bits_per_block != 0 );
}
// gives a reference to the highest block
@@ -1715,6 +2047,63 @@ inline const Block& dynamic_bitset<Block, Allocator>::m_highest_block() const
return m_bits.back();
}
template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>& dynamic_bitset<Block, Allocator>::range_operation(
size_type pos, size_type len,
Block (*partial_block_operation)(Block, size_type, size_type),
Block (*full_block_operation)(Block))
{
assert(pos + len <= m_num_bits);
// Do nothing in case of zero length
if (!len)
return *this;
// Use an additional asserts in order to detect size_type overflow
// For example: pos = 10, len = size_type_limit - 2, pos + len = 7
// In case of overflow, 'pos + len' is always smaller than 'len'
assert(pos + len >= len);
// Start and end blocks of the [pos; pos + len - 1] sequence
const size_type first_block = block_index(pos);
const size_type last_block = block_index(pos + len - 1);
const size_type first_bit_index = bit_index(pos);
const size_type last_bit_index = bit_index(pos + len - 1);
if (first_block == last_block) {
// Filling only a sub-block of a block
m_bits[first_block] = partial_block_operation(m_bits[first_block],
first_bit_index, last_bit_index);
} else {
// Check if the corner blocks won't be fully filled with 'val'
const size_type first_block_shift = bit_index(pos) ? 1 : 0;
const size_type last_block_shift = (bit_index(pos + len - 1)
== bits_per_block - 1) ? 0 : 1;
// Blocks that will be filled with ~0 or 0 at once
const size_type first_full_block = first_block + first_block_shift;
const size_type last_full_block = last_block - last_block_shift;
for (size_type i = first_full_block; i <= last_full_block; ++i) {
m_bits[i] = full_block_operation(m_bits[i]);
}
// Fill the first block from the 'first' bit index to the end
if (first_block_shift) {
m_bits[first_block] = partial_block_operation(m_bits[first_block],
first_bit_index, bits_per_block - 1);
}
// Fill the last block from the start to the 'last' bit index
if (last_block_shift) {
m_bits[last_block] = partial_block_operation(m_bits[last_block],
0, last_bit_index);
}
}
return *this;
}
// If size() is not a multiple of bits_per_block
// then not all the bits in the last block are used.
@@ -1730,8 +2119,7 @@ inline void dynamic_bitset<Block, Allocator>::m_zero_unused_bits()
const block_width_type extra_bits = count_extra_bits();
if (extra_bits != 0)
m_highest_block() &= ~(~static_cast<Block>(0) << extra_bits);
m_highest_block() &= (Block(1) << extra_bits) - 1;
}
// check class invariants
@@ -1740,7 +2128,7 @@ bool dynamic_bitset<Block, Allocator>::m_check_invariants() const
{
const block_width_type extra_bits = count_extra_bits();
if (extra_bits > 0) {
block_type const mask = (~static_cast<Block>(0) << extra_bits);
const block_type mask = detail::dynamic_bitset_impl::max_limit<Block>::value << extra_bits;
if ((m_highest_block() & mask) != 0)
return false;
}
@@ -1754,8 +2142,26 @@ bool dynamic_bitset<Block, Allocator>::m_check_invariants() const
} // namespace boost
#undef BOOST_BITSET_CHAR
// std::hash support
#if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) && !defined(BOOST_DYNAMIC_BITSET_NO_STD_HASH)
#include <functional>
namespace std
{
template<typename Block, typename Allocator>
struct hash< boost::dynamic_bitset<Block, Allocator> >
{
typedef boost::dynamic_bitset<Block, Allocator> argument_type;
typedef std::size_t result_type;
result_type operator()(const argument_type& a) const BOOST_NOEXCEPT
{
boost::hash<argument_type> hasher;
return hasher(a);
}
};
}
#endif
#endif // include guard

View File

@@ -0,0 +1,46 @@
// -----------------------------------------------------------
//
// Copyright (c) 2015 Seth Heeren
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
#ifndef BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
#define BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include <boost/core/nvp.hpp>
namespace boost {
// implementation for optional zero-copy serialization support
template <typename Block, typename Allocator>
class dynamic_bitset<Block, Allocator>::serialize_impl
{
public:
template <typename Ar>
static void serialize(Ar& ar, dynamic_bitset<Block, Allocator>& bs, unsigned) {
ar & boost::make_nvp("m_num_bits", bs.m_num_bits)
& boost::make_nvp("m_bits", bs.m_bits);
}
};
}
// ADL hook to Boost Serialization library
namespace boost {
namespace serialization {
template <typename Ar, typename Block, typename Allocator>
void serialize(Ar& ar, dynamic_bitset<Block, Allocator>& bs, unsigned version) {
dynamic_bitset<Block, Allocator>::serialize_impl::serialize(ar, bs, version);
}
} // namespace serialization
} // namespace boost
#endif // include guard

17
meta/libraries.json Normal file
View File

@@ -0,0 +1,17 @@
{
"key": "dynamic_bitset",
"name": "Dynamic Bitset",
"authors": [
"Jeremy Siek",
"Chuck Allison"
],
"description": "The dynamic_bitset class represents a set of bits. It provides accesses to the value of individual bits via an operator[] and provides all of the bitwise operators that one can apply to builtin integers, such as operator& and operator<<. The number of bits in the set is specified at runtime via a parameter to the constructor of the dynamic_bitset.",
"documentation": "dynamic_bitset.html",
"category": [
"Containers"
],
"maintainers": [
"Jeremy Siek <jeremy.siek -at- gmail.com>"
],
"cxxstd": "03"
}

42
test/Jamfile.v2 Normal file
View File

@@ -0,0 +1,42 @@
#
# Copyright Vladimir Prus 2004
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
import os ;
# import rules for testing conditional on config file variables
import ../../config/checks/config : requires ;
test-suite dynamic_bitset :
[ run dyn_bitset_unit_tests1.cpp : : : <library>/boost/system//boost_system ]
[ run dyn_bitset_unit_tests2.cpp : : : <library>/boost/system//boost_system ]
[ run dyn_bitset_unit_tests3.cpp : : : <library>/boost/system//boost_system ]
[ run dyn_bitset_unit_tests4.cpp : : : <library>/boost/filesystem//boost_filesystem
<library>/boost/system//boost_system ]
[ run test_ambiguous_set.cpp ]
[ run test_lowest_bit.cpp ]
[ run test_boost_hash.cpp ]
[ run test_std_hash.cpp : : : [ requires cxx11_hdr_unordered_set ] ]
[ compile-fail test_std_hash.cpp : [ requires cxx11_hdr_unordered_set ]
<define>BOOST_DYNAMIC_BITSET_NO_STD_HASH
: test_std_hash_disabled ]
;
# due to https://github.com/boostorg/serialization/issues/108
if ! [ os.environ UBSAN_OPTIONS ]
{
test-suite dynamic_bitset_serialization :
[ run dyn_bitset_unit_tests5.cpp
: : : <define>_SCL_SECURE_NO_WARNINGS=1
<library>/boost/serialization//boost_serialization
<library>/boost/system//boost_system ]
;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,11 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2014 Riccardo Marcangelo
//
// Copyright (c) 2014 Glen Joseph Fernandes
// (glenjofe@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,11 +14,38 @@
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/limits.hpp"
#include "boost/config.hpp"
#include <boost/dynamic_bitset/dynamic_bitset.hpp>
#include <boost/limits.hpp>
#include <boost/config.hpp>
#include "boost/detail/workaround.hpp"
#include <boost/config/workaround.hpp>
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#include <cstdlib>
template<class T>
class minimal_allocator {
public:
typedef T value_type;
minimal_allocator() {}
template <typename U>
minimal_allocator(const minimal_allocator<U>&) {}
T* allocate(std::size_t n) {
void* p = std::malloc(sizeof(T) * n);
if (!p) {
throw std::bad_alloc();
}
return static_cast<T*>(p);
}
void deallocate(T* p, std::size_t) {
std::free(p);
}
};
#endif
#define BOOST_BITSET_TEST_COUNT(x) (sizeof(x)/sizeof(x[0]))
@@ -71,8 +103,8 @@ void run_numeric_ctor_tests( BOOST_EXPLICIT_TEMPLATE_TYPE(Tests)
};
const T numbers[] = {
T(-1), T(-3), T(-8), T(-15), mi/2, mi,
0, 1, 3, 8, 15, ma/2, ma
T(-1), T(-3), T(-8), T(-15), T(mi/2), T(mi),
T(0), T(1), T(3), T(8), T(15), T(ma/2), T(ma)
};
for (std::size_t s = 0; s < BOOST_BITSET_TEST_COUNT(sizes); ++s) {
@@ -117,9 +149,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
//=====================================================================
// Test construction from unsigned long
{
typedef typename bitset_type::size_type size_type;
// NOTE:
//
// 1. keep this in sync with the numeric types supported
@@ -240,29 +269,70 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::copy_constructor(b);
}
//=====================================================================
// Test assignment operator
// Test copy assignment operator
{
bitset_type a, b;
Tests::assignment_operator(a, b);
Tests::copy_assignment_operator(a, b);
}
{
bitset_type a(std::string("1")), b(std::string("0"));
Tests::assignment_operator(a, b);
Tests::copy_assignment_operator(a, b);
}
{
bitset_type a(long_string), b(long_string);
Tests::assignment_operator(a, b);
Tests::copy_assignment_operator(a, b);
}
{
bitset_type a;
bitset_type b(long_string); // b greater than a, a empty
Tests::assignment_operator(a, b);
Tests::copy_assignment_operator(a, b);
}
{
bitset_type a(std::string("0"));
bitset_type b(long_string); // b greater than a
Tests::assignment_operator(a, b);
Tests::copy_assignment_operator(a, b);
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
//=====================================================================
// Test move constructor
{
boost::dynamic_bitset<Block> b;
Tests::move_constructor(b);
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::move_constructor(b);
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::move_constructor(b);
}
//=====================================================================
// Test move assignment operator
{
bitset_type a, b;
Tests::move_assignment_operator(a, b);
}
{
bitset_type a(std::string("1")), b(std::string("0"));
Tests::move_assignment_operator(a, b);
}
{
bitset_type a(long_string), b(long_string);
Tests::move_assignment_operator(a, b);
}
{
bitset_type a;
bitset_type b(long_string); // b greater than a, a empty
Tests::move_assignment_operator(a, b);
}
{
bitset_type a(std::string("0"));
bitset_type b(long_string); // b greater than a
Tests::move_assignment_operator(a, b);
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
//=====================================================================
// Test swap
{
@@ -315,6 +385,25 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::clear(a);
}
//=====================================================================
// Test pop back
{
boost::dynamic_bitset<Block> a(std::string("01"));
Tests::pop_back(a);
}
{
boost::dynamic_bitset<Block> a(std::string("10"));
Tests::pop_back(a);
}
{
const int size_to_fill_all_blocks = 4 * bits_per_block;
boost::dynamic_bitset<Block> a(size_to_fill_all_blocks, 255ul);
Tests::pop_back(a);
}
{
boost::dynamic_bitset<Block> a(long_string);
Tests::pop_back(a);
}
//=====================================================================
// Test append bit
{
boost::dynamic_bitset<Block> a;
@@ -420,10 +509,43 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
bit_vec[i] = long_string[n - 1 - i] == '0' ? 0 : 1;
Tests::operator_bracket(b, bit_vec);
}
//=====================================================================
// Test at
{
boost::dynamic_bitset<Block> b1;
std::vector<bool> bitvec1;
Tests::at(b1, bitvec1);
}
{
boost::dynamic_bitset<Block> b(std::string("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);
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);
}
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
{
typedef boost::dynamic_bitset<Block,
minimal_allocator<Block> > Bitset;
Bitset b;
bitset_test<Bitset>::max_size(b);
}
#endif
// Test copy-initialize with default constructor
{
boost::dynamic_bitset<Block> b[1] = {};
(void)b;
}
}
int
test_main(int, char*[])
main()
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
@@ -433,5 +555,5 @@ test_main(int, char*[])
run_test_cases< ::boost::ulong_long_type>();
# endif
return 0;
return boost::report_errors();
}

View File

@@ -1,6 +1,8 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2018 Evgeny Shulgin
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,8 +11,8 @@
// -----------------------------------------------------------
#include "bitset_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/config.hpp"
#include <boost/dynamic_bitset/dynamic_bitset.hpp>
#include <boost/config.hpp>
template <typename Block>
@@ -194,14 +196,51 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
{ // case pos >= b.size()
boost::dynamic_bitset<Block> b;
Tests::set_one(b, 0, true);
Tests::set_one(b, 0, false);
}
{ // case pos < b.size()
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::set_one(b, 0, true);
Tests::set_one(b, 0, false);
}
{ // case pos == b.size() / 2
boost::dynamic_bitset<Block> b(long_string);
Tests::set_one(b, long_string.size()/2, true);
Tests::set_one(b, long_string.size()/2, false);
}
//=====================================================================
// Test b.set(pos, len)
{ // case size is 1
boost::dynamic_bitset<Block> 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);
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);
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);
}
{ // case pos = 1, len = size - 2
boost::dynamic_bitset<Block> 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);
Tests::set_segment(b, 3, 7, true);
Tests::set_segment(b, 3, 7, false);
}
//=====================================================================
// Test b.reset()
@@ -232,6 +271,33 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
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"));
Tests::reset_segment(b, 0, 1);
}
{ // case fill the whole set
boost::dynamic_bitset<Block> b(long_string);
Tests::reset_segment(b, 0, b.size());
}
{ // case pos = size / 4, len = size / 2
boost::dynamic_bitset<Block> 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);
}
{ // case pos = 1, len = size - 2
boost::dynamic_bitset<Block> b(long_string);
Tests::reset_segment(b, 1, b.size() - 2);
}
{ // case pos = 3, len = 7
boost::dynamic_bitset<Block> b(long_string);
Tests::reset_segment(b, 3, 7);
}
//=====================================================================
// Test ~b
{
boost::dynamic_bitset<Block> b;
@@ -273,10 +339,37 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
boost::dynamic_bitset<Block> 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"));
Tests::flip_segment(b, 0, 1);
}
{ // case fill the whole set
boost::dynamic_bitset<Block> b(long_string);
Tests::flip_segment(b, 0, b.size());
}
{ // case pos = size / 4, len = size / 2
boost::dynamic_bitset<Block> 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);
}
{ // case pos = 1, len = size - 2
boost::dynamic_bitset<Block> b(long_string);
Tests::flip_segment(b, 1, b.size() - 2);
}
{ // case pos = 3, len = 7
boost::dynamic_bitset<Block> b(long_string);
Tests::flip_segment(b, 3, 7);
}
}
int
test_main(int, char*[])
main()
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
@@ -286,5 +379,5 @@ test_main(int, char*[])
run_test_cases< ::boost::ulong_long_type>();
# endif
return 0;
return boost::report_errors();
}

View File

@@ -1,6 +1,8 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
// Copyright (c) 2014 Riccardo Marcangelo
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -10,10 +12,9 @@
#include <assert.h>
#include "bitset_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/limits.hpp"
#include "boost/config.hpp"
#include <boost/dynamic_bitset/dynamic_bitset.hpp>
#include <boost/limits.hpp>
#include <boost/config.hpp>
template <typename Block>
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
@@ -121,32 +122,103 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::size(b);
}
//=====================================================================
// Test b.capacity()
{
boost::dynamic_bitset<Block> b;
Tests::capacity_test_one(b);
}
{
boost::dynamic_bitset<Block> b(100);
Tests::capacity_test_two(b);
}
//=====================================================================
// Test b.reserve()
{
boost::dynamic_bitset<Block> b;
Tests::reserve_test_one(b);
}
{
boost::dynamic_bitset<Block> b(100);
Tests::reserve_test_two(b);
}
//=====================================================================
// Test b.shrink_to_fit()
{
boost::dynamic_bitset<Block> b;
Tests::shrink_to_fit_test_one(b);
}
{
boost::dynamic_bitset<Block> b(100);
Tests::shrink_to_fit_test_two(b);
}
//=====================================================================
// Test b.all()
{
boost::dynamic_bitset<Block> b;
Tests::all(b);
Tests::all(~b);
Tests::all(b.set());
Tests::all(b.reset());
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::all(b);
Tests::all(~b);
Tests::all(b.set());
Tests::all(b.reset());
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::all(b);
Tests::all(~b);
Tests::all(b.set());
Tests::all(b.reset());
}
//=====================================================================
// Test b.any()
{
boost::dynamic_bitset<Block> b;
Tests::any(b);
Tests::any(~b);
Tests::any(b.set());
Tests::any(b.reset());
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::any(b);
Tests::any(~b);
Tests::any(b.set());
Tests::any(b.reset());
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::any(b);
Tests::any(~b);
Tests::any(b.set());
Tests::any(b.reset());
}
//=====================================================================
// Test b.none()
{
boost::dynamic_bitset<Block> b;
Tests::none(b);
Tests::none(~b);
Tests::none(b.set());
Tests::none(b.reset());
}
{
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::none(b);
Tests::none(~b);
Tests::none(b.set());
Tests::none(b.reset());
}
{
boost::dynamic_bitset<Block> b(long_string);
Tests::none(b);
Tests::none(~b);
Tests::none(b.set());
Tests::none(b.reset());
}
//=====================================================================
// Test a.is_subset_of(b)
@@ -404,6 +476,14 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
boost::dynamic_bitset<Block> 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"));
Tests::operator_less_than(a, b);
}
{
boost::dynamic_bitset<Block> a(std::string("10")), b(std::string("111"));
Tests::operator_less_than(a, b);
}
{
boost::dynamic_bitset<Block> a(long_string), b(long_string);
Tests::operator_less_than(a, b);
@@ -418,7 +498,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
b[long_string.size()/2].flip();
Tests::operator_less_than(a, b);
}
// check for consistency with ulong behaviour
// check for consistency with ulong behaviour when the sizes are equal
{
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
assert(a < b);
@@ -431,6 +511,31 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
assert(!(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);
assert(a < b);
}
{
boost::dynamic_bitset<Block> a(3, 4ul), b(4, 5ul);
assert(!(a < b));
}
{
boost::dynamic_bitset<Block> a(4, 4ul), b(3, 4ul);
assert(a < b);
}
{
boost::dynamic_bitset<Block> a(3, 4ul), b(4, 4ul);
assert(!(a < b));
}
{
boost::dynamic_bitset<Block> a(4, 5ul), b(3, 4ul);
assert(a < b);
}
{
boost::dynamic_bitset<Block> a(3, 5ul), b(4, 4ul);
assert(!(a < b));
}
//=====================================================================
// Test operator<=
{
@@ -569,6 +674,23 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::test_bit(b, long_string.size()/2);
}
//=====================================================================
// Test b.test_set(pos)
{ // case pos >= b.size()
boost::dynamic_bitset<Block> b;
Tests::test_set_bit(b, 0, true);
Tests::test_set_bit(b, 0, false);
}
{ // case pos < b.size()
boost::dynamic_bitset<Block> b(std::string("0"));
Tests::test_set_bit(b, 0, true);
Tests::test_set_bit(b, 0, false);
}
{ // case pos == b.size() / 2
boost::dynamic_bitset<Block> b(long_string);
Tests::test_set_bit(b, long_string.size() / 2, true);
Tests::test_set_bit(b, long_string.size() / 2, false);
}
//=====================================================================
// Test b << pos
{ // case pos == 0
std::size_t pos = 0;
@@ -676,8 +798,9 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
}
}
int
test_main(int, char*[])
main()
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
@@ -687,5 +810,5 @@ test_main(int, char*[])
run_test_cases< ::boost::ulong_long_type>();
# endif
return 0;
return boost::report_errors();
}

View File

@@ -14,14 +14,14 @@
#include <stdexcept> // for std::logic_error
#include <assert.h>
#include "boost/config.hpp"
#include <boost/config.hpp>
#if !defined (BOOST_NO_STRINGSTREAM)
# include <sstream>
#endif
#include "bitset_test.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/detail/workaround.hpp"
#include <boost/dynamic_bitset/dynamic_bitset.hpp>
#include <boost/config/workaround.hpp>
// Codewarrior 8.3 for Win fails without this.
@@ -125,13 +125,13 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
}
{
// test 1a - file stream
scoped_temp_file stf;
bitset_type b(strings[si]);
std::ofstream file(test_file_name(), std::ios::trunc);
std::ofstream file(stf.path().string().c_str(), std::ios::trunc);
file.width(w);
file.fill(fill_chars[ci]);
file.exceptions(masks[mi]);
Tests::stream_inserter(b, file, test_file_name());
Tests::stream_inserter(b, file, stf.path().string().c_str());
}
{
//NOTE: there are NO string stream tests
@@ -139,12 +139,13 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
#if !defined (BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS)
{
// test 1b - wide file stream
scoped_temp_file stf;
bitset_type b(strings[si]);
std::wofstream file(test_file_name());
std::wofstream file(stf.path().string().c_str());
file.width(w);
file.fill(fill_chars[ci]);
file.exceptions(masks[mi]);
Tests::stream_inserter(b, file, test_file_name());
Tests::stream_inserter(b, file, stf.path().string().c_str());
}
#endif
}
@@ -176,11 +177,11 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
std::ios::iostate masks[] = {
std::ios::goodbit,
std::ios::eofbit,
std::ios::failbit,
std::ios::eofbit | std::ios::failbit
};
std::ios::goodbit,
std::ios::eofbit,
std::ios::failbit,
std::ios::eofbit | std::ios::failbit
};
const std::string spaces = "\t\n "; //"\t\n\v\f ";
@@ -190,7 +191,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
// (in Tests::stream_extractor instantiation)
#if !(defined __BORLANDC__ \
#if !(defined BOOST_BORLANDC \
&& BOOST_WORKAROUND(BOOST_RWSTD_VER, BOOST_TESTED_AT(0x20101)))
// Borland 5.5.1 with RW library crashes
// empty string
@@ -257,13 +258,14 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
}
// test 1a - (narrow) file stream
{
scoped_temp_file stf;
bitset_type b(1, 255ul);
{
std::ofstream f(test_file_name());
std::ofstream f(stf.path().string().c_str());
f << strings[si];
}
std::ifstream f(test_file_name());
std::ifstream f(stf.path().string().c_str());
f.width(w);
f.exceptions(masks[mi]);
Tests::stream_extractor(b, f, strings[si]);
@@ -282,14 +284,15 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
#if !defined(BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS)
// test 1b - wchar_t file stream
{
scoped_temp_file stf;
std::wstring wstr = widen_string(strings[si]);
bitset_type b(1, 255ul);
{
std::basic_ofstream<wchar_t> of(test_file_name());
std::basic_ofstream<wchar_t> of(stf.path().string().c_str());
of << wstr;
}
std::basic_ifstream<wchar_t> f(test_file_name());
std::basic_ifstream<wchar_t> f(stf.path().string().c_str());
f.width(w);
f.exceptions(masks[mi]);
Tests::stream_extractor(b, f, wstr);
@@ -321,7 +324,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
int
test_main(int, char*[])
main()
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
@@ -331,5 +334,5 @@ test_main(int, char*[])
run_test_cases< ::boost::ulong_long_type>();
# endif
return 0;
return boost::report_errors();
}

View File

@@ -0,0 +1,112 @@
// -----------------------------------------------------------
// Copyright (c) 2001 Jeremy Siek
// Copyright (c) 2003-2006 Gennaro Prota
//
// Copyright (c) 2015 Seth Heeren
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------
#include "boost/config.hpp"
#if !defined (BOOST_NO_STRINGSTREAM)
# include <sstream>
#endif
#include "bitset_test.hpp"
#include <boost/dynamic_bitset/serialization.hpp>
#include <boost/config/workaround.hpp>
// 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
#if defined BOOST_NO_STD_WSTRING || defined BOOST_NO_STD_LOCALE
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
#endif
#include <boost/serialization/vector.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <sstream>
namespace {
template <typename Block>
struct SerializableType {
boost::dynamic_bitset<Block> x;
private:
friend class boost::serialization::access;
template <class Archive> void serialize(Archive &ar, const unsigned int) {
ar & BOOST_SERIALIZATION_NVP(x);
}
};
template <typename Block, typename IArchive, typename OArchive>
void test_serialization( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
{
SerializableType<Block> a;
for (int i=0; i<128; ++i)
a.x.resize(11*i, i%2);
#if !defined (BOOST_NO_STRINGSTREAM)
std::stringstream ss;
// test serialization
{
OArchive oa(ss);
oa << BOOST_SERIALIZATION_NVP(a);
}
// test de-serialization
{
IArchive ia(ss);
SerializableType<Block> b;
ia >> BOOST_SERIALIZATION_NVP(b);
assert(a.x == b.x);
}
#else
# error "TODO implement file-based test path?"
#endif
}
template <typename Block>
void test_binary_archive( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) {
test_serialization<Block, boost::archive::binary_iarchive, boost::archive::binary_oarchive>();
}
template <typename Block>
void test_xml_archive( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) {
test_serialization<Block, boost::archive::xml_iarchive, boost::archive::xml_oarchive>();
}
}
template <typename Block>
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
{
test_binary_archive<Block>();
test_xml_archive<Block>();
}
int main()
{
run_test_cases<unsigned char>();
run_test_cases<unsigned short>();
run_test_cases<unsigned int>();
run_test_cases<unsigned long>();
# ifdef BOOST_HAS_LONG_LONG
run_test_cases< ::boost::ulong_long_type>();
# endif
return boost::report_errors();
}

View File

@@ -0,0 +1,30 @@
//
// Copyright (C) 2018 James E. King III
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/dynamic_bitset.hpp>
#include <boost/core/lightweight_test.hpp>
int main(int, char*[])
{
boost::dynamic_bitset<> x(5); // all 0's by default
x.set(1, 2);
x.set(3, 1, true);
x.set(2, 1, false);
BOOST_TEST(!x.test(0));
BOOST_TEST( x.test(1));
BOOST_TEST(!x.test(2));
BOOST_TEST( x.test(3));
BOOST_TEST(!x.test(4));
return boost::report_errors();
}

47
test/test_boost_hash.cpp Normal file
View File

@@ -0,0 +1,47 @@
//
// Copyright (C) 2019 James E. King III
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/config.hpp>
#include <boost/dynamic_bitset.hpp>
#include <boost/core/lightweight_test.hpp>
#include <set>
int main(int, char*[])
{
typedef boost::dynamic_bitset<unsigned long> bitset_type;
const std::string long_string =
"01001110101110110101011010000000000011110101101111111111";
const std::string long_string_prime_begin =
"11001110101110110101011010000000000011110101101111111111";
const std::string long_string_prime_end =
"01001110101110110101011010000000000011110101101111111110";
bitset_type zeroes(long_string.size(), 0);
bitset_type stuff (long_string);
bitset_type stupb (long_string_prime_begin);
bitset_type stupe (long_string_prime_end);
bitset_type ones (long_string.size(), 1);
boost::hash<bitset_type> bitset_hasher;
std::set<std::size_t> results;
results.insert(bitset_hasher(zeroes));
results.insert(bitset_hasher(stuff));
results.insert(bitset_hasher(stupb));
results.insert(bitset_hasher(stupe));
results.insert(bitset_hasher(ones));
// if any hash is identical to another there will be less than 5
BOOST_TEST_EQ(results.size(), 5);
return boost::report_errors();
}

28
test/test_lowest_bit.cpp Normal file
View File

@@ -0,0 +1,28 @@
//
// Copyright (C) 2018 James E. King III
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/cstdint.hpp>
#include <boost/dynamic_bitset/detail/lowest_bit.hpp>
#include <boost/core/lightweight_test.hpp>
int main(int, char*[])
{
for (boost::int32_t i = 1; i < 32; ++i) {
BOOST_TEST_EQ(i, boost::detail::lowest_bit(1u << i));
}
BOOST_TEST_EQ(2, boost::detail::lowest_bit(123456788));
BOOST_TEST_EQ(30, boost::detail::lowest_bit(static_cast<boost::int64_t>(1507208177123328)));
return boost::report_errors();
}

39
test/test_std_hash.cpp Normal file
View File

@@ -0,0 +1,39 @@
//
// Copyright (C) 2019 James E. King III
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/config.hpp>
#include <boost/dynamic_bitset.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <functional>
#include <unordered_set>
int main(int, char*[])
{
typedef boost::dynamic_bitset<unsigned long> bitset_type;
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);
std::unordered_set<bitset_type> bitsets;
bitsets.insert(zeroes);
bitsets.insert(stuff);
bitsets.insert(ones);
BOOST_TEST_EQ(bitsets.size(), 3);
return boost::report_errors();
}