mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-22 05:12:13 +00:00
Compare commits
140 Commits
boost-1.44
...
boost-1.69
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a580c496fa | ||
|
|
1ca15c5fcd | ||
|
|
512ac37529 | ||
|
|
8e265c49f8 | ||
|
|
a449a11a80 | ||
|
|
a0735943f2 | ||
|
|
8fe1db1b08 | ||
|
|
d7d6555f85 | ||
|
|
a90fe08934 | ||
|
|
b944aa3008 | ||
|
|
759af5e853 | ||
|
|
7b6379a356 | ||
|
|
4f54d83981 | ||
|
|
4cac68e762 | ||
|
|
d3eb4faf0c | ||
|
|
3f3662d39d | ||
|
|
184d1ba7ad | ||
|
|
5b39db5ba0 | ||
|
|
f4e49ff56f | ||
|
|
0c8640efb8 | ||
|
|
0ead484c37 | ||
|
|
6cafa21c6d | ||
|
|
dbfce8e174 | ||
|
|
684b6117dd | ||
|
|
572e9d78ff | ||
|
|
e49b08a289 | ||
|
|
d644c83b13 | ||
|
|
a50768c085 | ||
|
|
91895380c6 | ||
|
|
7259281f5b | ||
|
|
92af4f52e9 | ||
|
|
d86f4ebddb | ||
|
|
340822f979 | ||
|
|
1c5e30fe49 | ||
|
|
0f48010783 | ||
|
|
1d59cc4788 | ||
|
|
9879dd05b5 | ||
|
|
29ba0c22b1 | ||
|
|
8b7374b1db | ||
|
|
2091a4fd18 | ||
|
|
225064d355 | ||
|
|
b151c97fd2 | ||
|
|
a93174ddf9 | ||
|
|
1611aeb16a | ||
|
|
3229e26108 | ||
|
|
083c5e6214 | ||
|
|
18eb52ecee | ||
|
|
a3ea40d932 | ||
|
|
dd7cdc794e | ||
|
|
10195375ed | ||
|
|
9ed6f608a1 | ||
|
|
ba0ba59f24 | ||
|
|
bcc384b604 | ||
|
|
7b14895ec6 | ||
|
|
eb6004d98d | ||
|
|
f34a8a4b23 | ||
|
|
d19aeced56 | ||
|
|
5f4c0dc4d9 | ||
|
|
1b880102fe | ||
|
|
e8b37ccf10 | ||
|
|
e7aa32f5db | ||
|
|
86b177d3ee | ||
|
|
4c6825716f | ||
|
|
ac0baa94ee | ||
|
|
ae64496e98 | ||
|
|
0a1621f0e7 | ||
|
|
4d8b9b5c33 | ||
|
|
9fe813dd93 | ||
|
|
dd69fe8756 | ||
|
|
20df4eadc8 | ||
|
|
cccd1f74dc | ||
|
|
71a5cc6eeb | ||
|
|
c9fa6dbdd1 | ||
|
|
7186546f7d | ||
|
|
b82bfe4832 | ||
|
|
a257dead26 | ||
|
|
f44fbae9ba | ||
|
|
d6f1835fbb | ||
|
|
e6fc8e8ec9 | ||
|
|
734861bdac | ||
|
|
594140a081 | ||
|
|
59e99b9b45 | ||
|
|
f199a7f006 | ||
|
|
60f871da0c | ||
|
|
76d2f9d4d1 | ||
|
|
5c79c20827 | ||
|
|
ed32df5ad2 | ||
|
|
da0b582703 | ||
|
|
622c8d8fd5 | ||
|
|
97d2bff3b6 | ||
|
|
a143af6e2f | ||
|
|
59825bc8db | ||
|
|
7d1144a461 | ||
|
|
c298ba0c5f | ||
|
|
574f1dfe62 | ||
|
|
e953b16cee | ||
|
|
180aa15c44 | ||
|
|
7ed46a6667 | ||
|
|
24d2081a73 | ||
|
|
f6ce97de67 | ||
|
|
7530a40476 | ||
|
|
c05a47b50d | ||
|
|
d09c7d2180 | ||
|
|
d80a9dbdf8 | ||
|
|
15b61f694a | ||
|
|
eef25927d7 | ||
|
|
a8998ae8a0 | ||
|
|
aa6053121c | ||
|
|
5d66eda2ac | ||
|
|
771e3d8779 | ||
|
|
1b7c462afe | ||
|
|
8a1da9667b | ||
|
|
717fb80e40 | ||
|
|
adc36a2b7f | ||
|
|
a8c3c80888 | ||
|
|
3a04624801 | ||
|
|
08357c3972 | ||
|
|
41e1f468d3 | ||
|
|
ae44c787e2 | ||
|
|
60375651d9 | ||
|
|
50ffc7be59 | ||
|
|
02f4b61f14 | ||
|
|
07b5b85dfe | ||
|
|
1170f90afb | ||
|
|
98917625dd | ||
|
|
109a0aef13 | ||
|
|
5995354ceb | ||
|
|
7f268666ad | ||
|
|
ecbc0c4262 | ||
|
|
184337e1cc | ||
|
|
2726ad0c3c | ||
|
|
30bd2e5bab | ||
|
|
38f7aa5d40 | ||
|
|
48aaaabed2 | ||
|
|
755fa101f8 | ||
|
|
9c0620b7f9 | ||
|
|
30b986e549 | ||
|
|
eb7f05d0c4 | ||
|
|
fff12b2c59 | ||
|
|
fb5e1d024d |
175
.travis.yml
Normal file
175
.travis.yml
Normal file
@@ -0,0 +1,175 @@
|
||||
# Copyright 2016 Peter Dimov
|
||||
# Copyright 2017, 2018 James E. King III
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#
|
||||
# Generic Travis CI build script for boostorg repositories
|
||||
# See: https://github.com/jeking3/boost-ci
|
||||
#
|
||||
# Instructions for customizing this script for your library:
|
||||
#
|
||||
# 1. Customize the compilers and language levels you want in the 'jobs'.
|
||||
# 2. If you have more than include/, src/, test/, example/, examples/, or
|
||||
# tools/ directories, modify your Travis CI project and add the environment
|
||||
# variable DEPINST. For example if your build uses code in "bench/" and
|
||||
# "fog/" directories, then set DEPINST to the following:
|
||||
# --include bench --include fog
|
||||
# 3. If you want to enable Coverity Scan, you need to provide the environment
|
||||
# variables COVERITY_SCAN_TOKEN and COVERITY_SCAN_NOTIFICATION_EMAIL in
|
||||
# your github settings.
|
||||
# 4. Enable pull request builds in your boostorg/<library> account.
|
||||
#
|
||||
# That's it - the scripts will do everything else for you.
|
||||
|
||||
sudo: false
|
||||
dist: trusty
|
||||
language: cpp
|
||||
|
||||
env:
|
||||
global:
|
||||
# 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..
|
||||
# - B2_ADDRESS_MODEL=address-model=64,32
|
||||
# - B2_LINK=link=shared,static
|
||||
# - B2_THREADING=threading=multi,single
|
||||
- B2_VARIANT=variant=release,debug
|
||||
|
||||
install:
|
||||
- git clone https://github.com/jeking3/boost-ci.git boost-ci
|
||||
- cp -pr boost-ci/ci boost-ci/.codecov.yml .
|
||||
- source ci/travis/install.sh
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- binutils-gold
|
||||
- gdb
|
||||
- libc6-dbg
|
||||
|
||||
branches:
|
||||
only:
|
||||
- develop
|
||||
- master
|
||||
|
||||
script:
|
||||
- cd $BOOST_ROOT/libs/$SELF
|
||||
- ci/travis/build.sh
|
||||
|
||||
#
|
||||
# Default toolsets in Ubuntu
|
||||
#
|
||||
# trusty xenial bionic
|
||||
# 14.04 16.04 18.04
|
||||
# ------ ------ ------
|
||||
# clang 3.4 3.8 6.0
|
||||
# gcc 4.8.2 5.3.1 7.3.0
|
||||
#
|
||||
|
||||
anchors:
|
||||
clang-34: &clang-34 { apt: { packages: [ "clang-3.4" ], sources: [ "llvm-toolchain-trusty-3.4" ] } }
|
||||
clang-38: &clang-38 { apt: { packages: [ "clang-3.8",
|
||||
"libstdc++-6-dev" ], sources: [ "llvm-toolchain-trusty-3.8",
|
||||
"ubuntu-toolchain-r-test" ] } }
|
||||
clang-4: &clang-4 { apt: { packages: [ "clang-4.0",
|
||||
"libstdc++-6-dev" ], sources: [ "llvm-toolchain-trusty-4.0",
|
||||
"ubuntu-toolchain-r-test" ] } }
|
||||
clang-5: &clang-5 { apt: { packages: [ "clang-5.0",
|
||||
"libstdc++-7-dev" ], sources: [ "llvm-toolchain-trusty-5.0",
|
||||
"ubuntu-toolchain-r-test" ] } }
|
||||
clang-6: &clang-6 { apt: { packages: [ "clang-6.0",
|
||||
"libc++-dev",
|
||||
"libstdc++-8-dev",
|
||||
"valgrind" ], sources: [ "llvm-toolchain-trusty-6.0",
|
||||
"ubuntu-toolchain-r-test" ] } }
|
||||
gcc-44: &gcc-44 { apt: { packages: [ "g++-4.4" ], sources: [ "ubuntu-toolchain-r-test" ] } }
|
||||
gcc-46: &gcc-46 { apt: { packages: [ "g++-4.6" ], sources: [ "ubuntu-toolchain-r-test" ] } }
|
||||
gcc-48: &gcc-48 { apt: { packages: [ "g++-4.8" ], sources: [ "ubuntu-toolchain-r-test" ] } }
|
||||
gcc-5: &gcc-5 { apt: { packages: [ "g++-5" ], sources: [ "ubuntu-toolchain-r-test" ] } }
|
||||
gcc-6: &gcc-6 { apt: { packages: [ "g++-6" ], sources: [ "ubuntu-toolchain-r-test" ] } }
|
||||
gcc-7: &gcc-7 { apt: { packages: [ "g++-7" ], sources: [ "ubuntu-toolchain-r-test" ] } }
|
||||
gcc-8: &gcc-8 { apt: { packages: [ "g++-8" ], sources: [ "ubuntu-toolchain-r-test" ] } }
|
||||
|
||||
jobs:
|
||||
allow_failures:
|
||||
- env:
|
||||
- COPY="all the environment settings from your job"
|
||||
|
||||
include:
|
||||
# libstdc++
|
||||
- { os: "linux", env: [ "TOOLSET=gcc-4.4", "CXXSTD=98,0x" ], addons: *gcc-44 }
|
||||
- { os: "linux", env: [ "TOOLSET=gcc-4.6", "CXXSTD=03,0x" ], addons: *gcc-46 }
|
||||
- { os: "linux", env: [ "TOOLSET=gcc-4.8", "CXXSTD=03,11" ], addons: *gcc-48 }
|
||||
- { os: "linux", env: [ "TOOLSET=gcc-5", "CXXSTD=03,11" ], addons: *gcc-5 }
|
||||
- { os: "linux", env: [ "TOOLSET=gcc-6", "CXXSTD=03,11,14" ], addons: *gcc-6 }
|
||||
- { os: "linux", env: [ "TOOLSET=gcc-7", "CXXSTD=03,11,14,17" ], addons: *gcc-7 }
|
||||
- { os: "linux", env: [ "TOOLSET=gcc-8", "CXXSTD=03,11,14,17,2a" ], addons: *gcc-8 }
|
||||
- { os: "linux", env: [ "TOOLSET=clang-3.4", "CXXSTD=03,11" ], addons: *clang-34 }
|
||||
- { os: "linux", env: [ "TOOLSET=clang-3.8", "CXXSTD=03,11,14" ], addons: *clang-38 }
|
||||
- { os: "linux", env: [ "TOOLSET=clang-4.0", "CXXSTD=03,11,14" ], addons: *clang-4 }
|
||||
- { os: "linux", env: [ "TOOLSET=clang-5.0", "CXXSTD=03,11,14,17" ], addons: *clang-5 }
|
||||
- { os: "linux", env: [ "TOOLSET=clang-6.0", "CXXSTD=03,11,14,17,2a" ], addons: *clang-6 }
|
||||
# libc++
|
||||
- { os: "linux", env: [ "TOOLSET=clang-6.0", "CXXSTD=03,11,14,17,2a",
|
||||
"CXXFLAGS=-stdlib=libc++" ], addons: *clang-6 }
|
||||
# the rvm environment on osx is taking over basic commands like "cd" and breaking things!
|
||||
# - { os: "osx" , env: [ "COMMENT=libc++",
|
||||
# "TOOLSET=clang", "CXXSTD=03,11,14" ] }
|
||||
|
||||
- os: linux
|
||||
env:
|
||||
- COMMENT=codecov.io
|
||||
- TOOLSET=gcc-7
|
||||
- DEFINES="define=BOOST_NO_STRESS_TEST=1"
|
||||
addons: *gcc-7
|
||||
script:
|
||||
- pushd /tmp && git clone https://github.com/linux-test-project/lcov.git && export PATH=/tmp/lcov/bin:$PATH && which lcov && lcov --version && popd
|
||||
- cd $BOOST_ROOT/libs/$SELF
|
||||
- ci/travis/codecov.sh
|
||||
|
||||
- os: linux
|
||||
env:
|
||||
- COMMENT=cppcheck
|
||||
script:
|
||||
- cd $BOOST_ROOT/libs/$SELF
|
||||
- ci/travis/cppcheck.sh
|
||||
|
||||
- os: linux
|
||||
env:
|
||||
- COMMENT=ubsan
|
||||
- B2_VARIANT=variant=debug
|
||||
- TOOLSET=gcc-8
|
||||
- CXXSTD=03,11,14,17,2a
|
||||
- DEFINES="define=BOOST_NO_STRESS_TEST=1"
|
||||
- CXXFLAGS="cxxflags=-fno-omit-frame-pointer cxxflags=-fsanitize=undefined cxxflags=-fno-sanitize-recover=undefined"
|
||||
- LINKFLAGS="linkflags=-fsanitize=undefined linkflags=-fno-sanitize-recover=undefined linkflags=-fuse-ld=gold"
|
||||
- UBSAN_OPTIONS=print_stacktrace=1
|
||||
addons: *gcc-8
|
||||
|
||||
- os: linux
|
||||
env:
|
||||
- COMMENT=valgrind
|
||||
- TOOLSET=clang-6.0
|
||||
- CXXSTD=03,11,14,17,2a
|
||||
- DEFINES="define=BOOST_NO_STRESS_TEST=1"
|
||||
- B2_VARIANT=variant=debug
|
||||
- TESTFLAGS=testing.launcher=valgrind
|
||||
- VALGRIND_OPTS=--error-exitcode=1
|
||||
addons: *clang-6
|
||||
|
||||
#################### Jobs to run on pushes to master, develop ###################
|
||||
|
||||
# Coverity Scan
|
||||
- os: linux
|
||||
if: (env(COVERITY_SCAN_NOTIFICATION_EMAIL) IS present) AND (branch IN (develop, master)) AND (type IN (cron, push))
|
||||
env:
|
||||
- COMMENT="Coverity Scan"
|
||||
- TOOLSET=gcc-7
|
||||
addons: *gcc-7
|
||||
script:
|
||||
- cd $BOOST_ROOT/libs/$SELF
|
||||
- ci/travis/coverity.sh
|
||||
|
||||
notifications:
|
||||
email:
|
||||
false
|
||||
11
Jamfile
Normal file
11
Jamfile
Normal 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 ;
|
||||
14
Jamfile.v2
14
Jamfile.v2
@@ -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
23
LICENSE
Normal 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
34
README.md
Normal 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 | Travis | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests |
|
||||
:-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- |
|
||||
[`master`](https://github.com/boostorg/dynamic_bitset/tree/master) | [](https://travis-ci.org/boostorg/dynamic_bitset) | [](https://ci.appveyor.com/project/jeking3/dynamic_bitset-jv17p/branch/master) | [](https://scan.coverity.com/projects/boostorg-dynamic_bitset) | [](https://codecov.io/gh/boostorg/dynamic_bitset/branch/master)| [](https://pdimov.github.io/boostdep-report/master/dynamic_bitset.html) | [](http://www.boost.org/doc/libs/master/doc/html/dynamic_bitset.html) | [](http://www.boost.org/development/tests/master/developer/dynamic_bitset.html)
|
||||
[`develop`](https://github.com/boostorg/dynamic_bitset/tree/develop) | [](https://travis-ci.org/boostorg/dynamic_bitset) | [](https://ci.appveyor.com/project/jeking3/dynamic_bitset-jv17p/branch/develop) | [](https://scan.coverity.com/projects/boostorg-dynamic_bitset) | [](https://codecov.io/gh/boostorg/dynamic_bitset/branch/develop) | [](https://pdimov.github.io/boostdep-report/develop/dynamic_bitset.html) | [](http://www.boost.org/doc/libs/develop/doc/html/dynamic_bitset.html) | [](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.
|
||||
|
||||
126
appveyor.yml
Normal file
126
appveyor.yml
Normal file
@@ -0,0 +1,126 @@
|
||||
# Copyright 2016, 2017 Peter Dimov
|
||||
# Copyright (C) 2017, 2018 James E. King III
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#
|
||||
# Generic Appveyor build script for boostorg repositories
|
||||
# See: https://github.com/jeking3/boost-ci/
|
||||
#
|
||||
# Instructions for customizing this script for your library:
|
||||
#
|
||||
# 1. Customize the compilers and language levels you want.
|
||||
# 2. If you have move 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:
|
||||
- develop
|
||||
- master
|
||||
|
||||
matrix:
|
||||
# Adding MAYFAIL to any matrix job allows it to fail but the build stays green:
|
||||
allow_failures:
|
||||
- MAYFAIL: true
|
||||
|
||||
environment:
|
||||
global:
|
||||
# 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: address-model=64,32
|
||||
# B2_LINK: link=shared,static
|
||||
# B2_THREADING: threading=multi,single
|
||||
B2_VARIANT: variant=release,debug
|
||||
|
||||
matrix:
|
||||
- FLAVOR: Visual Studio 2017 C++2a Strict
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: msvc-14.1
|
||||
B2_ADDRESS_MODEL: address-model=64
|
||||
CXXFLAGS: cxxflags=-permissive-
|
||||
CXXSTD: latest # 2a
|
||||
|
||||
- FLAVOR: Visual Studio 2017 C++17
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: msvc-14.1
|
||||
B2_ADDRESS_MODEL: address-model=64
|
||||
CXXSTD: 17
|
||||
|
||||
- FLAVOR: Visual Studio 2017 C++14 (Default)
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: msvc-14.1
|
||||
B2_ADDRESS_MODEL: address-model=64,32
|
||||
|
||||
- FLAVOR: Visual Studio 2015 C++14 (Default)
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
TOOLSET: msvc-14.0
|
||||
B2_ADDRESS_MODEL: address-model=64,32
|
||||
|
||||
- FLAVOR: Visual Studio 2010, 2012, 2013
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
TOOLSET: msvc-10.0,msvc-11.0,msvc-12.0
|
||||
|
||||
- FLAVOR: cygwin (32-bit)
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ADDPATH: C:\cygwin\bin;
|
||||
B2_ADDRESS_MODEL: address-model=32
|
||||
CXXSTD: 03,11
|
||||
# https://github.com/boostorg/test/issues/144
|
||||
DEFINES: define=_POSIX_C_SOURCE=200112L
|
||||
THREADING: threadapi=pthread
|
||||
TOOLSET: gcc
|
||||
|
||||
- FLAVOR: cygwin (64-bit)
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ADDPATH: C:\cygwin64\bin;
|
||||
B2_ADDRESS_MODEL: address-model=64
|
||||
CXXSTD: 11,17
|
||||
# https://github.com/boostorg/test/issues/144
|
||||
DEFINES: define=_POSIX_C_SOURCE=200112L define=__USE_ISOC99
|
||||
THREADING: threadapi=pthread
|
||||
TOOLSET: gcc
|
||||
|
||||
- FLAVOR: mingw32
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARCH: i686
|
||||
B2_ADDRESS_MODEL: address-model=32
|
||||
CXXSTD: 03,11
|
||||
SCRIPT: ci\appveyor\mingw.bat
|
||||
|
||||
- FLAVOR: mingw64
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARCH: x86_64
|
||||
B2_ADDRESS_MODEL: address-model=64
|
||||
CXXSTD: 11,17
|
||||
DEFINES: define=__USE_ISOC99
|
||||
SCRIPT: ci\appveyor\mingw.bat
|
||||
|
||||
install:
|
||||
- set SELF=%APPVEYOR_PROJECT_NAME:-=_%
|
||||
- git clone https://github.com/jeking3/boost-ci.git C:\boost-ci
|
||||
- xcopy /s /e /q /i C:\boost-ci\ci .\ci
|
||||
- ci\appveyor\install.bat
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- set SELF=%APPVEYOR_PROJECT_NAME:-=_%
|
||||
- PATH=%ADDPATH%%PATH%
|
||||
# The definition of TOOLCXX omits CXXSTD= if it was not defined above
|
||||
- IF NOT DEFINED CXXSTD (SET TOOLCXX=toolset=%TOOLSET%) ELSE (SET TOOLCXX=toolset=%TOOLSET% cxxstd=%CXXSTD%)
|
||||
# Echo the complete build command to the build log
|
||||
- IF NOT DEFINED SCRIPT (ECHO b2 libs/%SELF:\=/% %TOOLCXX% %CXXFLAGS% %DEFINES% %THREADING% %B2_ADDRESS_MODEL% %B2_LINK% %B2_THREADING% %B2_VARIANT% -j3)
|
||||
# Now go build...
|
||||
- IF DEFINED SCRIPT (call libs\%SELF%\%SCRIPT%) ELSE (b2 libs/%SELF:\=/% %TOOLCXX% %CXXFLAGS% %DEFINES% %THREADING% %B2_ADDRESS_MODEL% %B2_LINK% %B2_THREADING% %B2_VARIANT% -j3)
|
||||
1
doc/readme
Normal file
1
doc/readme
Normal file
@@ -0,0 +1 @@
|
||||
The documentation for the dynamic_bitset library is the top-level index.html 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
|
||||
@@ -163,16 +166,23 @@ public:
|
||||
<a href=
|
||||
"#cons5">dynamic_bitset</a>(const dynamic_bitset& b);
|
||||
|
||||
<a href=
|
||||
"#move-cons">dynamic_bitset</a>(dynamic_bitset&& b);
|
||||
|
||||
void <a href="#swap">swap</a>(dynamic_bitset& b);
|
||||
|
||||
dynamic_bitset& <a href=
|
||||
"#assign">operator=</a>(const dynamic_bitset& b);
|
||||
|
||||
dynamic_bitset& <a href=
|
||||
"#move-assign">operator=</a>(dynamic_bitset&& 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 +198,39 @@ public:
|
||||
dynamic_bitset <a href="#op-sl">operator<<</a>(size_type n) const;
|
||||
dynamic_bitset <a href="#op-sr">operator>></a>(size_type n) const;
|
||||
|
||||
dynamic_bitset& <a href="#set3">set</a>(size_type n, size_type len, bool val);
|
||||
dynamic_bitset& <a href="#set2">set</a>(size_type n, bool val = true);
|
||||
dynamic_bitset& <a href="#set1">set</a>();
|
||||
dynamic_bitset& <a href="#reset3">reset</a>(size_type n, size_type len);
|
||||
dynamic_bitset& <a href="#reset2">reset</a>(size_type n);
|
||||
dynamic_bitset& <a href="#reset1">reset</a>();
|
||||
dynamic_bitset& <a href="#flip3">flip</a>(size_type n, size_type len);
|
||||
dynamic_bitset& <a href="#flip2">flip</a>(size_type n);
|
||||
dynamic_bitset& <a href="#flip1">flip</a>();
|
||||
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& a) const;
|
||||
bool <a href="#is_proper_subset_of">is_proper_subset_of</a>(const dynamic_bitset& a) const;
|
||||
bool <a href="#intersects">intersects</a>(const dynamic_bitset& 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;
|
||||
@@ -355,7 +374,7 @@ 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>
|
||||
@@ -620,6 +639,20 @@ allocator in <tt>x</tt>. <br />
|
||||
(Required by <a href=
|
||||
"http://www.sgi.com/tech/stl/Assignable.html">Assignable</a>.)
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
<a id="move-cons">dynamic_bitset</a>(dynamic_bitset&& 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>
|
||||
template <typename BlockInputIterator>
|
||||
@@ -763,6 +796,20 @@ dynamic_bitset& <a id=
|
||||
(Required by <a href=
|
||||
"http://www.sgi.com/tech/stl/Assignable.html">Assignable</a>.)
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
dynamic_bitset& <a id=
|
||||
"move-assign">operator=</a>(dynamic_bitset&& 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>
|
||||
allocator_type <a id="get_allocator">get_allocator()</a> const;
|
||||
@@ -796,6 +843,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->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);
|
||||
@@ -1010,6 +1066,18 @@ dynamic_bitset& <a id="reset1">reset</a>()
|
||||
<b>Returns:</b> <tt>*this</tt><br />
|
||||
<b>Throws:</b> nothing.
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
dynamic_bitset& <a id=
|
||||
"set3">set</a>(size_type n, size_type len, bool val);
|
||||
</pre>
|
||||
|
||||
<b>Precondition:</b> <tt>n + len < this->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& <a id=
|
||||
@@ -1022,6 +1090,17 @@ dynamic_bitset& <a id=
|
||||
<tt>false</tt>. <br />
|
||||
<b>Returns:</b> <tt>*this</tt>
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
dynamic_bitset& <a id=
|
||||
"reset3">reset</a>(size_type n, size_type len);
|
||||
</pre>
|
||||
|
||||
<b>Precondition:</b> <tt>n + len < this->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& <a id="reset2">reset</a>(size_type n)
|
||||
@@ -1031,6 +1110,16 @@ dynamic_bitset& <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& <a id="flip3">flip</a>(size_type n, size_type len)
|
||||
</pre>
|
||||
|
||||
<b>Precondition:</b> <tt>n + len < this->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& <a id="flip2">flip</a>(size_type n)
|
||||
@@ -1077,6 +1166,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 +1209,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
|
||||
@@ -1113,6 +1245,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 < this->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 +1318,19 @@ also set and if <tt>this->count() < a.count()</tt>.
|
||||
Otherwise this function returns false.<br />
|
||||
<b>Throws:</b> nothing.
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
bool <a id=
|
||||
"intersects">intersects</a>(const dynamic_bitset& a) const
|
||||
</pre>
|
||||
|
||||
<b>Requires:</b> <tt>this->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;
|
||||
@@ -1495,6 +1652,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,9 +1712,12 @@ 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>
|
||||
@@ -1581,6 +1749,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 © 2014</td>
|
||||
<td>Ahmed Charles (<a href="mailto:acharles@outlook.com">acharles@outlook.com</a>)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Copyright © 2014</td>
|
||||
<td>Glen Fernandes (<a href="mailto:glenjofe@gmail.com">glenjofe@gmail.com</a>)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Copyright © 2014</td>
|
||||
<td>Riccardo Marcangelo (<a href="mailto:ricky.65@outlook.com">ricky.65@outlook.com</a>)</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br />
|
||||
<div class="legalnotice">
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// -----------------------------------------------------------
|
||||
// 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
|
||||
;
|
||||
|
||||
@@ -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.
|
||||
|
||||
//
|
||||
//
|
||||
// -----------------------------------------------------------------------//
|
||||
@@ -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):
|
||||
@@ -91,11 +95,11 @@ template <typename T>
|
||||
void timing_test(T* = 0) // dummy parameter to workaround VC6
|
||||
{
|
||||
|
||||
const unsigned long num = 100000;
|
||||
const unsigned long num = 30 * 100000;
|
||||
|
||||
|
||||
// This variable is printed at the end of the test,
|
||||
// to prevent the optimizer eliminating the call to
|
||||
// to prevent the optimizer from removing the call to
|
||||
// count() in the loop below.
|
||||
typename boost::dynamic_bitset<T>::size_type dummy = 0;
|
||||
|
||||
@@ -123,7 +127,6 @@ void timing_test(T* = 0) // dummy parameter to workaround VC6
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
prologue();
|
||||
|
||||
timing_test<unsigned char>();
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
// -----------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
|
||||
// Copyright (c) 2003-2006, 2008 Gennaro Prota
|
||||
// Copyright (c) 2003-2006, 2008 Gennaro Prota
|
||||
// Copyright (c) 2014 Glen Joseph Fernandes
|
||||
// (glenjofe@gmail.com)
|
||||
// Copyright (c) 2018 Evgeny Shulgin
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -12,10 +15,14 @@
|
||||
#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"
|
||||
|
||||
#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 {
|
||||
|
||||
@@ -121,6 +128,61 @@ namespace boost {
|
||||
}
|
||||
|
||||
|
||||
// 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 = 0;
|
||||
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))
|
||||
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));
|
||||
}
|
||||
|
||||
#ifdef _M_X64
|
||||
template <>
|
||||
BOOST_FORCEINLINE std::size_t popcount<unsigned __int64>(unsigned __int64 value) BOOST_NOEXCEPT
|
||||
{
|
||||
return static_cast<std::size_t>(__popcnt64(value));
|
||||
}
|
||||
#endif
|
||||
|
||||
#elif defined(BOOST_GCC) || defined(__clang__) || (defined(BOOST_INTEL) && defined(__GNUC__))
|
||||
template <>
|
||||
BOOST_FORCEINLINE std::size_t popcount<unsigned int>(unsigned int value) BOOST_NOEXCEPT
|
||||
{
|
||||
return __builtin_popcount(value);
|
||||
}
|
||||
|
||||
template <>
|
||||
BOOST_FORCEINLINE std::size_t popcount<unsigned long>(unsigned long value) BOOST_NOEXCEPT
|
||||
{
|
||||
return __builtin_popcountl(value);
|
||||
}
|
||||
|
||||
template <>
|
||||
BOOST_FORCEINLINE std::size_t popcount<boost::ulong_long_type>(boost::ulong_long_type value) BOOST_NOEXCEPT
|
||||
{
|
||||
return __builtin_popcountll(value);
|
||||
}
|
||||
#endif
|
||||
|
||||
// overload for access by blocks
|
||||
//
|
||||
template <typename Iterator, typename ValueType>
|
||||
@@ -129,13 +191,7 @@ namespace boost {
|
||||
{
|
||||
std::size_t num = 0;
|
||||
while (length){
|
||||
|
||||
ValueType value = *first;
|
||||
while (value) {
|
||||
num += count_table<>::table[value & ((1u<<table_width) - 1)];
|
||||
value >>= table_width;
|
||||
}
|
||||
|
||||
num += popcount<ValueType>(*first);
|
||||
++first;
|
||||
--length;
|
||||
}
|
||||
@@ -155,17 +211,25 @@ namespace boost {
|
||||
// meaningful info.
|
||||
//
|
||||
template <typename T>
|
||||
typename T::size_type vector_max_size_workaround(const T & v) {
|
||||
inline typename T::size_type vector_max_size_workaround(const T & v)
|
||||
BOOST_NOEXCEPT
|
||||
{
|
||||
typedef typename T::allocator_type allocator_type;
|
||||
|
||||
typedef typename T::allocator_type allocator_type;
|
||||
const allocator_type& alloc = v.get_allocator();
|
||||
|
||||
const typename allocator_type::size_type alloc_max =
|
||||
v.get_allocator().max_size();
|
||||
const typename T::size_type container_max = v.max_size();
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
typedef std::allocator_traits<allocator_type> allocator_traits;
|
||||
|
||||
return alloc_max < container_max?
|
||||
alloc_max :
|
||||
container_max;
|
||||
const typename allocator_traits::size_type alloc_max =
|
||||
allocator_traits::max_size(alloc);
|
||||
#else
|
||||
const typename allocator_type::size_type alloc_max = alloc.max_size();
|
||||
#endif
|
||||
|
||||
const typename T::size_type container_max = v.max_size();
|
||||
|
||||
return alloc_max < container_max ? alloc_max : container_max;
|
||||
}
|
||||
|
||||
// for static_asserts
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -34,11 +41,15 @@
|
||||
#endif
|
||||
|
||||
#include "boost/dynamic_bitset_fwd.hpp"
|
||||
#include "boost/detail/dynamic_bitset.hpp"
|
||||
#include "boost/dynamic_bitset/detail/dynamic_bitset.hpp"
|
||||
#include "boost/dynamic_bitset/detail/lowest_bit.hpp"
|
||||
#include "boost/detail/iterator.hpp" // used to implement append(Iter, Iter)
|
||||
#include "boost/static_assert.hpp"
|
||||
#include "boost/move/move.hpp"
|
||||
#include "boost/limits.hpp"
|
||||
#include "boost/pending/lowest_bit.hpp"
|
||||
#include "boost/static_assert.hpp"
|
||||
#include "boost/utility/addressof.hpp"
|
||||
#include "boost/detail/no_exceptions_support.hpp"
|
||||
#include "boost/throw_exception.hpp"
|
||||
|
||||
|
||||
namespace boost {
|
||||
@@ -46,21 +57,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 +88,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 )
|
||||
@@ -207,12 +219,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>
|
||||
@@ -263,17 +281,22 @@ 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();
|
||||
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 +306,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 +333,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,
|
||||
@@ -327,20 +357,71 @@ public:
|
||||
|
||||
#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;
|
||||
|
||||
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)
|
||||
? static_cast<Block>(~0)
|
||||
: ((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 static_cast<Block>(~0);
|
||||
}
|
||||
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 +714,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
|
||||
@@ -670,7 +779,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 +812,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 +932,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 +985,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 +1012,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 +1041,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(), static_cast<Block>(~0));
|
||||
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 +1077,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)
|
||||
@@ -966,6 +1116,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 = static_cast<Block>(~0);
|
||||
|
||||
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 +1182,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 +1203,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 +1301,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 +1326,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 +1361,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,7 +1434,6 @@ 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
|
||||
//
|
||||
@@ -1230,8 +1450,7 @@ dynamic_bitset<Block, Allocator>::m_do_find_from(size_type first_block) const
|
||||
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 +1476,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 +1510,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>
|
||||
@@ -1422,19 +1713,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 +1737,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 +1760,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 +1813,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 +1826,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 +1862,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 +1874,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 +1897,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 +1905,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 +1990,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 +2011,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 +2083,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 +2092,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 = block_type(~0) << extra_bits;
|
||||
if ((m_highest_block() & mask) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
46
include/boost/dynamic_bitset/serialization.hpp
Normal file
46
include/boost/dynamic_bitset/serialization.hpp
Normal 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/serialization/vector.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 & serialization::make_nvp("m_num_bits", bs.m_num_bits)
|
||||
& serialization::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
|
||||
|
||||
16
meta/libraries.json
Normal file
16
meta/libraries.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"key": "dynamic_bitset",
|
||||
"name": "Dynamic Bitset",
|
||||
"authors": [
|
||||
"Jeremy Siek",
|
||||
"Chuck Allison"
|
||||
],
|
||||
"description": "The dynamic_bitset class represents a set of bits. It provides accesses to the value of individual bits via an operator[] and provides all of the bitwise operators that one can apply to builtin integers, such as operator& and operator<<. The number of bits in the set is specified at runtime via a parameter to the constructor of the dynamic_bitset.",
|
||||
"documentation": "dynamic_bitset.html",
|
||||
"category": [
|
||||
"Containers"
|
||||
],
|
||||
"maintainers": [
|
||||
"Jeremy Siek <jeremy.siek -at- gmail.com>"
|
||||
]
|
||||
}
|
||||
32
test/Jamfile.v2
Normal file
32
test/Jamfile.v2
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# 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 ;
|
||||
|
||||
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 ]
|
||||
;
|
||||
|
||||
# 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 ]
|
||||
;
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006, 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
|
||||
@@ -25,11 +28,12 @@
|
||||
#include "boost/limits.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include "boost/test/minimal.hpp"
|
||||
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
template <typename Block>
|
||||
inline bool nth_bit(Block num, std::size_t n)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
#ifdef __BORLANDC__
|
||||
// Borland deduces Block as a const qualified type,
|
||||
// and thus finds numeric_limits<Block> to be zero :(
|
||||
@@ -39,8 +43,9 @@ inline bool nth_bit(Block num, std::size_t n)
|
||||
#else
|
||||
int block_width = std::numeric_limits<Block>::digits;
|
||||
#endif
|
||||
|
||||
assert(n < (std::size_t) block_width);
|
||||
#endif
|
||||
|
||||
return (num >> n) & 1;
|
||||
}
|
||||
|
||||
@@ -60,10 +65,27 @@ std::string get_long_string()
|
||||
return std::string(p);
|
||||
}
|
||||
|
||||
const char * test_file_name()
|
||||
class scoped_temp_file
|
||||
{
|
||||
return "boost_dynamic_bitset_tests";
|
||||
}
|
||||
public:
|
||||
scoped_temp_file()
|
||||
: m_path(boost::filesystem::unique_path())
|
||||
{
|
||||
}
|
||||
|
||||
~scoped_temp_file()
|
||||
{
|
||||
boost::filesystem::remove(m_path);
|
||||
}
|
||||
|
||||
const boost::filesystem::path& path() const
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
private:
|
||||
boost::filesystem::path m_path;
|
||||
};
|
||||
|
||||
#if defined BOOST_OLD_IOSTREAMS || defined BOOST_NO_STD_LOCALE
|
||||
template <typename Stream>
|
||||
@@ -129,7 +151,7 @@ struct bitset_test {
|
||||
// - any remaining bit positions are initialized to zero
|
||||
//
|
||||
|
||||
Bitset b(num_bits, num);
|
||||
Bitset b(static_cast<typename Bitset::size_type>(num_bits), static_cast<unsigned long>(num));
|
||||
|
||||
// OK, we can now cast to size_type
|
||||
typedef typename Bitset::size_type size_type;
|
||||
@@ -267,11 +289,12 @@ struct bitset_test {
|
||||
}
|
||||
}
|
||||
|
||||
// assignment operator (absent from std::bitset)
|
||||
static void assignment_operator(const Bitset& lhs, const Bitset& rhs)
|
||||
// copy assignment operator (absent from std::bitset)
|
||||
static void copy_assignment_operator(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
b = rhs;
|
||||
b = b; // self assignment check
|
||||
BOOST_CHECK(b == rhs);
|
||||
|
||||
// Changes to the copy do not affect the original
|
||||
@@ -282,6 +305,32 @@ struct bitset_test {
|
||||
}
|
||||
}
|
||||
|
||||
static void max_size(const Bitset& b)
|
||||
{
|
||||
BOOST_CHECK(b.max_size() > 0);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
|
||||
// move constructor (absent from std::bitset)
|
||||
static void move_constructor(const Bitset& b)
|
||||
{
|
||||
Bitset copy(boost::move(b));
|
||||
BOOST_CHECK(b == copy);
|
||||
}
|
||||
|
||||
// move assignment operator (absent from std::bitset)
|
||||
static void move_assignment_operator(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
Bitset c(rhs);
|
||||
b = boost::move(c);
|
||||
b = boost::move(b); // self assignment check
|
||||
BOOST_CHECK(b == rhs);
|
||||
}
|
||||
|
||||
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
|
||||
static void swap(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
// bitsets must be swapped
|
||||
@@ -339,6 +388,20 @@ struct bitset_test {
|
||||
BOOST_CHECK(b.size() == 0);
|
||||
}
|
||||
|
||||
static void pop_back(const Bitset& lhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
b.pop_back();
|
||||
BOOST_CHECK(b.size() == lhs.size() - 1);
|
||||
for (std::size_t i = 0; i < b.size(); ++i)
|
||||
BOOST_CHECK(b[i] == lhs[i]);
|
||||
|
||||
b.pop_back();
|
||||
BOOST_CHECK(b.size() == lhs.size() - 2);
|
||||
for (std::size_t j = 0; j < b.size(); ++j)
|
||||
BOOST_CHECK(b[j] == lhs[j]);
|
||||
}
|
||||
|
||||
static void append_bit(const Bitset& lhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
@@ -557,6 +620,22 @@ struct bitset_test {
|
||||
}
|
||||
}
|
||||
|
||||
static void set_segment(const Bitset& b, std::size_t pos,
|
||||
std::size_t len, bool value)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
std::size_t N = lhs.size();
|
||||
Bitset prev(lhs);
|
||||
lhs.set(pos, len, value);
|
||||
for (std::size_t I = 0; I < N; ++I)
|
||||
{
|
||||
if (I < pos || I >= pos + len)
|
||||
BOOST_CHECK(lhs[I] == prev[I]);
|
||||
else
|
||||
BOOST_CHECK(lhs[I] == value);
|
||||
}
|
||||
}
|
||||
|
||||
static void reset_all(const Bitset& b)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
@@ -585,6 +664,22 @@ struct bitset_test {
|
||||
}
|
||||
}
|
||||
|
||||
static void reset_segment(const Bitset& b, std::size_t pos,
|
||||
std::size_t len)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
std::size_t N = lhs.size();
|
||||
Bitset prev(lhs);
|
||||
lhs.reset(pos, len);
|
||||
for (std::size_t I = 0; I < N; ++I)
|
||||
{
|
||||
if (I < pos || I >= pos + len)
|
||||
BOOST_CHECK(lhs[I] == prev[I]);
|
||||
else
|
||||
BOOST_CHECK(!lhs[I]);
|
||||
}
|
||||
}
|
||||
|
||||
static void operator_flip(const Bitset& b)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
@@ -622,6 +717,22 @@ struct bitset_test {
|
||||
}
|
||||
}
|
||||
|
||||
static void flip_segment(const Bitset& b, std::size_t pos,
|
||||
std::size_t len)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
std::size_t N = lhs.size();
|
||||
Bitset prev(lhs);
|
||||
lhs.flip(pos, len);
|
||||
for (std::size_t I = 0; I < N; ++I)
|
||||
{
|
||||
if (I < pos || I >= pos + len)
|
||||
BOOST_CHECK(lhs[I] == prev[I]);
|
||||
else
|
||||
BOOST_CHECK(lhs[I] != prev[I]);
|
||||
}
|
||||
}
|
||||
|
||||
// empty
|
||||
static void empty(const Bitset& b)
|
||||
{
|
||||
@@ -689,9 +800,82 @@ struct bitset_test {
|
||||
BOOST_CHECK(Bitset(b).set().count() == b.size());
|
||||
}
|
||||
|
||||
static void capacity_test_one(const Bitset& lhs)
|
||||
{
|
||||
//empty bitset
|
||||
Bitset b(lhs);
|
||||
BOOST_CHECK(b.capacity() == 0);
|
||||
}
|
||||
|
||||
static void capacity_test_two(const Bitset& lhs)
|
||||
{
|
||||
//bitset constructed with size "100"
|
||||
Bitset b(lhs);
|
||||
BOOST_CHECK(b.capacity() >= 100);
|
||||
b.resize(200);
|
||||
BOOST_CHECK(b.capacity() >= 200);
|
||||
}
|
||||
|
||||
static void reserve_test_one(const Bitset& lhs)
|
||||
{
|
||||
//empty bitset
|
||||
Bitset b(lhs);
|
||||
b.reserve(16);
|
||||
BOOST_CHECK(b.capacity() >= 16);
|
||||
}
|
||||
|
||||
static void reserve_test_two(const Bitset& lhs)
|
||||
{
|
||||
//bitset constructed with size "100"
|
||||
Bitset b(lhs);
|
||||
BOOST_CHECK(b.capacity() >= 100);
|
||||
b.reserve(60);
|
||||
BOOST_CHECK(b.size() == 100);
|
||||
BOOST_CHECK(b.capacity() >= 100);
|
||||
b.reserve(160);
|
||||
BOOST_CHECK(b.size() == 100);
|
||||
BOOST_CHECK(b.capacity() >= 160);
|
||||
}
|
||||
|
||||
static void shrink_to_fit_test_one(const Bitset& lhs)
|
||||
{
|
||||
//empty bitset
|
||||
Bitset b(lhs);
|
||||
b.shrink_to_fit();
|
||||
BOOST_CHECK(b.size() == 0);
|
||||
BOOST_CHECK(b.capacity() == 0);
|
||||
}
|
||||
|
||||
static void shrink_to_fit_test_two(const Bitset& lhs)
|
||||
{
|
||||
//bitset constructed with size "100"
|
||||
Bitset b(lhs);
|
||||
b.shrink_to_fit();
|
||||
BOOST_CHECK(b.capacity() >= 100);
|
||||
BOOST_CHECK(b.size() == 100);
|
||||
b.reserve(200);
|
||||
BOOST_CHECK(b.capacity() >= 200);
|
||||
BOOST_CHECK(b.size() == 100);
|
||||
b.shrink_to_fit();
|
||||
BOOST_CHECK(b.capacity() < 200);
|
||||
BOOST_CHECK(b.size() == 100);
|
||||
}
|
||||
|
||||
static void all(const Bitset& b)
|
||||
{
|
||||
BOOST_CHECK(b.all() == (b.count() == b.size()));
|
||||
bool result = true;
|
||||
for(std::size_t i = 0; i < b.size(); ++i)
|
||||
if(!b[i]) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
BOOST_CHECK(b.all() == result);
|
||||
}
|
||||
|
||||
static void any(const Bitset& b)
|
||||
{
|
||||
//BOOST_CHECK(b.any() == (b.count() > 0));
|
||||
BOOST_CHECK(b.any() == (b.count() != 0));
|
||||
bool result = false;
|
||||
for(std::size_t i = 0; i < b.size(); ++i)
|
||||
if(b[i]) {
|
||||
@@ -842,23 +1026,41 @@ struct bitset_test {
|
||||
|
||||
static bool less_than(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
// Compare from most significant to least.
|
||||
// Careful, don't send unsigned int into negative territory!
|
||||
if (a.size() == 0)
|
||||
return false;
|
||||
|
||||
std::size_t I;
|
||||
for (I = a.size() - 1; I > 0; --I)
|
||||
if (a[I] < b[I])
|
||||
return true;
|
||||
else if (a[I] > b[I])
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Bitset::size_type size_type;
|
||||
|
||||
size_type asize(a.size());
|
||||
size_type bsize(b.size());
|
||||
|
||||
if (!bsize)
|
||||
{
|
||||
return false;
|
||||
// if (a[I] = b[I]) skip to next
|
||||
|
||||
if (a[0] < b[0])
|
||||
return true;
|
||||
}
|
||||
else if (!asize)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
{
|
||||
|
||||
// Compare from most significant to least.
|
||||
|
||||
size_type leqsize(std::min BOOST_PREVENT_MACRO_SUBSTITUTION(asize,bsize));
|
||||
size_type I;
|
||||
for (I = 0; I < leqsize; ++I,--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;
|
||||
// if (a[i] = b[j]) skip to next
|
||||
}
|
||||
return (a.size() < b.size());
|
||||
}
|
||||
}
|
||||
|
||||
static typename Bitset::size_type next_bit_on(const Bitset& b, typename Bitset::size_type prev)
|
||||
@@ -925,6 +1127,25 @@ struct bitset_test {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_set_bit(const Bitset& b, std::size_t pos, bool value)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
std::size_t N = lhs.size();
|
||||
if (pos < N) {
|
||||
Bitset prev(lhs);
|
||||
// Stores a new value in the bit at position pos in lhs.
|
||||
BOOST_CHECK(lhs.test_set(pos, value) == prev[pos]);
|
||||
BOOST_CHECK(lhs[pos] == value);
|
||||
|
||||
// All other values of lhs remain unchanged
|
||||
for (std::size_t I = 0; I < N; ++I)
|
||||
if (I != pos)
|
||||
BOOST_CHECK(lhs[I] == prev[I]);
|
||||
} else {
|
||||
// Not in range, doesn't satisfy precondition.
|
||||
}
|
||||
}
|
||||
|
||||
static void operator_shift_left(const Bitset& lhs, std::size_t pos)
|
||||
{
|
||||
Bitset x(lhs);
|
||||
@@ -1048,7 +1269,7 @@ struct bitset_test {
|
||||
// This test require that os be an output _and_ input stream.
|
||||
// Of course dynamic_bitset's operator << doesn't require that.
|
||||
|
||||
size_type total_len = w <= 0 || (size_type)(w) < b.size()? b.size() : w;
|
||||
size_type total_len = w <= 0 || static_cast<size_type>(w) < b.size()? b.size() : static_cast<size_type>(w);
|
||||
const string_type padding (total_len - b.size(), fill_char);
|
||||
string_type expected;
|
||||
boost::to_string(b, expected);
|
||||
@@ -1139,7 +1360,7 @@ struct bitset_test {
|
||||
// {digits} or part of them
|
||||
const typename Bitset::size_type max_digits =
|
||||
w > 0 && static_cast<typename Bitset::size_type>(w) < b.max_size()
|
||||
? w : b.max_size();
|
||||
? static_cast<typename Bitset::size_type>(w) : b.max_size();
|
||||
|
||||
for( ; pos < len && (pos - after_spaces) < max_digits; ++pos) {
|
||||
if(!is_one_or_zero(is, str[pos]))
|
||||
@@ -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
|
||||
@@ -15,6 +20,33 @@
|
||||
|
||||
#include "boost/detail/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,6 +509,14 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
bit_vec[i] = long_string[n - 1 - i] == '0' ? 0 : 1;
|
||||
Tests::operator_bracket(b, bit_vec);
|
||||
}
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
{
|
||||
typedef boost::dynamic_bitset<Block,
|
||||
minimal_allocator<Block> > Bitset;
|
||||
Bitset b;
|
||||
bitset_test<Bitset>::max_size(b);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
@@ -1,6 +1,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
|
||||
@@ -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,6 +339,33 @@ 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
|
||||
@@ -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
|
||||
@@ -14,7 +16,6 @@
|
||||
#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,6 +798,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
test_main(int, char*[])
|
||||
{
|
||||
@@ -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 ";
|
||||
|
||||
@@ -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);
|
||||
111
test/dyn_bitset_unit_tests5.cpp
Normal file
111
test/dyn_bitset_unit_tests5.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
// -----------------------------------------------------------
|
||||
// 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/detail/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/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 test_main(int, char*[])
|
||||
{
|
||||
run_test_cases<unsigned char>();
|
||||
run_test_cases<unsigned short>();
|
||||
run_test_cases<unsigned int>();
|
||||
run_test_cases<unsigned long>();
|
||||
# ifdef BOOST_HAS_LONG_LONG
|
||||
run_test_cases< ::boost::ulong_long_type>();
|
||||
# endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
30
test/test_ambiguous_set.cpp
Normal file
30
test/test_ambiguous_set.cpp
Normal 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/detail/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();
|
||||
}
|
||||
28
test/test_lowest_bit.cpp
Normal file
28
test/test_lowest_bit.cpp
Normal 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/detail/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();
|
||||
}
|
||||
Reference in New Issue
Block a user