mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-20 04:32:12 +00:00
Compare commits
2 Commits
master
...
boost-1.30
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b1fcc1e54 | ||
|
|
4a44c8fdf5 |
@@ -1,97 +0,0 @@
|
||||
# Copyright 2016, 2017 Peter Dimov
|
||||
# Copyright 2017 - 2019 James E. King III
|
||||
# Copyright 2019 - 2021 Alexander Grund
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#
|
||||
# Generic Appveyor build script for boostorg repositories
|
||||
# See: https://github.com/boostorg/boost-ci/
|
||||
#
|
||||
# Instructions for customizing this script for your library:
|
||||
#
|
||||
# 1. Customize the compilers and language levels you want.
|
||||
# 2. If you have more than include/, src/, test/, example/, examples/,
|
||||
# benchmark/ or tools/ directories, set the environment variable DEPINST.
|
||||
# For example if your build uses code in "bench/" and "fog/" directories:
|
||||
# - DEPINST: --include bench --include fog
|
||||
# 3. Enable pull request builds in your boostorg/<library> account.
|
||||
#
|
||||
# That's it - the script will do everything else for you.
|
||||
#
|
||||
|
||||
version: 1.0.{build}-{branch}
|
||||
|
||||
shallow_clone: true
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- /bugfix\/.*/
|
||||
- /feature\/.*/
|
||||
- /fix\/.*/
|
||||
- /pr\/.*/
|
||||
|
||||
skip_commits:
|
||||
files:
|
||||
- LICENSE
|
||||
- meta/*
|
||||
- README.md
|
||||
|
||||
matrix:
|
||||
fast_finish: false
|
||||
# Adding MAYFAIL to any matrix job allows it to fail but the build stays green:
|
||||
allow_failures:
|
||||
- MAYFAIL: true
|
||||
|
||||
environment:
|
||||
global:
|
||||
B2_CI_VERSION: 1
|
||||
GIT_FETCH_JOBS: 4
|
||||
# see: http://www.boost.org/build/doc/html/bbv2/overview/invocation.html#bbv2.overview.invocation.properties
|
||||
# to use the default for a given environment, comment it out; recommend you build debug and release however:
|
||||
# on Windows it is important to exercise all the possibilities, especially shared vs static, however most
|
||||
# libraries that care about this exercise it in their Jamfiles...
|
||||
B2_ADDRESS_MODEL: 32,64
|
||||
B2_LINK: shared,static
|
||||
# B2_THREADING: threading=multi,single
|
||||
B2_VARIANT: release
|
||||
|
||||
matrix:
|
||||
- FLAVOR: Visual Studio 2017 C++2a Strict
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
B2_CXXFLAGS: -permissive-
|
||||
B2_CXXSTD: 2a
|
||||
B2_TOOLSET: msvc-14.1
|
||||
|
||||
- FLAVOR: Visual Studio 2017 C++14/17
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
B2_CXXSTD: 14,17
|
||||
B2_TOOLSET: msvc-14.1
|
||||
|
||||
- FLAVOR: cygwin (32-bit)
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ADDPATH: C:\cygwin\bin;
|
||||
B2_ADDRESS_MODEL: 32
|
||||
B2_CXXSTD: 11,14,1z
|
||||
B2_TOOLSET: gcc
|
||||
|
||||
- FLAVOR: cygwin (64-bit)
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ADDPATH: C:\cygwin64\bin;
|
||||
B2_ADDRESS_MODEL: 64
|
||||
B2_CXXSTD: 11,14,1z
|
||||
B2_TOOLSET: gcc
|
||||
|
||||
install:
|
||||
- git clone --depth 1 https://github.com/boostorg/boost-ci.git C:\boost-ci-cloned
|
||||
# Copy ci folder if not testing Boost.CI
|
||||
- if NOT "%APPVEYOR_PROJECT_NAME%" == "boost-ci" xcopy /s /e /q /i /y C:\boost-ci-cloned\ci .\ci
|
||||
- rmdir /s /q C:\boost-ci-cloned
|
||||
- ci\appveyor\install.bat
|
||||
|
||||
build: off
|
||||
|
||||
test_script: ci\build.bat
|
||||
|
||||
168
.clang-format
168
.clang-format
@@ -1,168 +0,0 @@
|
||||
# ============================================================================
|
||||
# Copyright 2025 Gennaro Prota.
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
# ============================================================================
|
||||
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignArrayOfStructures: Left
|
||||
AlignConsecutiveAssignments: AcrossEmptyLinesAndComments
|
||||
AlignConsecutiveBitFields: AcrossEmptyLinesAndComments
|
||||
AlignConsecutiveDeclarations: AcrossEmptyLinesAndComments
|
||||
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: AlignAfterOperator
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortLambdasOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: AllDefinitions
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
AttributeMacros: [ ]
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: true
|
||||
AfterClass: true
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: true
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeConceptDeclarations: true
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: true
|
||||
BreakInheritanceList: BeforeComma
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 0
|
||||
CommentPragmas: ''
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: false
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: Always
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
ForEachMacros: [ ]
|
||||
IfMacros: [ ]
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
- Regex: 'top_level_namespace.hpp'
|
||||
Priority: 0
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 1
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: ''
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseLabels: false
|
||||
IndentCaseBlocks: false
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentRequires: true
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertTrailingCommas: Wrapped
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
LambdaBodyIndentation: Signature
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PointerAlignment: Middle
|
||||
PPIndentWidth: -1
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: true
|
||||
ShortNamespaceLines: 1
|
||||
SortIncludes: CaseSensitive
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: true
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceAroundPointerQualifiers: Both
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: Always
|
||||
SpacesInConditionalStatement: true
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParentheses: true
|
||||
SpacesInSquareBrackets: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
BitFieldColonSpacing: Both
|
||||
Standard: Latest
|
||||
StatementAttributeLikeMacros: [ ]
|
||||
StatementMacros: [ ]
|
||||
TabWidth: 8
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
WhitespaceSensitiveMacros: [ ]
|
||||
|
||||
# Local Variables:
|
||||
# mode: yaml
|
||||
# End:
|
||||
# vim: set ft=yaml:
|
||||
31
.codecov.yml
31
.codecov.yml
@@ -1,31 +0,0 @@
|
||||
# Copyright 2019 - 2021 Alexander Grund
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
#
|
||||
# Sample codecov configuration file. Edit as required
|
||||
|
||||
codecov:
|
||||
max_report_age: off
|
||||
require_ci_to_pass: yes
|
||||
notify:
|
||||
# Increase this if you have multiple coverage collection jobs
|
||||
after_n_builds: 2
|
||||
wait_for_ci: yes
|
||||
|
||||
parsers:
|
||||
gcov:
|
||||
branch_detection:
|
||||
conditional: yes
|
||||
loop: yes
|
||||
method: no
|
||||
macro: no
|
||||
|
||||
# Change how pull request comments look
|
||||
comment:
|
||||
layout: "reach,diff,flags,files,footer"
|
||||
|
||||
# Ignore specific files or folders. Glob patterns are supported.
|
||||
# See https://docs.codecov.com/docs/ignoring-paths
|
||||
ignore:
|
||||
- libs/dynamic_bitset/test/
|
||||
- test/
|
||||
110
.github/workflows/ci.yml
vendored
110
.github/workflows/ci.yml
vendored
@@ -1,110 +0,0 @@
|
||||
#
|
||||
# Copyright 2020-2021 Peter Dimov
|
||||
# Copyright 2021 Andrey Semashev
|
||||
# Copyright 2021-2024 Alexander Grund
|
||||
# Copyright 2022-2025 James E. King III
|
||||
# Copyright 2023 Alan de Freitas
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
#
|
||||
# This workflow uses the Boost.CI reusable workflow which builds a variety of
|
||||
# configurations of your project, runs tests, and generates code coverage reports.
|
||||
#
|
||||
# To use it, copy this file into your repository as `.github/workflows/ci.yml` and
|
||||
# customize it appropriately.
|
||||
#
|
||||
---
|
||||
name: Boost.CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
- bugfix/**
|
||||
- feature/**
|
||||
- fix/**
|
||||
- pr/**
|
||||
paths-ignore:
|
||||
- LICENSE
|
||||
- meta/**
|
||||
- README.md
|
||||
|
||||
jobs:
|
||||
call-boost-ci:
|
||||
name: Run Boost.CI
|
||||
uses: boostorg/boost-ci/.github/workflows/reusable.yml@master
|
||||
with:
|
||||
# These compilers fail.
|
||||
exclude_compiler: 'clang-3.5,clang-3.6,clang-3.7,clang-3.8,gcc-4.8,gcc-4.9'
|
||||
secrets:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
COVERITY_SCAN_NOTIFICATION_EMAIL: ${{ secrets.COVERITY_SCAN_NOTIFICATION_EMAIL }}
|
||||
COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||
|
||||
antora:
|
||||
name: Antora docs
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- { name: Windows, os: windows-latest }
|
||||
- { name: Ubuntu, os: ubuntu-latest }
|
||||
- { name: macOS, os: macos-15 }
|
||||
runs-on: ${{ matrix.os }}
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- name: Install packages
|
||||
uses: alandefreitas/cpp-actions/package-install@v1.8.8
|
||||
with:
|
||||
apt-get: git cmake
|
||||
|
||||
- name: Clone Boost.DynamicBitset
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Clone Boost
|
||||
uses: alandefreitas/cpp-actions/boost-clone@v1.8.8
|
||||
id: boost-clone
|
||||
with:
|
||||
branch: ${{ (github.ref_name == 'master' && github.ref_name) || 'develop' }}
|
||||
boost-dir: ../boost-source
|
||||
scan-modules-dir: .
|
||||
scan-modules-ignore: dynamic_bitset
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
|
||||
- name: Setup Ninja
|
||||
if: runner.os == 'Windows'
|
||||
uses: seanmiddleditch/gha-setup-ninja@v5
|
||||
|
||||
- name: Build Antora docs
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
git config --global --add safe.directory "$(pwd)"
|
||||
|
||||
cd ..
|
||||
BOOST_SRC_DIR="$(pwd)/boost-source"
|
||||
export BOOST_SRC_DIR
|
||||
|
||||
cd dynamic_bitset
|
||||
cd doc
|
||||
bash ./build_antora.sh
|
||||
|
||||
# Antora returns zero even if it fails, so we check if the site directory exists.
|
||||
if [ ! -d "html" ]
|
||||
then
|
||||
echo "Antora build failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Create Antora docs artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: antora-docs-${{ matrix.name }}
|
||||
path: doc/html
|
||||
@@ -1,96 +0,0 @@
|
||||
# Generated by `boostdep --cmake dynamic_bitset`
|
||||
# Copyright 2020 Peter Dimov
|
||||
# Copyright 2025 Gennaro Prota
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.16)
|
||||
|
||||
project(boost_dynamic_bitset VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
|
||||
set(BOOST_DYNAMIC_BITSET_IS_ROOT OFF)
|
||||
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
set(BOOST_DYNAMIC_BITSET_IS_ROOT ON)
|
||||
endif ()
|
||||
|
||||
add_library(boost_dynamic_bitset INTERFACE)
|
||||
add_library(Boost::dynamic_bitset ALIAS boost_dynamic_bitset)
|
||||
|
||||
target_include_directories(boost_dynamic_bitset INTERFACE include)
|
||||
|
||||
if (BOOST_DYNAMIC_BITSET_IS_ROOT)
|
||||
# This means this script will be executed as the root CMakeLists.txt
|
||||
# so the Boost:: targets are not available unless we explicitly include
|
||||
# them here. MrDocs executes this script as root too.
|
||||
if (NOT DEFINED BOOST_SRC_DIR AND DEFINED ENV{BOOST_SRC_DIR})
|
||||
set(DEFAULT_BOOST_SRC_DIR "$ENV{BOOST_SRC_DIR}")
|
||||
else ()
|
||||
set(DEFAULT_BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
|
||||
endif ()
|
||||
set(BOOST_SRC_DIR ${DEFAULT_BOOST_SRC_DIR} CACHE STRING "Boost source dir to use when running CMake from this directory")
|
||||
if (NOT IS_ABSOLUTE ${BOOST_SRC_DIR})
|
||||
set(BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${BOOST_SRC_DIR}")
|
||||
endif ()
|
||||
|
||||
# Validate BOOST_SRC_DIR
|
||||
set(BOOST_SRC_DIR_IS_VALID ON)
|
||||
foreach (F "CMakeLists.txt" "Jamroot" "boost-build.jam" "bootstrap.sh" "libs")
|
||||
if (NOT EXISTS "${BOOST_SRC_DIR}/${F}")
|
||||
message(STATUS "${BOOST_SRC_DIR}/${F} does not exist. Fallback to find_package.")
|
||||
set(BOOST_SRC_DIR_IS_VALID OFF)
|
||||
break()
|
||||
endif ()
|
||||
endforeach ()
|
||||
if (NOT BOOST_SRC_DIR_IS_VALID)
|
||||
message(FATAL_ERROR "BOOST_SRC_DIR is not valid. Please set it to the root of a Boost checkout.")
|
||||
endif ()
|
||||
|
||||
# If BOOST_SRC_DIR is valid, fallback to find_package
|
||||
set(CMAKE_FOLDER Dependencies)
|
||||
set(BOOST_INCLUDE_LIBRARIES assert config container_hash core throw_exception)
|
||||
set(BOOST_EXCLUDE_LIBRARIES dynamic_bitset)
|
||||
set(PREV_BUILD_TESTING ${BUILD_TESTING})
|
||||
set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE)
|
||||
add_subdirectory(${BOOST_SRC_DIR} Dependencies/boost EXCLUDE_FROM_ALL)
|
||||
set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${BOOST_SRC_DIR}/tools/cmake/include")
|
||||
unset(CMAKE_FOLDER)
|
||||
endif()
|
||||
|
||||
target_link_libraries(boost_dynamic_bitset
|
||||
INTERFACE
|
||||
Boost::assert
|
||||
Boost::config
|
||||
Boost::container_hash
|
||||
Boost::core
|
||||
Boost::throw_exception
|
||||
)
|
||||
|
||||
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
|
||||
|
||||
add_subdirectory(test)
|
||||
|
||||
endif()
|
||||
|
||||
if (DYNAMIC_BITSET_MRDOCS_BUILD)
|
||||
set(INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include")
|
||||
|
||||
# Create a temporary source file that includes boost/dynamic_bitset.hpp.
|
||||
set(TEMP_CPP_FILE "${CMAKE_CURRENT_BINARY_DIR}/dynamic_bitset_for_mrdocs.cpp")
|
||||
file(WRITE ${TEMP_CPP_FILE} "// This file is generated automatically by CMake\n\n")
|
||||
file(APPEND ${TEMP_CPP_FILE} "#include \"boost/dynamic_bitset.hpp\"\n")
|
||||
|
||||
# Create a custom target for MrDocs.
|
||||
add_library(dynamic_bitset_mrdocs_target ${TEMP_CPP_FILE})
|
||||
|
||||
# This is to get the documentation of the constructor from basic_string_view.
|
||||
set_target_properties(dynamic_bitset_mrdocs_target PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES)
|
||||
|
||||
# Set any other target properties here.
|
||||
target_include_directories(dynamic_bitset_mrdocs_target PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
target_link_libraries(dynamic_bitset_mrdocs_target PRIVATE boost_dynamic_bitset)
|
||||
file(GLOB BOOST_MODULE_PATHS "$ENV{BOOST_SRC_DIR}/libs/*/include")
|
||||
target_include_directories(dynamic_bitset_mrdocs_target PRIVATE ${BOOST_MODULE_PATHS})
|
||||
|
||||
# Don't create any other targets.
|
||||
return()
|
||||
endif()
|
||||
40
Jamfile
Normal file
40
Jamfile
Normal file
@@ -0,0 +1,40 @@
|
||||
subproject libs/dynamic_bitset ;
|
||||
|
||||
unit-test dyn_bitset_unit_tests1
|
||||
: dyn_bitset_unit_tests1.cpp
|
||||
<lib>../test/build/test_exec_monitor
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
unit-test dyn_bitset_unit_tests2
|
||||
: dyn_bitset_unit_tests2.cpp
|
||||
<lib>../test/build/test_exec_monitor
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
unit-test dyn_bitset_unit_tests3
|
||||
: dyn_bitset_unit_tests3.cpp
|
||||
<lib>../test/build/test_exec_monitor
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
exe timing_tests
|
||||
: timing_tests.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
exe example1
|
||||
: example1.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
exe example2
|
||||
: example2.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
exe example3
|
||||
: example3.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
23
LICENSE
23
LICENSE
@@ -1,23 +0,0 @@
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
25
README.md
25
README.md
@@ -1,25 +0,0 @@
|
||||
DynamicBitset, part of the [Boost C++ Libraries](https://github.com/boostorg), is a bit vector similar to std::bitset but dynamically resizable.
|
||||
|
||||
### License
|
||||
|
||||
Distributed under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt).
|
||||
|
||||
### Properties
|
||||
|
||||
* C++11
|
||||
* Header-only
|
||||
|
||||
### Build status
|
||||
|
||||
<!-- boost-ci/tools/makebadges.sh --project dynamic_bitset --appveyor n7bki5ka3v918r5r --codecov PVG5jth1ez --coverity 16167 -->
|
||||
| Branch | GitHub Actions | AppVeyor | Coverity Scan | Codecov | Deps | Docs | Tests |
|
||||
| :-------------: | -------------- | -------- | ------------- | ------- | ---- | ---- | ----- |
|
||||
| [`master`](https://github.com/boostorg/dynamic_bitset/tree/master) | [](https://github.com/boostorg/dynamic_bitset/actions?query=branch:master) | [](https://ci.appveyor.com/project/cppalliance/dynamic-bitset/branch/master) | [](https://scan.coverity.com/projects/boostorg-dynamic_bitset) | [](https://codecov.io/gh/boostorg/dynamic_bitset/tree/master) | [](https://pdimov.github.io/boostdep-report/master/dynamic_bitset.html) | [](https://www.boost.org/doc/libs/master/libs/dynamic_bitset) | [](https://www.boost.org/development/tests/master/developer/dynamic_bitset.html)
|
||||
| [`develop`](https://github.com/boostorg/dynamic_bitset/tree/develop) | [](https://github.com/boostorg/dynamic_bitset/actions?query=branch:develop) | [](https://ci.appveyor.com/project/cppalliance/dynamic-bitset/branch/develop) | [](https://scan.coverity.com/projects/boostorg-dynamic_bitset) | [](https://codecov.io/gh/boostorg/dynamic_bitset/tree/develop) | [](https://pdimov.github.io/boostdep-report/develop/dynamic_bitset.html) | [](https://www.boost.org/doc/libs/develop/libs/dynamic_bitset) | [](https://www.boost.org/development/tests/develop/developer/dynamic_bitset.html)
|
||||
|
||||
### More information
|
||||
|
||||
* [Ask questions](https://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-dynamic_bitset).
|
||||
* [Report bugs](https://github.com/boostorg/dynamic_bitset/issues): Be sure to mention the Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good, as well.
|
||||
* Submit your patches as pull requests against the **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt).
|
||||
* Discussions about the library are held on the [Boost developers mailing list](https://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](https://www.boost.org/community/policy.html) before posting, and add the `[dynamic_bitset]` tag at the beginning of the subject line.
|
||||
727
bitset_test.hpp
Normal file
727
bitset_test.hpp
Normal file
@@ -0,0 +1,727 @@
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// 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.
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm> // for std::min
|
||||
#include <fstream>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
// Extract the bit at position n from num.
|
||||
template <typename Block>
|
||||
inline bool nth_bit(Block num, std::size_t n)
|
||||
{
|
||||
// Move the nth bit to position 0 and then clear all other bits.
|
||||
return (num >> n) & 1;
|
||||
}
|
||||
inline unsigned long max_num(std::size_t num_bits)
|
||||
{
|
||||
using namespace std; // for std::pow, VC++ workaround -JGS
|
||||
return (unsigned long)(pow((double)2, (double)num_bits));
|
||||
}
|
||||
|
||||
|
||||
// constructors
|
||||
// default (can't do this generically)
|
||||
|
||||
// from unsigned long
|
||||
|
||||
template <typename Bitset>
|
||||
struct bitset_test {
|
||||
|
||||
static void from_unsigned_long(Bitset b, unsigned long num)
|
||||
{
|
||||
// initializes the first M bit position to the cooresponding bit
|
||||
// values in val. M is the smaller of N and the value CHAR_BIT *
|
||||
// sizeof(unsigned long)
|
||||
|
||||
// missing from the std?
|
||||
// if M < N then the remaining bit positions are initialized to zero
|
||||
|
||||
std::size_t N = b.size();
|
||||
std::size_t M = std::min(N, CHAR_BIT * sizeof(unsigned long));
|
||||
std::size_t I;
|
||||
for (I = 0; I < M; ++I)
|
||||
BOOST_CHECK(b[I] == nth_bit(num, I));
|
||||
for (; I < N; ++I)
|
||||
BOOST_CHECK(b[I] == 0);
|
||||
}
|
||||
|
||||
// from string
|
||||
static void from_string(const std::string& str, std::size_t pos,
|
||||
std::size_t n)
|
||||
{
|
||||
if (pos > str.size()) {
|
||||
// Not in range, doesn't satisfy precondition.
|
||||
} else {
|
||||
std::size_t rlen = std::min(n, str.size() - pos);
|
||||
|
||||
// Throws invalid_argument if any of the rlen characters in str
|
||||
// beginning at position pos is other than 0 or 1.
|
||||
bool any_non_zero_or_one = false;
|
||||
for (std::size_t i = pos; i < pos + rlen; ++i)
|
||||
if (! (str[i] == '0' || str[i] == '1'))
|
||||
any_non_zero_or_one = true;
|
||||
if (any_non_zero_or_one) {
|
||||
// Input does not satisfy precondition.
|
||||
} else {
|
||||
// Construct an object, initializing the first M bit position to
|
||||
// values determined from the corresponding characters in the
|
||||
// str. M is the smaller of N and rlen. Character position pos
|
||||
// + M - 1 corresponds to bit position zero. Subsequent
|
||||
// decreasing character position correspond to increasing bit
|
||||
// positions.
|
||||
|
||||
Bitset b(str, pos, n);
|
||||
std::size_t N = b.size();
|
||||
std::size_t M = std::min(N, rlen);
|
||||
std::size_t j;
|
||||
for (j = 0; j < M; ++j)
|
||||
BOOST_CHECK(b[j] == (str[pos + M - 1 - j] == '1'));
|
||||
// If M < N, remaining bit positions are initialize to zero
|
||||
for (; j < N; ++j)
|
||||
BOOST_CHECK(b[j] == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef typename Bitset::block_type Block;
|
||||
|
||||
// PRE: std::equal(first1, last1, first2) == true
|
||||
static void from_block_range(std::vector<Block> blocks)
|
||||
{
|
||||
{
|
||||
Bitset bset(blocks.begin(), blocks.end());
|
||||
std::size_t n = blocks.size();
|
||||
for (std::size_t b = 0; b < n; ++b) {
|
||||
for (std::size_t i = 0; i < sizeof(Block) * CHAR_BIT; ++i) {
|
||||
std::size_t bit = b * sizeof(Block) * CHAR_BIT + i;
|
||||
BOOST_CHECK(bset[bit] == nth_bit(blocks[b], i));
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
Bitset bset(blocks.size() * sizeof(Block) * CHAR_BIT);
|
||||
boost::from_block_range(blocks.begin(), blocks.end(), bset);
|
||||
std::size_t n = blocks.size();
|
||||
for (std::size_t b = 0; b < n; ++b) {
|
||||
for (std::size_t i = 0; i < sizeof(Block) * CHAR_BIT; ++i) {
|
||||
std::size_t bit = b * sizeof(Block) * CHAR_BIT + i;
|
||||
BOOST_CHECK(bset[bit] == nth_bit(blocks[b], i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copy constructor (absent from std::bitset)
|
||||
static void copy_constructor(const Bitset& b)
|
||||
{
|
||||
Bitset copy(b);
|
||||
BOOST_CHECK(b == copy);
|
||||
|
||||
// Changes to the copy do not affect the original
|
||||
if (b.size() > 0) {
|
||||
std::size_t pos = copy.size() / 2;
|
||||
copy.flip(pos);
|
||||
BOOST_CHECK(copy[pos] != b[pos]);
|
||||
}
|
||||
}
|
||||
|
||||
// assignment operator (absent from std::bitset)
|
||||
static void assignment_operator(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
b = rhs;
|
||||
BOOST_CHECK(b == rhs);
|
||||
|
||||
// Changes to the copy do not affect the original
|
||||
if (b.size() > 0) {
|
||||
std::size_t pos = b.size() / 2;
|
||||
b.flip(pos);
|
||||
BOOST_CHECK(b[pos] != rhs[pos]);
|
||||
}
|
||||
}
|
||||
|
||||
static void resize(const Bitset& lhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
|
||||
// Test no change in size
|
||||
b.resize(lhs.size());
|
||||
BOOST_CHECK(b == lhs);
|
||||
|
||||
// Test increase in size
|
||||
b.resize(lhs.size() * 2, true);
|
||||
|
||||
std::size_t i;
|
||||
for (i = 0; i < lhs.size(); ++i)
|
||||
BOOST_CHECK(b[i] == lhs[i]);
|
||||
for (; i < b.size(); ++i)
|
||||
BOOST_CHECK(b[i] == true);
|
||||
|
||||
// Test decrease in size
|
||||
b.resize(lhs.size());
|
||||
for (i = 0; i < lhs.size(); ++i)
|
||||
BOOST_CHECK(b[i] == lhs[i]);
|
||||
}
|
||||
|
||||
static void clear(const Bitset& lhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
b.clear();
|
||||
BOOST_CHECK(b.size() == 0);
|
||||
}
|
||||
|
||||
static void append_bit(const Bitset& lhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
b.push_back(true);
|
||||
BOOST_CHECK(b.size() == lhs.size() + 1);
|
||||
BOOST_CHECK(b[b.size() - 1] == true);
|
||||
for (std::size_t i = 0; i < lhs.size(); ++i)
|
||||
BOOST_CHECK(b[i] == lhs[i]);
|
||||
|
||||
b.push_back(false);
|
||||
BOOST_CHECK(b.size() == lhs.size() + 2);
|
||||
BOOST_CHECK(b[b.size() - 1] == false);
|
||||
BOOST_CHECK(b[b.size() - 2] == true);
|
||||
for (std::size_t j = 0; j < lhs.size(); ++j)
|
||||
BOOST_CHECK(b[j] == lhs[j]);
|
||||
}
|
||||
|
||||
static void append_block(const Bitset& lhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
Block value(128);
|
||||
b.append(value);
|
||||
BOOST_CHECK(b.size() == lhs.size() + Bitset::bits_per_block);
|
||||
for (std::size_t i = 0; i < Bitset::bits_per_block; ++i)
|
||||
BOOST_CHECK(b[lhs.size() + i] == bool((value >> i) & 1));
|
||||
}
|
||||
|
||||
static void append_block_range(const Bitset& lhs, std::vector<Block> blocks)
|
||||
{
|
||||
Bitset b(lhs), c(lhs);
|
||||
b.append(blocks.begin(), blocks.end());
|
||||
for (typename std::vector<Block>::iterator i = blocks.begin();
|
||||
i != blocks.end(); ++i)
|
||||
c.append(*i);
|
||||
BOOST_CHECK(b == c);
|
||||
}
|
||||
|
||||
// operator[] and reference members
|
||||
// PRE: b[i] == bit_vec[i]
|
||||
static void operator_bracket(const Bitset& lhs, const std::vector<bool>& bit_vec)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
std::size_t i, j, k;
|
||||
|
||||
// x = b[i]
|
||||
// x = ~b[i]
|
||||
for (i = 0; i < b.size(); ++i) {
|
||||
bool x = b[i];
|
||||
BOOST_CHECK(x == bit_vec[i]);
|
||||
x = ~b[i];
|
||||
BOOST_CHECK(x == !bit_vec[i]);
|
||||
}
|
||||
Bitset prev(b);
|
||||
|
||||
// b[i] = x
|
||||
for (j = 0; j < b.size(); ++j) {
|
||||
bool x = !prev[j];
|
||||
b[j] = x;
|
||||
for (k = 0; k < b.size(); ++k)
|
||||
if (j == k)
|
||||
BOOST_CHECK(b[k] == x);
|
||||
else
|
||||
BOOST_CHECK(b[k] == prev[k]);
|
||||
b[j] = prev[j];
|
||||
}
|
||||
b.flip();
|
||||
|
||||
// b[i] = b[j]
|
||||
for (i = 0; i < b.size(); ++i) {
|
||||
b[i] = prev[i];
|
||||
for (j = 0; j < b.size(); ++j) {
|
||||
if (i == j)
|
||||
BOOST_CHECK(b[j] == prev[j]);
|
||||
else
|
||||
BOOST_CHECK(b[j] == !prev[j]);
|
||||
}
|
||||
b[i] = !prev[i];
|
||||
}
|
||||
|
||||
// b[i].flip()
|
||||
for (i = 0; i < b.size(); ++i) {
|
||||
b[i].flip();
|
||||
for (j = 0; j < b.size(); ++j) {
|
||||
if (i == j)
|
||||
BOOST_CHECK(b[j] == prev[j]);
|
||||
else
|
||||
BOOST_CHECK(b[j] == !prev[j]);
|
||||
}
|
||||
b[i].flip();
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// bitwise operators
|
||||
|
||||
// bitwise and assignment
|
||||
|
||||
// PRE: b.size() == rhs.size()
|
||||
static void and_assignment(const Bitset& b, const Bitset& rhs)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
Bitset prev(lhs);
|
||||
lhs &= rhs;
|
||||
// Clears each bit in lhs for which the corresponding bit in rhs is
|
||||
// clear, and leaves all other bits unchanged.
|
||||
for (std::size_t I = 0; I < lhs.size(); ++I)
|
||||
if (rhs[I] == 0)
|
||||
BOOST_CHECK(lhs[I] == 0);
|
||||
else
|
||||
BOOST_CHECK(lhs[I] == prev[I]);
|
||||
}
|
||||
|
||||
// PRE: b.size() == rhs.size()
|
||||
static void or_assignment(const Bitset& b, const Bitset& rhs)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
Bitset prev(lhs);
|
||||
lhs |= rhs;
|
||||
// Sets each bit in lhs for which the corresponding bit in rhs is set, and
|
||||
// leaves all other bits unchanged.
|
||||
for (std::size_t I = 0; I < lhs.size(); ++I)
|
||||
if (rhs[I] == 1)
|
||||
BOOST_CHECK(lhs[I] == 1);
|
||||
else
|
||||
BOOST_CHECK(lhs[I] == prev[I]);
|
||||
}
|
||||
|
||||
// PRE: b.size() == rhs.size()
|
||||
static void xor_assignment(const Bitset& b, const Bitset& rhs)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
Bitset prev(lhs);
|
||||
lhs ^= rhs;
|
||||
// Flips each bit in lhs for which the corresponding bit in rhs is set,
|
||||
// and leaves all other bits unchanged.
|
||||
for (std::size_t I = 0; I < lhs.size(); ++I)
|
||||
if (rhs[I] == 1)
|
||||
BOOST_CHECK(lhs[I] == !prev[I]);
|
||||
else
|
||||
BOOST_CHECK(lhs[I] == prev[I]);
|
||||
}
|
||||
|
||||
// PRE: b.size() == rhs.size()
|
||||
static void sub_assignment(const Bitset& b, const Bitset& rhs)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
Bitset prev(lhs);
|
||||
lhs -= rhs;
|
||||
// Resets each bit in lhs for which the corresponding bit in rhs is set,
|
||||
// and leaves all other bits unchanged.
|
||||
for (std::size_t I = 0; I < lhs.size(); ++I)
|
||||
if (rhs[I] == 1)
|
||||
BOOST_CHECK(lhs[I] == 0);
|
||||
else
|
||||
BOOST_CHECK(lhs[I] == prev[I]);
|
||||
}
|
||||
|
||||
static void shift_left_assignment(const Bitset& b, std::size_t pos)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
Bitset prev(lhs);
|
||||
lhs <<= pos;
|
||||
// Replaces each bit at position I in lhs with the following value:
|
||||
// - If I < pos, the new value is zero
|
||||
// - If I >= pos, the new value is the previous value of the bit at
|
||||
// position I - pos
|
||||
for (std::size_t I = 0; I < lhs.size(); ++I)
|
||||
if (I < pos)
|
||||
BOOST_CHECK(lhs[I] == 0);
|
||||
else
|
||||
BOOST_CHECK(lhs[I] == prev[I - pos]);
|
||||
}
|
||||
|
||||
static void shift_right_assignment(const Bitset& b, std::size_t pos)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
Bitset prev(lhs);
|
||||
lhs >>= pos;
|
||||
// Replaces each bit at position I in lhs with the following value:
|
||||
// - If pos >= N - I, the new value is zero
|
||||
// - If pos < N - I, the new value is the previous value of the bit at
|
||||
// position I + pos
|
||||
std::size_t N = lhs.size();
|
||||
for (std::size_t I = 0; I < N; ++I)
|
||||
if (pos >= N - I)
|
||||
BOOST_CHECK(lhs[I] == 0);
|
||||
else
|
||||
BOOST_CHECK(lhs[I] == prev[I + pos]);
|
||||
}
|
||||
|
||||
|
||||
static void set_all(const Bitset& b)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
lhs.set();
|
||||
for (std::size_t I = 0; I < lhs.size(); ++I)
|
||||
BOOST_CHECK(lhs[I] == 1);
|
||||
}
|
||||
|
||||
static void set_one(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.
|
||||
lhs.set(pos, value);
|
||||
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 reset_all(const Bitset& b)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
// Resets all bits in lhs
|
||||
lhs.reset();
|
||||
for (std::size_t I = 0; I < lhs.size(); ++I)
|
||||
BOOST_CHECK(lhs[I] == 0);
|
||||
}
|
||||
|
||||
static void reset_one(const Bitset& b, std::size_t pos)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
std::size_t N = lhs.size();
|
||||
if (pos < N) {
|
||||
Bitset prev(lhs);
|
||||
lhs.reset(pos);
|
||||
// Resets the bit at position pos in lhs
|
||||
BOOST_CHECK(lhs[pos] == 0);
|
||||
|
||||
// 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_flip(const Bitset& b)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
Bitset x(lhs);
|
||||
BOOST_CHECK(~lhs == x.flip());
|
||||
}
|
||||
|
||||
static void flip_all(const Bitset& b)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
std::size_t N = lhs.size();
|
||||
Bitset prev(lhs);
|
||||
lhs.flip();
|
||||
// Toggles all the bits in lhs
|
||||
for (std::size_t I = 0; I < N; ++I)
|
||||
BOOST_CHECK(lhs[I] == !prev[I]);
|
||||
}
|
||||
|
||||
static void flip_one(const Bitset& b, std::size_t pos)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
std::size_t N = lhs.size();
|
||||
if (pos < N) {
|
||||
Bitset prev(lhs);
|
||||
lhs.flip(pos);
|
||||
// Toggles the bit at position pos in lhs
|
||||
BOOST_CHECK(lhs[pos] == !prev[pos]);
|
||||
|
||||
// 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.
|
||||
}
|
||||
}
|
||||
|
||||
// to_ulong()
|
||||
static void to_ulong(const Bitset& lhs)
|
||||
{
|
||||
std::size_t N = lhs.size();
|
||||
std::size_t n = CHAR_BIT * sizeof(unsigned long);
|
||||
bool will_overflow = false;
|
||||
for (std::size_t I = n; I < N; ++I)
|
||||
if (lhs[I] != 0)
|
||||
will_overflow = true;
|
||||
if (will_overflow) {
|
||||
try {
|
||||
(void)lhs.to_ulong();
|
||||
BOOST_CHECK(false); // It should have thrown and exception
|
||||
} catch (std::overflow_error) {
|
||||
// Good!
|
||||
} catch (...) {
|
||||
BOOST_CHECK(false); // threw the wrong exception
|
||||
}
|
||||
} else {
|
||||
unsigned long num = lhs.to_ulong();
|
||||
// Make sure the number is right
|
||||
for (std::size_t I = 0; I < N; ++I)
|
||||
BOOST_CHECK(lhs[I] == nth_bit(num, I));
|
||||
}
|
||||
}
|
||||
|
||||
// to_string()
|
||||
static void to_string(const Bitset& b)
|
||||
{
|
||||
// Construct a string object of the appropriate type and initializes
|
||||
// it to a string of length N characters. Each character is determined
|
||||
// by the value of its corresponding bit position in b. Character
|
||||
// position N - 1 corresponds to bit position zero. Sebsequent
|
||||
// decreasing character positions correspond to increasing bit
|
||||
// positions. Bit value zero becomes the charactet 0, bit value one
|
||||
// becomes the character 1.
|
||||
std::string str;
|
||||
boost::to_string(b, str);
|
||||
std::size_t N = b.size();
|
||||
BOOST_CHECK(str.size() == b.size());
|
||||
for (std::size_t I = 0; I < b.size(); ++I)
|
||||
BOOST_CHECK(b[I] == 0 ? (str[N - 1 - I] == '0') : (str[N - 1 - I] == '1'));
|
||||
}
|
||||
|
||||
static void count(const Bitset& b)
|
||||
{
|
||||
std::size_t c = b.count();
|
||||
std::size_t c_real = 0;
|
||||
for (std::size_t I = 0; I < b.size(); ++I)
|
||||
if (b[I])
|
||||
++c_real;
|
||||
BOOST_CHECK(c == c_real);
|
||||
}
|
||||
|
||||
static void size(const Bitset& b)
|
||||
{
|
||||
BOOST_CHECK(Bitset(b).set().count() == b.size());
|
||||
}
|
||||
|
||||
static void any(const Bitset& b)
|
||||
{
|
||||
BOOST_CHECK(b.any() == (b.count() > 0));
|
||||
}
|
||||
|
||||
static void none(const Bitset& b)
|
||||
{
|
||||
BOOST_CHECK(b.none() == (b.count() == 0));
|
||||
}
|
||||
|
||||
static void subset(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (a.is_subset_of(b)) {
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I])
|
||||
BOOST_CHECK(b[I]);
|
||||
} else {
|
||||
bool is_subset = true;
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I] && !b[I]) {
|
||||
is_subset = false;
|
||||
break;
|
||||
}
|
||||
BOOST_CHECK(is_subset == false);
|
||||
}
|
||||
}
|
||||
|
||||
static void proper_subset(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (a.is_proper_subset_of(b)) {
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I])
|
||||
BOOST_CHECK(b[I]);
|
||||
BOOST_CHECK(a.count() < b.count());
|
||||
} else {
|
||||
bool is_subset = true;
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I] && !b[I]) {
|
||||
is_subset = false;
|
||||
break;
|
||||
}
|
||||
BOOST_CHECK(is_subset == false || a.count() >= b.count());
|
||||
}
|
||||
}
|
||||
|
||||
static void operator_equal(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (a == b) {
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
BOOST_CHECK(a[I] == b[I]);
|
||||
} else {
|
||||
if (a.size() == b.size()) {
|
||||
bool diff = false;
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I] != b[I]) {
|
||||
diff = true;
|
||||
break;
|
||||
}
|
||||
BOOST_CHECK(diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void operator_not_equal(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (a != b) {
|
||||
if (a.size() == b.size()) {
|
||||
bool diff = false;
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I] != b[I]) {
|
||||
diff = true;
|
||||
break;
|
||||
}
|
||||
BOOST_CHECK(diff);
|
||||
}
|
||||
} else {
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
BOOST_CHECK(a[I] == b[I]);
|
||||
}
|
||||
}
|
||||
|
||||
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])
|
||||
return false;
|
||||
// if (a[I] = b[I]) skip to next
|
||||
|
||||
if (a[0] < b[0])
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
static void operator_less_than(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (less_than(a, b))
|
||||
BOOST_CHECK(a < b);
|
||||
else
|
||||
BOOST_CHECK(!(a < b));
|
||||
}
|
||||
|
||||
static void operator_greater_than(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (less_than(a, b) || a == b)
|
||||
BOOST_CHECK(!(a > b));
|
||||
else
|
||||
BOOST_CHECK(a > b);
|
||||
}
|
||||
|
||||
static void operator_less_than_eq(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (less_than(a, b) || a == b)
|
||||
BOOST_CHECK(a <= b);
|
||||
else
|
||||
BOOST_CHECK(!(a <= b));
|
||||
}
|
||||
|
||||
static void operator_greater_than_eq(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (less_than(a, b))
|
||||
BOOST_CHECK(!(a >= b));
|
||||
else
|
||||
BOOST_CHECK(a >= b);
|
||||
}
|
||||
|
||||
static void test_bit(const Bitset& b, std::size_t pos)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
std::size_t N = lhs.size();
|
||||
if (pos < N) {
|
||||
BOOST_CHECK(lhs.test(pos) == lhs[pos]);
|
||||
} else {
|
||||
// Not in range, doesn't satisfy precondition.
|
||||
}
|
||||
}
|
||||
|
||||
static void operator_shift_left(const Bitset& lhs, std::size_t pos)
|
||||
{
|
||||
Bitset x(lhs);
|
||||
BOOST_CHECK((lhs << pos) == (x <<= pos));
|
||||
}
|
||||
|
||||
static void operator_shift_right(const Bitset& lhs, std::size_t pos)
|
||||
{
|
||||
Bitset x(lhs);
|
||||
BOOST_CHECK((lhs >> pos) == (x >>= pos));
|
||||
}
|
||||
|
||||
// operator|
|
||||
static
|
||||
void operator_or(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
Bitset x(lhs);
|
||||
BOOST_CHECK((lhs | rhs) == (x |= rhs));
|
||||
}
|
||||
|
||||
// operator&
|
||||
static
|
||||
void operator_and(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
Bitset x(lhs);
|
||||
BOOST_CHECK((lhs & rhs) == (x &= rhs));
|
||||
}
|
||||
|
||||
// operator^
|
||||
static
|
||||
void operator_xor(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
Bitset x(lhs);
|
||||
BOOST_CHECK((lhs ^ rhs) == (x ^= rhs));
|
||||
}
|
||||
|
||||
// operator-
|
||||
static
|
||||
void operator_sub(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
Bitset x(lhs);
|
||||
BOOST_CHECK((lhs - rhs) == (x -= rhs));
|
||||
}
|
||||
|
||||
// operator<<(ostream,
|
||||
// operator>>(istream,
|
||||
|
||||
static
|
||||
void stream_read_write(const Bitset& out, const Bitset& in)
|
||||
{
|
||||
Bitset x(in);
|
||||
{
|
||||
std::ofstream f("tmp");
|
||||
f << out;
|
||||
}
|
||||
{
|
||||
std::ifstream f("tmp");
|
||||
f >> x;
|
||||
BOOST_CHECK(out == x);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
27
build.jam
27
build.jam
@@ -1,27 +0,0 @@
|
||||
# Copyright René Ferdinand Rivera Morell 2023-2024
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
require-b2 5.2 ;
|
||||
|
||||
constant boost_dependencies :
|
||||
/boost/assert//boost_assert
|
||||
/boost/config//boost_config
|
||||
/boost/container_hash//boost_container_hash
|
||||
/boost/core//boost_core
|
||||
/boost/throw_exception//boost_throw_exception ;
|
||||
|
||||
project /boost/dynamic_bitset
|
||||
: common-requirements
|
||||
<include>include
|
||||
;
|
||||
|
||||
explicit
|
||||
[ alias boost_dynamic_bitset : : : : <library>$(boost_dependencies) ]
|
||||
[ alias all : boost_dynamic_bitset example test ]
|
||||
;
|
||||
|
||||
call-if : boost-library dynamic_bitset
|
||||
;
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
import generate ;
|
||||
import path ;
|
||||
import property-set ;
|
||||
import virtual-target ;
|
||||
|
||||
path-constant HERE : . ;
|
||||
|
||||
make html/index.html : build_antora.sh : @run-script ;
|
||||
generate files-to-install : html/index.html : <generating-rule>@delayed-glob ;
|
||||
install install
|
||||
: files-to-install
|
||||
: <location>html
|
||||
<install-source-root>html/dynamic_bitset
|
||||
;
|
||||
explicit html/index.html files-to-install ;
|
||||
|
||||
# this runs the antora script
|
||||
actions run-script
|
||||
{
|
||||
bash $(>)
|
||||
}
|
||||
|
||||
# this globs after its sources are created
|
||||
rule delayed-glob ( project name : property-set : sources * )
|
||||
{
|
||||
for local src in $(sources)
|
||||
{
|
||||
# the next line causes the source to be generated immediately
|
||||
# and not later (which it normally would)
|
||||
UPDATE_NOW [ $(src).actualize ] ;
|
||||
}
|
||||
|
||||
# we need to construct the path to the globbed directory;
|
||||
# this path would be <current-project>/antora
|
||||
local root = [ path.root html [ $(project).location ] ] ;
|
||||
local files ;
|
||||
|
||||
# actual globbing happens here
|
||||
for local file in [ path.glob-tree $(root) : * ]
|
||||
{
|
||||
# we have to skip directories, because our match expression accepts anything
|
||||
if [ CHECK_IF_FILE $(file) ]
|
||||
{
|
||||
# we construct a list of targets to copy
|
||||
files += [ virtual-target.from-file $(file:D=) : $(file:D) : $(project) ] ;
|
||||
}
|
||||
}
|
||||
|
||||
# we prepend empty usage requirements to the result
|
||||
return [ property-set.empty ] $(files) ;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
alias boostdoc ;
|
||||
explicit boostdoc ;
|
||||
alias boostrelease : install ;
|
||||
explicit boostrelease ;
|
||||
@@ -1,21 +0,0 @@
|
||||
# ============================================================================
|
||||
# Copyright 2025 Gennaro Prota.
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
# ============================================================================
|
||||
|
||||
name: dynamic_bitset
|
||||
version: ~
|
||||
title: Boost.DynamicBitset
|
||||
start_page: index.adoc
|
||||
asciidoc:
|
||||
attributes:
|
||||
source-language: asciidoc@
|
||||
table-caption: false
|
||||
nav:
|
||||
- modules/ROOT/nav.adoc
|
||||
ext:
|
||||
cpp-reference:
|
||||
config: doc/mrdocs.yml
|
||||
@@ -1,31 +0,0 @@
|
||||
#! /bin/sh --
|
||||
# ============================================================================
|
||||
# Copyright 2023 Alan de Freitas.
|
||||
# Copyright 2025 Gennaro Prota.
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
# ============================================================================
|
||||
|
||||
set -eu
|
||||
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
echo "No playbook supplied, using default playbook."
|
||||
PLAYBOOK="local-playbook.yml"
|
||||
else
|
||||
PLAYBOOK=$1
|
||||
fi
|
||||
|
||||
SCRIPT_DIR=$( dirname -- "${BASH_SOURCE[0]}" )
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
echo "Installing npm dependencies..."
|
||||
npm ci
|
||||
|
||||
echo "Building docs in custom dir..."
|
||||
PATH="$(pwd)/node_modules/.bin:${PATH}"
|
||||
export PATH
|
||||
npx antora --clean --fetch "$PLAYBOOK" --stacktrace --log-level all
|
||||
echo "Done"
|
||||
@@ -1,57 +0,0 @@
|
||||
# ============================================================================
|
||||
# Copyright 2023 Alan de Freitas.
|
||||
# Copyright 2025 Gennaro Prota.
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
# ============================================================================
|
||||
#
|
||||
# An antora playbook used for local development.
|
||||
# The playbook includes Boost.DynamicBitset as its only component.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
site:
|
||||
title: Boost.DynamicBitset
|
||||
start_page: dynamic_bitset::index.adoc
|
||||
robots: allow
|
||||
keys:
|
||||
repo_url: 'https://github.com/boostorg/dynamic_bitset'
|
||||
|
||||
content:
|
||||
sources:
|
||||
- url: ..
|
||||
start_path: doc
|
||||
edit_url: 'https://github.com/boostorg/dynamic_bitset/edit/{refname}/{path}'
|
||||
|
||||
output:
|
||||
dir: html
|
||||
|
||||
ui:
|
||||
bundle:
|
||||
url: https://github.com/boostorg/website-v2-docs/releases/download/ui-master/ui-bundle.zip
|
||||
snapshot: true
|
||||
|
||||
antora:
|
||||
extensions:
|
||||
- require: '@antora/lunr-extension' # https://gitlab.com/antora/antora-lunr-extension
|
||||
index_latest_only: true
|
||||
- require: '@cppalliance/antora-cpp-tagfiles-extension'
|
||||
cpp-tagfiles:
|
||||
using-namespaces:
|
||||
- 'boost::'
|
||||
- require: '@cppalliance/antora-cpp-reference-extension'
|
||||
dependencies:
|
||||
- name: 'boost'
|
||||
repo: 'https://github.com/boostorg/boost.git'
|
||||
tag: 'develop'
|
||||
variable: 'BOOST_SRC_DIR'
|
||||
system-env: 'BOOST_SRC_DIR'
|
||||
|
||||
asciidoc:
|
||||
attributes:
|
||||
# Enable pagination
|
||||
page-pagination: ''
|
||||
extensions:
|
||||
- '@cppalliance/asciidoctor-boost-links'
|
||||
- '@asciidoctor/tabs'
|
||||
@@ -1,10 +0,0 @@
|
||||
// ===========================================================================
|
||||
// Copyright 2025 Gennaro Prota.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
// ===========================================================================
|
||||
|
||||
* xref:index.adoc[]
|
||||
* xref:reference:boost/dynamic_bitset.adoc[Reference]
|
||||
@@ -1,72 +0,0 @@
|
||||
// ===========================================================================
|
||||
// Copyright 2001 Jeremy Siek
|
||||
// Copyright 2003-2004, 2008, 2025 Gennaro Prota
|
||||
// Copyright 2014 Ahmed Charles
|
||||
// Copyright 2014 Riccardo Marcangelo
|
||||
// Copyright 2018 Evgeny Shulgin
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
// ===========================================================================
|
||||
|
||||
= Boost.DynamicBitset
|
||||
|
||||
Boost.DynamicBitset is a portable library that provides a set of bits.
|
||||
|
||||
The set
|
||||
(xref:reference:boost/dynamic_bitset.adoc#boost-dynamic_bitset[dynamic_bitset])
|
||||
provides access to the value of individual bits via
|
||||
xref:reference:boost/dynamic_bitset/operator_subs-08.adoc[operator[\]] and
|
||||
provides all of the bitwise operators that one can apply to builtin integers,
|
||||
such as xref:reference:boost/operator_bitand.adoc[operator&] and
|
||||
xref:reference:boost/dynamic_bitset/operator_lshift.adoc[operator<<]. The number
|
||||
of bits can change at runtime.
|
||||
|
||||
`dynamic_bitset` is nearly identical to `std::bitset`. The difference is that
|
||||
the size of a `dynamic_bitset` (the number of bits) can change at runtime,
|
||||
whereas the size of a `std::bitset` is specified at compile-time through an
|
||||
integer template parameter.
|
||||
|
||||
The main problem that `dynamic_bitset` is designed to solve is that of
|
||||
representing a subset of a finite set. Each bit represents whether an element of
|
||||
the finite set is in the subset or not. As such the bitwise operations of
|
||||
`dynamic_bitset`, such as `operator&` and `operator|`, correspond to set
|
||||
operations, such as intersection and union.
|
||||
|
||||
== Definitions
|
||||
Each bit represents either the Boolean value `true` or `false` (1 or 0). To set
|
||||
a bit is to assign it 1. To clear or reset a bit is to assign it 0. To flip a
|
||||
bit is to change the value to 1 if it was 0 and to 0 if it was 1. Each bit has a
|
||||
non-negative position. A bitset `x` contains `x.size()` bits, with each bit
|
||||
assigned a unique position in the range `[0, x.size())`. The bit at position 0
|
||||
is called the least significant bit and the bit at position `size() - 1` is the
|
||||
most significant bit. When converting an instance of `dynamic_bitset` to or from
|
||||
an unsigned long `n`, the bit at position `i` of the bitset has the same value
|
||||
as `(n >> i) & 1`.
|
||||
|
||||
== Rationale
|
||||
Because of the proxy reference type, `dynamic_bitset` is not a
|
||||
https://en.cppreference.com/w/cpp/named_req/Container.html[Container] and its
|
||||
iterators do not satisfy the requirements for a LegacyForwardIterator. This
|
||||
means that its iterators are not usable with many standard algorithms. However,
|
||||
`dynamic_bitset` provides C++20 iterators which can be used with ranges.
|
||||
|
||||
Some people prefer the name "toggle" to "flip". The name "flip" was chosen
|
||||
because that is the name used in `std::bitset`. In fact, most of the function
|
||||
names for `dynamic_bitset` were chosen for this reason.
|
||||
|
||||
`dynamic_bitset` does not throw exceptions when a precondition is violated (as
|
||||
is done in `std::bitset`). Instead `BOOST_ASSERT()` is used. See the guidelines
|
||||
for Error and Exception Handling for the explanation. Note that, consistently
|
||||
with this, the documentation of the member functions doesn't use the term
|
||||
"precondition" for conditions that cause an exception to be emitted (the C++
|
||||
standard uses the term "requires" in such cases).
|
||||
|
||||
== Acknowledgments
|
||||
|
||||
We would like to thank the Boost community for putting in the time to review and
|
||||
accept this library. This library is much better than it ever would have been
|
||||
due to all the suggestions from Boost members. We especially thank Matt Marcus
|
||||
for taking on the task of review manager. Also, a special thanks goes to James
|
||||
Kanze for his invaluable help with the internationalization issues.
|
||||
@@ -1,26 +0,0 @@
|
||||
# ============================================================================
|
||||
# Copyright 2025 Gennaro Prota.
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
# ============================================================================
|
||||
|
||||
verbose: true
|
||||
source-root: ..
|
||||
cmake: '-DDYNAMIC_BITSET_MRDOCS_BUILD=ON'
|
||||
input:
|
||||
- ../include
|
||||
exclude-symbols:
|
||||
- 'boost::bit_iterator_base'
|
||||
- 'boost::bit_iterator'
|
||||
- 'boost::const_bit_iterator'
|
||||
- 'boost::detail'
|
||||
- 'boost::detail::**'
|
||||
- 'boost::to_string_helper'
|
||||
- 'boost::dynamic_bitset::bit_appender'
|
||||
- 'boost::dynamic_bitset::buffer_type'
|
||||
file-patterns:
|
||||
- '*.hpp'
|
||||
multipage: true
|
||||
generator: adoc
|
||||
2460
doc/package-lock.json
generated
2460
doc/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"@antora/cli": "3.1.10",
|
||||
"@antora/site-generator": "3.1.10",
|
||||
"antora": "3.1.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"@antora/expand-path-helper": "^2.0.0",
|
||||
"@antora/lunr-extension": "^1.0.0-alpha.8",
|
||||
"@asciidoctor/tabs": "^1.0.0-beta.3",
|
||||
"@cppalliance/antora-cpp-reference-extension": "^0.0.8",
|
||||
"@cppalliance/antora-cpp-tagfiles-extension": "^0.0.5",
|
||||
"@cppalliance/asciidoctor-boost-links": "^0.0.2"
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
To build the documentation, run build_docs.sh.
|
||||
258
dyn_bitset_unit_tests1.cpp
Normal file
258
dyn_bitset_unit_tests1.cpp
Normal file
@@ -0,0 +1,258 @@
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// 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.
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cmath> // for pow
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
|
||||
|
||||
template <typename Block>
|
||||
void test_from_ulong(std::size_t n, unsigned long number)
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(n, number);
|
||||
bitset_test< boost::dynamic_bitset<Block> >::from_unsigned_long(b, number);
|
||||
}
|
||||
|
||||
|
||||
template <typename Block>
|
||||
void run_test_cases()
|
||||
{
|
||||
typedef bitset_test< boost::dynamic_bitset<Block> > Tests;
|
||||
|
||||
std::string long_string(101, '0');
|
||||
for (std::size_t j = 0; j < long_string.size(); ++j)
|
||||
long_string[j] = '0' + (j % 2);
|
||||
|
||||
std::size_t N, ul_size = CHAR_BIT * sizeof(unsigned long),
|
||||
block_size = CHAR_BIT * sizeof(Block);
|
||||
unsigned long numbers[] = { 0, 40247,
|
||||
std::numeric_limits<unsigned long>::max() };
|
||||
|
||||
//=====================================================================
|
||||
// Test construction from unsigned long
|
||||
for (std::size_t i = 0; i < 3; ++i) {
|
||||
unsigned long number = numbers[i];
|
||||
N = 0;
|
||||
test_from_ulong<Block>(N, number);
|
||||
|
||||
N = std::size_t(0.7 * double(ul_size));
|
||||
test_from_ulong<Block>(N, number);
|
||||
|
||||
N = 1 * ul_size;
|
||||
test_from_ulong<Block>(N, number);
|
||||
|
||||
N = std::size_t(1.3 * double(ul_size));
|
||||
test_from_ulong<Block>(N, number);
|
||||
|
||||
N = std::size_t(0.7 * double(block_size));
|
||||
test_from_ulong<Block>(N, number);
|
||||
|
||||
N = block_size;
|
||||
test_from_ulong<Block>(N, number);
|
||||
|
||||
N = std::size_t(1.3 * double(block_size));
|
||||
test_from_ulong<Block>(N, number);
|
||||
|
||||
N = 3 * block_size;
|
||||
test_from_ulong<Block>(N, number);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test construction from a string
|
||||
{
|
||||
// case pos > str.size()
|
||||
Tests::from_string(std::string(""), 1, 1);
|
||||
|
||||
// invalid arguments
|
||||
Tests::from_string(std::string("x11"), 0, 3);
|
||||
Tests::from_string(std::string("0y1"), 0, 3);
|
||||
Tests::from_string(std::string("10z"), 0, 3);
|
||||
|
||||
// valid arguments
|
||||
Tests::from_string(std::string(""), 0, 0);
|
||||
Tests::from_string(std::string("0"), 0, 1);
|
||||
Tests::from_string(std::string("1"), 0, 1);
|
||||
Tests::from_string(long_string, 0, long_string.size());
|
||||
}
|
||||
//=====================================================================
|
||||
// Test construction from a block range
|
||||
{
|
||||
std::vector<Block> blocks;
|
||||
Tests::from_block_range(blocks);
|
||||
}
|
||||
{
|
||||
std::vector<Block> blocks(3);
|
||||
blocks[0] = static_cast<Block>(0);
|
||||
blocks[1] = static_cast<Block>(1);
|
||||
blocks[2] = ~Block(0);
|
||||
Tests::from_block_range(blocks);
|
||||
}
|
||||
{
|
||||
std::vector<Block> blocks(101);
|
||||
for (typename std::vector<Block>::size_type i = 0;
|
||||
i < blocks.size(); ++i)
|
||||
blocks[i] = i;
|
||||
Tests::from_block_range(blocks);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test copy constructor
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::copy_constructor(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::copy_constructor(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::copy_constructor(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test assignment operator
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
Tests::assignment_operator(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("0"));
|
||||
Tests::assignment_operator(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::assignment_operator(a, b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test resize
|
||||
{
|
||||
boost::dynamic_bitset<Block> a;
|
||||
Tests::resize(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0"));
|
||||
Tests::resize(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1"));
|
||||
Tests::resize(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string);
|
||||
Tests::resize(a);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test clear
|
||||
{
|
||||
boost::dynamic_bitset<Block> a;
|
||||
Tests::clear(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string);
|
||||
Tests::clear(a);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test append bit
|
||||
{
|
||||
boost::dynamic_bitset<Block> a;
|
||||
Tests::append_bit(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0"));
|
||||
Tests::append_bit(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1"));
|
||||
Tests::append_bit(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string);
|
||||
Tests::append_bit(a);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test append block
|
||||
{
|
||||
boost::dynamic_bitset<Block> a;
|
||||
Tests::append_block(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0"));
|
||||
Tests::append_block(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1"));
|
||||
Tests::append_block(a);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string);
|
||||
Tests::append_block(a);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test append block range
|
||||
{
|
||||
boost::dynamic_bitset<Block> a;
|
||||
std::vector<Block> blocks;
|
||||
Tests::append_block_range(a, blocks);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0"));
|
||||
std::vector<Block> blocks(3);
|
||||
blocks[0] = static_cast<Block>(0);
|
||||
blocks[1] = static_cast<Block>(1);
|
||||
blocks[2] = ~Block(0);
|
||||
Tests::append_block_range(a, blocks);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1"));
|
||||
std::vector<Block> blocks(101);
|
||||
for (typename std::vector<Block>::size_type i = 0;
|
||||
i < blocks.size(); ++i)
|
||||
blocks[i] = i;
|
||||
Tests::append_block_range(a, blocks);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string);
|
||||
std::vector<Block> blocks(3);
|
||||
blocks[0] = static_cast<Block>(0);
|
||||
blocks[1] = static_cast<Block>(1);
|
||||
blocks[2] = ~Block(0);
|
||||
Tests::append_block_range(a, blocks);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test bracket operator
|
||||
{
|
||||
boost::dynamic_bitset<Block> b1;
|
||||
std::vector<bool> bitvec1;
|
||||
Tests::operator_bracket(b1, bitvec1);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("1"));
|
||||
std::vector<bool> bit_vec(1, true);
|
||||
Tests::operator_bracket(b, bit_vec);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
std::size_t n = long_string.size();
|
||||
std::vector<bool> bit_vec(n);
|
||||
for (std::size_t i = 0; i < n; ++i)
|
||||
bit_vec[i] = long_string[n - 1 - i] == '0' ? 0 : 1;
|
||||
Tests::operator_bracket(b, bit_vec);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
test_main(int, char*[])
|
||||
{
|
||||
run_test_cases<unsigned char>();
|
||||
run_test_cases<unsigned short>();
|
||||
run_test_cases<unsigned long>();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
240
dyn_bitset_unit_tests2.cpp
Normal file
240
dyn_bitset_unit_tests2.cpp
Normal file
@@ -0,0 +1,240 @@
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// 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.
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cmath> // for pow
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
|
||||
template <typename Block>
|
||||
void run_test_cases()
|
||||
{
|
||||
typedef bitset_test< boost::dynamic_bitset<Block> > Tests;
|
||||
|
||||
std::string long_string(101, '0');
|
||||
for (std::size_t i = 0; i < long_string.size(); ++i)
|
||||
long_string[i] = '0' + (i % 2);
|
||||
|
||||
//=====================================================================
|
||||
// Test operator&=
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs, rhs;
|
||||
Tests::and_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
|
||||
Tests::and_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
|
||||
Tests::and_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
|
||||
Tests::and_assignment(lhs, rhs);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator |=
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs, rhs;
|
||||
Tests::or_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
|
||||
Tests::or_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
|
||||
Tests::or_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
|
||||
Tests::or_assignment(lhs, rhs);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator^=
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs, rhs;
|
||||
Tests::xor_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
|
||||
Tests::xor_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(std::string("0")), rhs(std::string("1"));
|
||||
Tests::xor_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string), rhs(long_string);
|
||||
Tests::xor_assignment(lhs, rhs);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator-=
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs, rhs;
|
||||
Tests::sub_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
|
||||
Tests::sub_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(std::string("0")), rhs(std::string("1"));
|
||||
Tests::sub_assignment(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string), rhs(long_string);
|
||||
Tests::sub_assignment(lhs, rhs);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator<<=
|
||||
{ // case pos == 0
|
||||
std::size_t pos = 0;
|
||||
boost::dynamic_bitset<Block> b(std::string("1010"));
|
||||
Tests::shift_left_assignment(b, pos);
|
||||
}
|
||||
{ // case pos == size()/2
|
||||
std::size_t pos = long_string.size() / 2;
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::shift_left_assignment(b, pos);
|
||||
}
|
||||
{ // case pos >= n
|
||||
std::size_t pos = long_string.size();
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::shift_left_assignment(b, pos);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator>>=
|
||||
{ // case pos == 0
|
||||
std::size_t pos = 0;
|
||||
boost::dynamic_bitset<Block> b(std::string("1010"));
|
||||
Tests::shift_right_assignment(b, pos);
|
||||
}
|
||||
{ // case pos == size()/2
|
||||
std::size_t pos = long_string.size() / 2;
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::shift_right_assignment(b, pos);
|
||||
}
|
||||
{ // case pos >= n
|
||||
std::size_t pos = long_string.size();
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::shift_right_assignment(b, pos);
|
||||
}
|
||||
//=====================================================================
|
||||
// test b.set()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::set_all(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::set_all(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::set_all(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.set(pos)
|
||||
{ // case pos >= b.size()
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::set_one(b, 0, true);
|
||||
}
|
||||
{ // case pos < b.size()
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::set_one(b, 0, true);
|
||||
}
|
||||
{ // case pos == b.size() / 2
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::set_one(b, long_string.size()/2, true);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.reset()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::reset_all(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::reset_all(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::reset_all(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.reset(pos)
|
||||
{ // case pos >= b.size()
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::reset_one(b, 0);
|
||||
}
|
||||
{ // case pos < b.size()
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::reset_one(b, 0);
|
||||
}
|
||||
{ // case pos == b.size() / 2
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::reset_one(b, long_string.size()/2);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test ~b
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::operator_flip(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("1"));
|
||||
Tests::operator_flip(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::operator_flip(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.flip()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::flip_all(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("1"));
|
||||
Tests::flip_all(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::flip_all(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.flip(pos)
|
||||
{ // case pos >= b.size()
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::flip_one(b, 0);
|
||||
}
|
||||
{ // case pos < b.size()
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::flip_one(b, 0);
|
||||
}
|
||||
{ // case pos == b.size() / 2
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::flip_one(b, long_string.size()/2);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
test_main(int argc, char*[])
|
||||
{
|
||||
run_test_cases<unsigned char>();
|
||||
run_test_cases<unsigned short>();
|
||||
run_test_cases<unsigned long>();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
535
dyn_bitset_unit_tests3.cpp
Normal file
535
dyn_bitset_unit_tests3.cpp
Normal file
@@ -0,0 +1,535 @@
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// 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.
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cmath> // for pow
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
|
||||
template <typename Block>
|
||||
void run_test_cases()
|
||||
{
|
||||
typedef bitset_test< boost::dynamic_bitset<Block> > Tests;
|
||||
|
||||
std::string long_string(101, '0');
|
||||
for (std::size_t i = 0; i < long_string.size(); ++i)
|
||||
long_string[i] = '0' + (i % 2);
|
||||
|
||||
std::size_t ul_size = CHAR_BIT * sizeof(unsigned long);
|
||||
|
||||
//=====================================================================
|
||||
// Test b.to_long()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::to_ulong(b);
|
||||
}
|
||||
{
|
||||
std::string ul_str(ul_size, '1');
|
||||
boost::dynamic_bitset<Block> b(ul_str);
|
||||
Tests::to_ulong(b);
|
||||
}
|
||||
{ // case overflow
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::to_ulong(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test to_string(b, str)
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::to_string(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::to_string(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::to_string(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.count()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::count(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::count(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::count(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.size()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::size(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::size(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::size(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.any()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::any(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::any(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::any(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.none()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::none(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::none(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::none(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a.is_subset_of(b)
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
a[long_string.size()/2].flip();
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
b[long_string.size()/2].flip();
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a.is_proper_subset_of(b)
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
a[long_string.size()/2].flip();
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
b[long_string.size()/2].flip();
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator==
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
Tests::operator_equal(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
|
||||
Tests::operator_equal(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
|
||||
Tests::operator_equal(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::operator_equal(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
a[long_string.size()/2].flip();
|
||||
Tests::operator_equal(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
b[long_string.size()/2].flip();
|
||||
Tests::operator_equal(a, b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator!=
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
Tests::operator_not_equal(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
|
||||
Tests::operator_not_equal(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
|
||||
Tests::operator_not_equal(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::operator_not_equal(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
a[long_string.size()/2].flip();
|
||||
Tests::operator_not_equal(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
b[long_string.size()/2].flip();
|
||||
Tests::operator_not_equal(a, b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator<
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
a[long_string.size()/2].flip();
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
b[long_string.size()/2].flip();
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
// check for consistency with ulong behaviour
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
|
||||
assert(a < b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
|
||||
assert(!(a < b));
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
|
||||
assert(!(a < b));
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator<=
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
Tests::operator_less_than_eq(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
|
||||
Tests::operator_less_than_eq(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
|
||||
Tests::operator_less_than_eq(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::operator_less_than_eq(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
a[long_string.size()/2].flip();
|
||||
Tests::operator_less_than_eq(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
b[long_string.size()/2].flip();
|
||||
Tests::operator_less_than_eq(a, b);
|
||||
}
|
||||
// check for consistency with ulong behaviour
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
|
||||
assert(a <= b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
|
||||
assert(a <= b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
|
||||
assert(!(a <= b));
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator>
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
Tests::operator_greater_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
|
||||
Tests::operator_greater_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
|
||||
Tests::operator_greater_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::operator_greater_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
a[long_string.size()/2].flip();
|
||||
Tests::operator_greater_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
b[long_string.size()/2].flip();
|
||||
Tests::operator_greater_than(a, b);
|
||||
}
|
||||
// check for consistency with ulong behaviour
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
|
||||
assert(!(a > b));
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
|
||||
assert(!(a > b));
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
|
||||
assert(a > b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator<=
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
Tests::operator_greater_than_eq(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
|
||||
Tests::operator_greater_than_eq(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
|
||||
Tests::operator_greater_than_eq(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::operator_greater_than_eq(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
a[long_string.size()/2].flip();
|
||||
Tests::operator_greater_than_eq(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
b[long_string.size()/2].flip();
|
||||
Tests::operator_greater_than_eq(a, b);
|
||||
}
|
||||
// check for consistency with ulong behaviour
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
|
||||
assert(!(a >= b));
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
|
||||
assert(a >= b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
|
||||
assert(a >= b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.test(pos)
|
||||
{ // case pos >= b.size()
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::test_bit(b, 0);
|
||||
}
|
||||
{ // case pos < b.size()
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::test_bit(b, 0);
|
||||
}
|
||||
{ // case pos == b.size() / 2
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::test_bit(b, long_string.size()/2);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b << pos
|
||||
{ // case pos == 0
|
||||
std::size_t pos = 0;
|
||||
boost::dynamic_bitset<Block> b(std::string("1010"));
|
||||
Tests::operator_shift_left(b, pos);
|
||||
}
|
||||
{ // case pos == size()/2
|
||||
std::size_t pos = long_string.size() / 2;
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::operator_shift_left(b, pos);
|
||||
}
|
||||
{ // case pos >= n
|
||||
std::size_t pos = long_string.size();
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::operator_shift_left(b, pos);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b >> pos
|
||||
{ // case pos == 0
|
||||
std::size_t pos = 0;
|
||||
boost::dynamic_bitset<Block> b(std::string("1010"));
|
||||
Tests::operator_shift_right(b, pos);
|
||||
}
|
||||
{ // case pos == size()/2
|
||||
std::size_t pos = long_string.size() / 2;
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::operator_shift_right(b, pos);
|
||||
}
|
||||
{ // case pos >= n
|
||||
std::size_t pos = long_string.size();
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::operator_shift_right(b, pos);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a & b
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs, rhs;
|
||||
Tests::operator_and(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
|
||||
Tests::operator_and(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
|
||||
Tests::operator_and(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
|
||||
Tests::operator_and(lhs, rhs);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a | b
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs, rhs;
|
||||
Tests::operator_or(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
|
||||
Tests::operator_or(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
|
||||
Tests::operator_or(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
|
||||
Tests::operator_or(lhs, rhs);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a^b
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs, rhs;
|
||||
Tests::operator_xor(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
|
||||
Tests::operator_xor(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
|
||||
Tests::operator_xor(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
|
||||
Tests::operator_xor(lhs, rhs);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a-b
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs, rhs;
|
||||
Tests::operator_sub(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
|
||||
Tests::operator_sub(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
|
||||
Tests::operator_sub(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
|
||||
Tests::operator_sub(lhs, rhs);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test stream operator<< and operator>>
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
boost::dynamic_bitset<Block> x(b.size());
|
||||
Tests::stream_read_write(b, x);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
boost::dynamic_bitset<Block> x(b.size());
|
||||
Tests::stream_read_write(b, x);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
boost::dynamic_bitset<Block> x(b.size());
|
||||
Tests::stream_read_write(b, x);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
test_main(int, char*[])
|
||||
{
|
||||
run_test_cases<unsigned char>();
|
||||
run_test_cases<unsigned short>();
|
||||
run_test_cases<unsigned long>();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
1395
dynamic_bitset.html
1395
dynamic_bitset.html
File diff suppressed because it is too large
Load Diff
@@ -1,23 +0,0 @@
|
||||
# -----------------------------------------------------------
|
||||
# Copyright (c) 2002 Gennaro Prota
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
#
|
||||
# -----------------------------------------------------------
|
||||
|
||||
project : requirements <library>/boost/dynamic_bitset//boost_dynamic_bitset ;
|
||||
|
||||
exe example1
|
||||
: example1.cpp
|
||||
;
|
||||
|
||||
exe example2
|
||||
: example2.cpp
|
||||
;
|
||||
|
||||
exe example3
|
||||
: example3.cpp
|
||||
;
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// An example of setting and reading some bits. Note that operator[]
|
||||
// goes from the least-significant bit at 0 to the most significant
|
||||
// bit at size()-1. The operator<< for dynamic_bitset prints the
|
||||
// bitset from most-significant to least-significant, since that is
|
||||
// the format most people are used to reading.
|
||||
//
|
||||
// The output is:
|
||||
//
|
||||
// 11001
|
||||
// 10011
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
boost::dynamic_bitset<> x( 5 ); // all 0's by default
|
||||
x[ 0 ] = 1;
|
||||
x[ 1 ] = 1;
|
||||
x[ 4 ] = 1;
|
||||
for ( boost::dynamic_bitset<>::size_type i = 0; i < x.size(); ++i )
|
||||
std::cout << x[ i ];
|
||||
std::cout << "\n";
|
||||
std::cout << x << "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Sample output:
|
||||
//
|
||||
// bits(0) = 00
|
||||
// bits(1) = 01
|
||||
// bits(2) = 10
|
||||
// bits(3) = 11
|
||||
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
const boost::dynamic_bitset<> b0( 2, 0ul );
|
||||
std::cout << "bits(0) = " << b0 << std::endl;
|
||||
|
||||
const boost::dynamic_bitset<> b1( 2, 1ul );
|
||||
std::cout << "bits(1) = " << b1 << std::endl;
|
||||
|
||||
const boost::dynamic_bitset<> b2( 2, 2ul );
|
||||
std::cout << "bits(2) = " << b2 << std::endl;
|
||||
|
||||
const boost::dynamic_bitset<> b3( 2, 3ul );
|
||||
std::cout << "bits(3) = " << b3 << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2008 Gennaro Prota
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Sample run:
|
||||
//
|
||||
// mask = 101010101010
|
||||
// x.size() = 0
|
||||
// Enter a bitset in binary: x = 100100010
|
||||
//
|
||||
// Input number: 100100010
|
||||
// x.size() is now: 9
|
||||
// As unsigned long: 290
|
||||
// Mask (possibly resized): 010101010
|
||||
// And with mask: 000100010
|
||||
// Or with mask: 110101010
|
||||
// Shifted left by 1: 001000100
|
||||
// Shifted right by 1: 010010001
|
||||
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
boost::dynamic_bitset<> mask( 12, 2730ul );
|
||||
std::cout << "mask = " << mask << std::endl;
|
||||
|
||||
boost::dynamic_bitset<> x;
|
||||
std::cout << "x.size() = " << x.size() << std::endl;
|
||||
|
||||
std::cout << "Enter a bitset in binary: x = " << std::flush;
|
||||
if ( std::cin >> x ) {
|
||||
const std::size_t sz = x.size();
|
||||
std::cout << std::endl;
|
||||
std::cout << "Input number: " << x << std::endl;
|
||||
std::cout << "x.size() is now: " << sz << std::endl;
|
||||
|
||||
bool fits_in_ulong = true;
|
||||
unsigned long ul = 0;
|
||||
try {
|
||||
ul = x.to_ulong();
|
||||
} catch ( std::overflow_error & ) {
|
||||
fits_in_ulong = false;
|
||||
}
|
||||
|
||||
std::cout << "As unsigned long: ";
|
||||
if ( fits_in_ulong ) {
|
||||
std::cout << ul;
|
||||
} else {
|
||||
std::cout << "(overflow exception)";
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
mask.resize( sz );
|
||||
|
||||
std::cout << "Mask (possibly resized): " << mask << std::endl;
|
||||
|
||||
std::cout << "And with mask: " << ( x & mask ) << std::endl;
|
||||
std::cout << "Or with mask: " << ( x | mask ) << std::endl;
|
||||
std::cout << "Shifted left by 1: " << ( x << 1 ) << std::endl;
|
||||
std::cout << "Shifted right by 1: " << ( x >> 1 ) << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
26
example1.cpp
Normal file
26
example1.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// (C) Copyright Jeremy Siek 2001. 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.
|
||||
|
||||
// Sample output:
|
||||
// 1
|
||||
// 1
|
||||
// 0
|
||||
// 0
|
||||
// 1
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
int main() {
|
||||
boost::dynamic_bitset<> x(5); // all 0's by default
|
||||
x[0] = 1;
|
||||
x[1] = 1;
|
||||
x[4] = 1;
|
||||
for (boost::dynamic_bitset<>::size_type i = 0; i < x.size(); ++i)
|
||||
std::cout << x[i];
|
||||
std::cout << "\n";
|
||||
std::cout << x << "\n";
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
30
example2.cpp
Normal file
30
example2.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// (C) Copyright Jeremy Siek 2001. 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.
|
||||
//
|
||||
// Sample output:
|
||||
// bits(0) = 00
|
||||
// bits(1) = 01
|
||||
// bits(2) = 10
|
||||
// bits(3) = 11
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
int main()
|
||||
{
|
||||
const boost::dynamic_bitset<> b0(2, 0ul);
|
||||
std::cout << "bits(0) = " << b0 << std::endl;
|
||||
|
||||
const boost::dynamic_bitset<> b1(2, 1ul);
|
||||
std::cout << "bits(1) = " << b1 << std::endl;
|
||||
|
||||
const boost::dynamic_bitset<> b2(2, 2ul);
|
||||
std::cout << "bits(2) = " << b2 << std::endl;
|
||||
|
||||
const boost::dynamic_bitset<> b3(2, 3ul);
|
||||
std::cout << "bits(3) = " << b3 << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
36
example3.cpp
Normal file
36
example3.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// (C) Copyright Jeremy Siek 2001. 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.
|
||||
//
|
||||
// Sample output:
|
||||
// mask = 101010101010
|
||||
// Enter a 12-bit bitset in binary: 100110101101
|
||||
// x = 100110101101
|
||||
// As ulong: 2477
|
||||
// And with mask: 100010101000
|
||||
// Or with mask: 101110101111
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
|
||||
int main(int, char*[]) {
|
||||
const boost::dynamic_bitset<> mask(12, 2730ul);
|
||||
std::cout << "mask = " << mask << std::endl;
|
||||
|
||||
boost::dynamic_bitset<> x(12);
|
||||
std::cout << "x.size()=" << x.size() << std::endl;
|
||||
|
||||
std::cout << "Enter a 12-bit bitset in binary: " << std::flush;
|
||||
if (std::cin >> x) {
|
||||
std::cout << "input number: " << x << std::endl;
|
||||
std::cout << "As unsigned long: " << x.to_ulong() << std::endl;
|
||||
std::cout << "And with mask: " << (x & mask) << std::endl;
|
||||
std::cout << "Or with mask: " << (x | mask) << std::endl;
|
||||
std::cout << "Shifted left: " << (x << 1) << std::endl;
|
||||
std::cout << "Shifted right: " << (x >> 1) << std::endl;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
176
include/boost/detail/dynamic_bitset.hpp
Normal file
176
include/boost/detail/dynamic_bitset.hpp
Normal file
@@ -0,0 +1,176 @@
|
||||
// (C) Copyright Chuck Allison and Jeremy Siek 2001, 2002.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// With optimizations by Gennaro Prota.
|
||||
|
||||
#ifndef BOOST_DETAIL_DYNAMIC_BITSET_HPP
|
||||
#define BOOST_DETAIL_DYNAMIC_BITSET_HPP
|
||||
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/detail/iterator.hpp"
|
||||
|
||||
#if !(defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) || defined(__BORLANDC__))
|
||||
#define BOOST_DYN_BITSET_USE_FRIENDS
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail {
|
||||
|
||||
// Forward references
|
||||
template <typename BlockInputIterator>
|
||||
std::size_t initial_num_blocks(BlockInputIterator first,
|
||||
BlockInputIterator last,
|
||||
std::input_iterator_tag);
|
||||
template <typename BlockForwardIterator>
|
||||
std::size_t initial_num_blocks(BlockForwardIterator first,
|
||||
BlockForwardIterator last,
|
||||
std::forward_iterator_tag);
|
||||
|
||||
// The following 2 classes make sure that the bitset
|
||||
// gets allocated in an exception safe manner
|
||||
template <typename Allocator>
|
||||
class dynamic_bitset_alloc_base {
|
||||
public:
|
||||
dynamic_bitset_alloc_base(const Allocator& alloc)
|
||||
: m_alloc(alloc) { }
|
||||
protected:
|
||||
Allocator m_alloc;
|
||||
};
|
||||
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
class dynamic_bitset_base :
|
||||
#ifdef BOOST_DYN_BITSET_USE_FRIENDS
|
||||
protected
|
||||
#else
|
||||
public
|
||||
#endif
|
||||
dynamic_bitset_alloc_base<Allocator>
|
||||
{
|
||||
typedef std::size_t size_type;
|
||||
#ifndef BOOST_DYN_BITSET_USE_FRIENDS
|
||||
public:
|
||||
#endif
|
||||
enum { bits_per_block = CHAR_BIT * sizeof(Block) };
|
||||
public:
|
||||
dynamic_bitset_base()
|
||||
: m_bits(0), m_num_bits(0), m_num_blocks(0) { }
|
||||
|
||||
dynamic_bitset_base(size_type num_bits, const Allocator& alloc)
|
||||
: dynamic_bitset_alloc_base<Allocator>(alloc),
|
||||
m_bits(dynamic_bitset_alloc_base<Allocator>::
|
||||
m_alloc.allocate(calc_num_blocks(num_bits), static_cast<void const *>(0))),
|
||||
m_num_bits(num_bits),
|
||||
m_num_blocks(calc_num_blocks(num_bits))
|
||||
{
|
||||
using namespace std;
|
||||
memset(m_bits, 0, m_num_blocks * sizeof(Block)); // G.P.S. ask to Jeremy
|
||||
}
|
||||
~dynamic_bitset_base() {
|
||||
if (m_bits)
|
||||
this->m_alloc.deallocate(m_bits, m_num_blocks);
|
||||
}
|
||||
#ifdef BOOST_DYN_BITSET_USE_FRIENDS
|
||||
protected:
|
||||
#endif
|
||||
Block* m_bits;
|
||||
size_type m_num_bits;
|
||||
size_type m_num_blocks;
|
||||
|
||||
static size_type word(size_type bit) { return bit / bits_per_block; } // [gps]
|
||||
static size_type offset(size_type bit){ return bit % bits_per_block; } // [gps]
|
||||
static Block mask1(size_type bit) { return Block(1) << offset(bit); }
|
||||
static Block mask0(size_type bit) { return ~(Block(1) << offset(bit)); }
|
||||
static size_type calc_num_blocks(size_type num_bits)
|
||||
{ return (num_bits + bits_per_block - 1) / bits_per_block; }
|
||||
};
|
||||
|
||||
|
||||
// ------- count table implementation --------------
|
||||
|
||||
typedef unsigned char byte_t;
|
||||
|
||||
// only count<true> has a definition
|
||||
#if 0
|
||||
// This was giving Intel C++ and Borland C++ trouble -JGS
|
||||
template <bool = true> struct count;
|
||||
template <> struct count <true> {
|
||||
#else
|
||||
template <bool bogus = true>
|
||||
struct count {
|
||||
#endif
|
||||
typedef byte_t element_type;
|
||||
static const byte_t table[];
|
||||
BOOST_STATIC_CONSTANT (unsigned int, max_bit = 8); // must be a power of two
|
||||
|
||||
};
|
||||
//typedef count<true> table_t;
|
||||
|
||||
|
||||
// the table: wrapped in a class template, so
|
||||
// that it is only instantiated if/when needed
|
||||
//
|
||||
#if 0
|
||||
// Intel C++ and Borland C++ trouble -JGS
|
||||
template <>
|
||||
const byte_t count <true>::table[] =
|
||||
#else
|
||||
template <bool bogus>
|
||||
const byte_t count<bogus>::table[] =
|
||||
#endif
|
||||
{
|
||||
// Automatically generated by GPTableGen.exe v.1.0
|
||||
//
|
||||
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
|
||||
};
|
||||
|
||||
|
||||
// -------------------------------------------------------
|
||||
|
||||
template <typename BlockInputIterator>
|
||||
std::size_t initial_num_blocks(BlockInputIterator first,
|
||||
BlockInputIterator last,
|
||||
std::input_iterator_tag)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename BlockForwardIterator>
|
||||
std::size_t initial_num_blocks(BlockForwardIterator first,
|
||||
BlockForwardIterator last,
|
||||
std::forward_iterator_tag)
|
||||
{
|
||||
std::size_t n = 0;
|
||||
while (first != last)
|
||||
++first, ++n;
|
||||
return n;
|
||||
}
|
||||
|
||||
template <typename BlockInputIterator>
|
||||
std::size_t initial_num_blocks(BlockInputIterator first,
|
||||
BlockInputIterator last)
|
||||
{
|
||||
typename detail::iterator_traits<BlockInputIterator>::iterator_category cat;
|
||||
return initial_num_blocks(first, last, cat);
|
||||
}
|
||||
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_DETAIL_DYNAMIC_BITSET_HPP
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,51 +0,0 @@
|
||||
// -----------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
|
||||
// Copyright (c) 2003-2006, 2008, 2025 Gennaro Prota
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#ifndef BOOST_DYNAMIC_BITSET_CONFIG_HPP_GP_20040424
|
||||
#define BOOST_DYNAMIC_BITSET_CONFIG_HPP_GP_20040424
|
||||
|
||||
#include "boost/config.hpp"
|
||||
|
||||
// no-op function to workaround gcc bug c++/8419
|
||||
//
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
template< typename T >
|
||||
T
|
||||
make_non_const( T t )
|
||||
{
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined( __GNUC__ )
|
||||
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT( expr ) \
|
||||
( boost::detail::make_non_const( expr ) )
|
||||
#else
|
||||
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT( expr ) ( expr )
|
||||
#endif
|
||||
|
||||
#if ! defined( BOOST_NO_CXX11_HDR_FUNCTIONAL ) && ! defined( BOOST_DYNAMIC_BITSET_NO_STD_HASH )
|
||||
# define BOOST_DYNAMIC_BITSET_SPECIALIZE_STD_HASH
|
||||
#endif
|
||||
|
||||
#if ( defined( _MSVC_LANG ) && _MSVC_LANG >= 201703L ) || __cplusplus >= 201703L
|
||||
# define BOOST_DYNAMIC_BITSET_USE_CPP17_OR_LATER
|
||||
#endif
|
||||
|
||||
#if ( defined( _MSVC_LANG ) && _MSVC_LANG >= 202002L ) || __cplusplus >= 202002L
|
||||
# define BOOST_DYNAMIC_BITSET_CONSTEXPR20 constexpr
|
||||
#else
|
||||
# define BOOST_DYNAMIC_BITSET_CONSTEXPR20
|
||||
#endif
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,154 +0,0 @@
|
||||
// -----------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
|
||||
// Copyright (c) 2003-2006, 2008, 2025 Gennaro Prota
|
||||
// Copyright (c) 2014 Glen Joseph Fernandes
|
||||
// (glenjofe@gmail.com)
|
||||
// Copyright (c) 2018 Evgeny Shulgin
|
||||
// Copyright (c) 2019 Andrey Semashev
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#ifndef BOOST_DETAIL_DYNAMIC_BITSET_HPP
|
||||
#define BOOST_DETAIL_DYNAMIC_BITSET_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail {
|
||||
namespace dynamic_bitset_impl {
|
||||
|
||||
template< typename AllocatorOrContainer, typename Block >
|
||||
class is_container
|
||||
{
|
||||
private:
|
||||
template< typename U >
|
||||
static decltype( std::declval< U >().resize( std::size_t{} ), std::declval< U >()[ 0 ], typename U::value_type(), std::is_same< typename U::value_type, Block >{}, std::true_type{} ) test( int );
|
||||
|
||||
template< typename >
|
||||
static std::false_type test( ... );
|
||||
|
||||
public:
|
||||
static constexpr bool value = decltype( test< AllocatorOrContainer >( 0 ) )::value;
|
||||
};
|
||||
|
||||
template< typename AllocatorOrContainer, bool IsContainer >
|
||||
class allocator_type_extractor_impl;
|
||||
|
||||
template< typename AllocatorOrContainer >
|
||||
class allocator_type_extractor_impl< AllocatorOrContainer, false >
|
||||
{
|
||||
public:
|
||||
typedef AllocatorOrContainer type;
|
||||
};
|
||||
|
||||
template< typename AllocatorOrContainer >
|
||||
class allocator_type_extractor_impl< AllocatorOrContainer, true >
|
||||
{
|
||||
public:
|
||||
typedef typename AllocatorOrContainer::allocator_type type;
|
||||
};
|
||||
|
||||
template< typename AllocatorOrContainer, typename Block >
|
||||
class allocator_type_extractor
|
||||
{
|
||||
public:
|
||||
typedef typename allocator_type_extractor_impl<
|
||||
AllocatorOrContainer,
|
||||
is_container< AllocatorOrContainer, Block >::value >::type type;
|
||||
};
|
||||
|
||||
template< typename T, int amount, int width /* = default */ >
|
||||
struct shifter
|
||||
{
|
||||
static BOOST_DYNAMIC_BITSET_CONSTEXPR20 void
|
||||
left_shift( T & v )
|
||||
{
|
||||
amount >= width ? ( v = 0 )
|
||||
: ( v >>= BOOST_DYNAMIC_BITSET_WRAP_CONSTANT( amount ) );
|
||||
}
|
||||
};
|
||||
|
||||
template< bool value >
|
||||
struct value_to_type
|
||||
{
|
||||
};
|
||||
|
||||
// for static_asserts
|
||||
template< typename T >
|
||||
struct allowed_block_type
|
||||
{
|
||||
enum
|
||||
{
|
||||
value = T( -1 ) > 0 // ensure T has no sign
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
struct allowed_block_type< bool >
|
||||
{
|
||||
enum
|
||||
{
|
||||
value = false
|
||||
};
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct is_numeric
|
||||
{
|
||||
enum
|
||||
{
|
||||
value = false
|
||||
};
|
||||
};
|
||||
|
||||
#define BOOST_dynamic_bitset_is_numeric( x ) \
|
||||
template<> \
|
||||
struct is_numeric< x > \
|
||||
{ \
|
||||
enum \
|
||||
{ \
|
||||
value = true \
|
||||
}; \
|
||||
} /**/
|
||||
|
||||
BOOST_dynamic_bitset_is_numeric( bool );
|
||||
BOOST_dynamic_bitset_is_numeric( char );
|
||||
|
||||
#if ! defined( BOOST_NO_INTRINSIC_WCHAR_T )
|
||||
BOOST_dynamic_bitset_is_numeric( wchar_t );
|
||||
#endif
|
||||
|
||||
BOOST_dynamic_bitset_is_numeric( signed char );
|
||||
BOOST_dynamic_bitset_is_numeric( short );
|
||||
BOOST_dynamic_bitset_is_numeric( int );
|
||||
BOOST_dynamic_bitset_is_numeric( long );
|
||||
BOOST_dynamic_bitset_is_numeric( long long );
|
||||
|
||||
BOOST_dynamic_bitset_is_numeric( unsigned char );
|
||||
BOOST_dynamic_bitset_is_numeric( unsigned short );
|
||||
BOOST_dynamic_bitset_is_numeric( unsigned int );
|
||||
BOOST_dynamic_bitset_is_numeric( unsigned long );
|
||||
BOOST_dynamic_bitset_is_numeric( unsigned long long );
|
||||
|
||||
// intentionally omitted
|
||||
// BOOST_dynamic_bitset_is_numeric(float);
|
||||
// BOOST_dynamic_bitset_is_numeric(double);
|
||||
// BOOST_dynamic_bitset_is_numeric(long double);
|
||||
|
||||
#undef BOOST_dynamic_bitset_is_numeric
|
||||
|
||||
} // dynamic_bitset_impl
|
||||
} // namespace detail
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,36 +0,0 @@
|
||||
// -----------------------------------------------------------
|
||||
// lowest_bit()
|
||||
//
|
||||
// Position of the lowest bit that is set.
|
||||
//
|
||||
// Copyright (c) 2003-2004, 2008, 2025 Gennaro Prota
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#ifndef BOOST_LOWEST_BIT_HPP_GP_20030301
|
||||
#define BOOST_LOWEST_BIT_HPP_GP_20030301
|
||||
|
||||
#include "boost/assert.hpp"
|
||||
#include "boost/core/bit.hpp"
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
|
||||
template< typename T >
|
||||
int
|
||||
lowest_bit( T x )
|
||||
{
|
||||
BOOST_ASSERT( x >= 1 );
|
||||
|
||||
return boost::core::countr_zero( static_cast< typename std::make_unsigned< T >::type >( x ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,49 +0,0 @@
|
||||
// -----------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2015 Seth Heeren
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#ifndef BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
|
||||
#define BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
|
||||
|
||||
#include "boost/core/nvp.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
|
||||
namespace boost {
|
||||
|
||||
// implementation for optional zero-copy serialization support
|
||||
template< typename Block, typename Allocator >
|
||||
class dynamic_bitset< Block, Allocator >::serialize_impl
|
||||
{
|
||||
public:
|
||||
template< typename Ar >
|
||||
static void
|
||||
serialize( Ar & ar, dynamic_bitset< Block, Allocator > & bs, unsigned )
|
||||
{
|
||||
ar & boost::make_nvp( "m_num_bits", bs.m_num_bits )
|
||||
& boost::make_nvp( "m_bits", bs.m_bits );
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// ADL hook to Boost Serialization library
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
template< typename Ar, typename Block, typename Allocator >
|
||||
void
|
||||
serialize( Ar & ar, dynamic_bitset< Block, Allocator > & bs, unsigned version )
|
||||
{
|
||||
dynamic_bitset< Block, Allocator >::serialize_impl::serialize( ar, bs, version );
|
||||
}
|
||||
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,13 +1,12 @@
|
||||
// -----------------------------------------------------------
|
||||
// (C) Copyright Chuck Allison and Jeremy Siek 2001, 2002.
|
||||
//
|
||||
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
|
||||
// Copyright (c) 2003-2004 Gennaro Prota
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
// 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.
|
||||
|
||||
// See http://www.boost.org/libs/dynamic_bitset for documentation.
|
||||
|
||||
#ifndef BOOST_DYNAMIC_BITSET_FWD_HPP
|
||||
#define BOOST_DYNAMIC_BITSET_FWD_HPP
|
||||
@@ -16,9 +15,10 @@
|
||||
|
||||
namespace boost {
|
||||
|
||||
template< typename Block = unsigned long, typename AllocatorOrContainer = std::allocator< Block > >
|
||||
template <typename Block = unsigned long,
|
||||
typename Allocator = std::allocator<Block> >
|
||||
class dynamic_bitset;
|
||||
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
||||
#endif // BOOST_DYNAMIC_BITSET_FWD_HPP
|
||||
|
||||
10
index.html
10
index.html
@@ -1,15 +1,9 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv=refresh content="0; URL=doc/html/index.html">
|
||||
<title>Automatic redirection</title>
|
||||
<meta http-equiv="refresh" content="0; URL=dynamic_bitset.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="dynamic_bitset.html">doc/html/index.html</a>. <hr>
|
||||
<p>© Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
<a href="dynamic_bitset.html">dynamic_bitset.html</a>.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<explicit-failures-markup>
|
||||
<library name="dynamic_bitset">
|
||||
<mark-unusable>
|
||||
<toolset name="*c++98"/>
|
||||
<toolset name="*gnu98"/>
|
||||
<toolset name="*c++0x"/>
|
||||
<toolset name="*gnu0x"/>
|
||||
<toolset name="msvc-7.1"/>
|
||||
<toolset name="msvc-8.*"/>
|
||||
<toolset name="msvc-9.*"/>
|
||||
<toolset name="msvc-10.*"/>
|
||||
<toolset name="msvc-11.*"/>
|
||||
<note author="Gennaro Prota">DynamicBitset requires at least C++11.</note>
|
||||
</mark-unusable>
|
||||
</library>
|
||||
</explicit-failures-markup>
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"key": "dynamic_bitset",
|
||||
"name": "Dynamic Bitset",
|
||||
"authors": [
|
||||
"Jeremy Siek",
|
||||
"Chuck Allison"
|
||||
],
|
||||
"description": "The dynamic_bitset template represents a set of bits. It provides access to the value of individual bits via operator[] and provides all of the bitwise operators that one can apply to builtin integers, such as operator& and operator<<. The number of bits in the set can change at runtime.",
|
||||
"category": [
|
||||
"Data structures"
|
||||
],
|
||||
"maintainers": [
|
||||
"Gennaro Prota <firstName.lastName -at- gmail.com>"
|
||||
],
|
||||
"cxxstd": "11"
|
||||
}
|
||||
@@ -1,50 +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)
|
||||
#
|
||||
|
||||
import os ;
|
||||
import testing ;
|
||||
|
||||
# import rules for testing conditional on config file variables
|
||||
import-search /boost/config/checks ;
|
||||
import config : requires ;
|
||||
|
||||
project : requirements <library>/boost/dynamic_bitset//boost_dynamic_bitset ;
|
||||
|
||||
test-suite dynamic_bitset :
|
||||
|
||||
[ run dyn_bitset_unit_tests1.cpp : : : <library>/boost/filesystem//boost_filesystem
|
||||
<library>/boost/system//boost_system ]
|
||||
[ run dyn_bitset_unit_tests2.cpp : : : <library>/boost/filesystem//boost_filesystem
|
||||
<library>/boost/system//boost_system ]
|
||||
[ run dyn_bitset_unit_tests3.cpp : : : <library>/boost/filesystem//boost_filesystem
|
||||
<library>/boost/system//boost_system ]
|
||||
[ run dyn_bitset_unit_tests4.cpp : : : <library>/boost/filesystem//boost_filesystem
|
||||
<library>/boost/system//boost_system ]
|
||||
[ run test_ambiguous_set.cpp ]
|
||||
[ run test_lowest_bit.cpp ]
|
||||
|
||||
[ run test_boost_hash.cpp ]
|
||||
[ run test_std_hash.cpp : : : [ requires cxx11_hdr_unordered_set ] ]
|
||||
|
||||
[ compile-fail test_std_hash.cpp : [ requires cxx11_hdr_unordered_set ]
|
||||
<define>BOOST_DYNAMIC_BITSET_NO_STD_HASH
|
||||
: test_std_hash_disabled ]
|
||||
;
|
||||
|
||||
# due to https://github.com/boostorg/serialization/issues/108
|
||||
if ! [ os.environ UBSAN_OPTIONS ]
|
||||
{
|
||||
test-suite dynamic_bitset_serialization :
|
||||
|
||||
[ run dyn_bitset_unit_tests5.cpp
|
||||
: : : <define>_SCL_SECURE_NO_WARNINGS=1
|
||||
<library>/boost/filesystem//boost_filesystem
|
||||
<library>/boost/serialization//boost_serialization
|
||||
<library>/boost/system//boost_system ]
|
||||
;
|
||||
}
|
||||
1630
test/bitset_test.hpp
1630
test/bitset_test.hpp
File diff suppressed because it is too large
Load Diff
@@ -1,22 +0,0 @@
|
||||
# Copyright 2021-2024 Alexander Grund
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.16)
|
||||
|
||||
project(cmake_subdir_test LANGUAGES CXX)
|
||||
|
||||
# Those 2 should work the same
|
||||
# while using find_package for the installed Boost avoids the need to manually specify dependencies
|
||||
if(BOOST_CI_INSTALL_TEST)
|
||||
find_package(boost_dynamic_bitset REQUIRED)
|
||||
else()
|
||||
set(BOOST_INCLUDE_LIBRARIES dynamic_bitset)
|
||||
add_subdirectory(../../../.. deps/boost EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
add_executable(main main.cpp)
|
||||
target_link_libraries(main Boost::dynamic_bitset)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME main COMMAND main)
|
||||
@@ -1,8 +0,0 @@
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
const boost::dynamic_bitset<> db{3, 4};
|
||||
|
||||
return db[2] ? 0 : 1;
|
||||
}
|
||||
@@ -1,633 +0,0 @@
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006, 2025 Gennaro Prota
|
||||
// Copyright (c) 2014 Ahmed Charles
|
||||
// Copyright (c) 2014 Riccardo Marcangelo
|
||||
//
|
||||
// Copyright (c) 2014 Glen Joseph Fernandes
|
||||
// (glenjofe@gmail.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include "boost/limits.hpp"
|
||||
|
||||
#if ! defined( BOOST_NO_CXX11_ALLOCATOR )
|
||||
# include <cstdlib>
|
||||
# include <new>
|
||||
|
||||
template< typename T >
|
||||
class minimal_allocator
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
|
||||
minimal_allocator()
|
||||
{
|
||||
}
|
||||
|
||||
template< typename U >
|
||||
minimal_allocator( const minimal_allocator< U > & )
|
||||
{
|
||||
}
|
||||
|
||||
T *
|
||||
allocate( std::size_t n )
|
||||
{
|
||||
void * p = std::malloc( sizeof( T ) * n );
|
||||
if ( ! p ) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
return static_cast< T * >( p );
|
||||
}
|
||||
|
||||
void
|
||||
deallocate( T * p, std::size_t )
|
||||
{
|
||||
std::free( p );
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#define BOOST_BITSET_TEST_COUNT( x ) ( sizeof( x ) / sizeof( x[ 0 ] ) )
|
||||
|
||||
template< typename Tests, typename String >
|
||||
void
|
||||
run_string_tests( const String & s )
|
||||
{
|
||||
const std::size_t len = s.length();
|
||||
const std::size_t step = len / 4 ? len / 4 : 1;
|
||||
|
||||
// bitset length determined by the string-related arguments
|
||||
std::size_t i;
|
||||
for ( i = 0; i <= len / 2; i += step ) {
|
||||
Tests::from_string( s, i, len / 2 ); // len/2 - i bits
|
||||
Tests::from_string( s, i, len ); // len - i bits
|
||||
Tests::from_string( s, i, 1 + len * 2 ); // len - i bits
|
||||
}
|
||||
|
||||
// bitset length explicitly specified
|
||||
for ( i = 0; i <= len / 2; i += step ) {
|
||||
for ( std::size_t sz = 0; sz <= len * 4; sz += step * 2 ) {
|
||||
Tests::from_string( s, i, len / 2, sz );
|
||||
Tests::from_string( s, i, len, sz );
|
||||
Tests::from_string( s, i, 1 + len * 2, sz );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tests the do-the-right-thing constructor dispatch
|
||||
template< typename Tests, typename T >
|
||||
void
|
||||
run_numeric_ctor_tests()
|
||||
{
|
||||
const int bits_per_block = Tests::bits_per_block;
|
||||
const int width = std::numeric_limits< T >::digits;
|
||||
const T ma = ( std::numeric_limits< T >::max )();
|
||||
const T mi = ( std::numeric_limits< T >::min )();
|
||||
|
||||
int sizes[] = {
|
||||
0, 7 * width / 10, width, 13 * width / 10, 3 * width, 7 * bits_per_block / 10, bits_per_block, 13 * bits_per_block / 10, 3 * bits_per_block
|
||||
};
|
||||
|
||||
const T numbers[] = {
|
||||
T( -1 ), T( -3 ), T( -8 ), T( -15 ), T( mi / 2 ), T( mi ), T( 0 ), T( 1 ), T( 3 ), T( 8 ), T( 15 ), T( ma / 2 ), T( ma )
|
||||
};
|
||||
|
||||
for ( std::size_t s = 0; s < BOOST_BITSET_TEST_COUNT( sizes ); ++s ) {
|
||||
for ( std::size_t n = 0; n < BOOST_BITSET_TEST_COUNT( numbers ); ++n ) {
|
||||
// can match ctor from ulong or templated one
|
||||
Tests::from_unsigned_long( sizes[ s ], numbers[ n ] );
|
||||
|
||||
typedef std::size_t compare_type;
|
||||
const compare_type sz = sizes[ s ];
|
||||
// this condition is to be sure that size is representable in T, so
|
||||
// that for signed T's we avoid implementation-defined behavior [if ma
|
||||
// is larger than what std::size_t can hold then this is ok for our
|
||||
// purposes: our sizes are anyhow < max(size_t)], which in turn could
|
||||
// make the first argument of from_unsigned_long() a small negative,
|
||||
// later converted to a very large unsigned. Example: signed 8-bit
|
||||
// char (CHAR_MAX=127), bits_per_block=64, sz = 192 > 127.
|
||||
const bool fits =
|
||||
sz <= static_cast< compare_type >( ma );
|
||||
|
||||
if ( fits ) {
|
||||
// can match templated ctor only (so we test dispatching)
|
||||
Tests::from_unsigned_long( static_cast< T >( sizes[ s ] ), numbers[ n ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
|
||||
void
|
||||
run_test_cases()
|
||||
{
|
||||
typedef boost::dynamic_bitset< Block, AllocatorOrContainer >
|
||||
bitset_type;
|
||||
typedef bitset_test< bitset_type > Tests;
|
||||
const int bits_per_block = bitset_type::bits_per_block;
|
||||
|
||||
const std::string long_string = get_long_string();
|
||||
const Block all_1s = static_cast< Block >( -1 );
|
||||
|
||||
//=====================================================================
|
||||
// Test construction from unsigned long
|
||||
{
|
||||
// NOTE:
|
||||
//
|
||||
// 1. keep this in sync with the numeric types supported
|
||||
// for constructor dispatch (of course)
|
||||
// 2. bool is tested separately; ugly and inelegant, but
|
||||
// we don't have much time to think of a better solution
|
||||
// which is likely to work on broken compilers
|
||||
//
|
||||
const int sizes[] = {
|
||||
0, 1, 3, 7 * bits_per_block / 10, bits_per_block, 13 * bits_per_block / 10, 3 * bits_per_block
|
||||
};
|
||||
|
||||
const bool values[] = { false, true };
|
||||
|
||||
for ( std::size_t s = 0; s < BOOST_BITSET_TEST_COUNT( sizes ); ++s ) {
|
||||
for ( std::size_t v = 0; v < BOOST_BITSET_TEST_COUNT( values ); ++v ) {
|
||||
Tests::from_unsigned_long( sizes[ s ], values[ v ] );
|
||||
Tests::from_unsigned_long( sizes[ s ] != 0, values[ v ] );
|
||||
}
|
||||
}
|
||||
|
||||
run_numeric_ctor_tests< Tests, char >();
|
||||
|
||||
#if ! defined( BOOST_NO_INTRINSIC_WCHAR_T )
|
||||
run_numeric_ctor_tests< Tests, wchar_t >();
|
||||
#endif
|
||||
|
||||
run_numeric_ctor_tests< Tests, signed char >();
|
||||
run_numeric_ctor_tests< Tests, short int >();
|
||||
run_numeric_ctor_tests< Tests, int >();
|
||||
run_numeric_ctor_tests< Tests, long int >();
|
||||
run_numeric_ctor_tests< Tests, long long >();
|
||||
|
||||
run_numeric_ctor_tests< Tests, unsigned char >();
|
||||
run_numeric_ctor_tests< Tests, unsigned short >();
|
||||
run_numeric_ctor_tests< Tests, unsigned int >();
|
||||
run_numeric_ctor_tests< Tests, unsigned long >();
|
||||
run_numeric_ctor_tests< Tests, unsigned long long >();
|
||||
}
|
||||
//=====================================================================
|
||||
// Test construction from a string
|
||||
{
|
||||
run_string_tests< Tests >( std::string( "" ) ); // empty string
|
||||
run_string_tests< Tests >( std::string( "1" ) );
|
||||
|
||||
run_string_tests< Tests >( long_string );
|
||||
|
||||
#if ! defined BOOST_NO_STD_WSTRING
|
||||
// I need to decide what to do for non "C" locales here. On
|
||||
// one hand I should have better tests. On the other one
|
||||
// I don't want tests for dynamic_bitset to cope with locales,
|
||||
// ctype::widen, etc. (but that's what you deserve when you
|
||||
// don't separate concerns at the library level)
|
||||
//
|
||||
run_string_tests< Tests >(
|
||||
std::wstring( L"11111000000111111111010101010101010101010111111" ) );
|
||||
#endif
|
||||
|
||||
// Note that these are _valid_ arguments
|
||||
Tests::from_string( std::string( "x11y" ), 1, 2 );
|
||||
Tests::from_string( std::string( "x11" ), 1, 10 );
|
||||
Tests::from_string( std::string( "x11" ), 1, 10, 10 );
|
||||
}
|
||||
//=====================================================================
|
||||
// test from_block_range
|
||||
{
|
||||
std::vector< Block > blocks;
|
||||
Tests::from_block_range( blocks );
|
||||
}
|
||||
{
|
||||
std::vector< Block > blocks( 3 );
|
||||
blocks[ 0 ] = static_cast< Block >( 0 );
|
||||
blocks[ 1 ] = static_cast< Block >( 1 );
|
||||
blocks[ 2 ] = all_1s;
|
||||
Tests::from_block_range( blocks );
|
||||
}
|
||||
{
|
||||
const unsigned int n = ( std::numeric_limits< unsigned char >::max )();
|
||||
std::vector< Block > blocks( n );
|
||||
for ( typename std::vector< Block >::size_type i = 0; i < n; ++i )
|
||||
blocks[ i ] = static_cast< Block >( i );
|
||||
Tests::from_block_range( blocks );
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
// test iterators
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::iterate_forward( b );
|
||||
Tests::iterate_backward( b );
|
||||
Tests::iterator_operations( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( 1, 1ul );
|
||||
Tests::iterate_forward( b );
|
||||
Tests::iterate_backward( b );
|
||||
Tests::iterator_operations( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( bitset_type::bits_per_block, 100ul );
|
||||
Tests::iterate_forward( b );
|
||||
Tests::iterate_backward( b );
|
||||
Tests::iterator_operations( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::iterate_forward( b );
|
||||
Tests::iterate_backward( b );
|
||||
Tests::iterator_operations( b );
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
// test to_block_range
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::to_block_range( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( 1, 1ul );
|
||||
Tests::to_block_range( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::to_block_range( b );
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
// Test copy constructor
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::copy_constructor( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( "0" );
|
||||
Tests::copy_constructor( b );
|
||||
}
|
||||
{
|
||||
bitset_type b ( long_string );
|
||||
Tests::copy_constructor( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test copy assignment operator
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::copy_assignment_operator( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( "1" ), b( "0" );
|
||||
Tests::copy_assignment_operator( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
Tests::copy_assignment_operator( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a;
|
||||
bitset_type b( long_string ); // b greater than a, a empty
|
||||
Tests::copy_assignment_operator( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( "0" );
|
||||
bitset_type b( long_string ); // b greater than a
|
||||
Tests::copy_assignment_operator( a, b );
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
// Test move constructor
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::move_constructor( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( "0" );
|
||||
Tests::move_constructor( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::move_constructor( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test move assignment operator
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::move_assignment_operator( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( "1" ), b( "0" );
|
||||
Tests::move_assignment_operator( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
Tests::move_assignment_operator( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a;
|
||||
bitset_type b( long_string ); // b greater than a, a empty
|
||||
Tests::move_assignment_operator( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( "0" );
|
||||
bitset_type b( long_string ); // b greater than a
|
||||
Tests::move_assignment_operator( a, b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test swap
|
||||
{
|
||||
bitset_type a;
|
||||
bitset_type b( "1" );
|
||||
Tests::swap( a, b );
|
||||
Tests::swap( b, a );
|
||||
Tests::swap( a, a );
|
||||
}
|
||||
{
|
||||
bitset_type a;
|
||||
bitset_type b( long_string );
|
||||
Tests::swap( a, b );
|
||||
Tests::swap( b, a );
|
||||
}
|
||||
{
|
||||
bitset_type a( "0" );
|
||||
bitset_type b( long_string );
|
||||
Tests::swap( a, b );
|
||||
Tests::swap( b, a );
|
||||
Tests::swap( a, a );
|
||||
Tests::swap( b, b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test resize
|
||||
{
|
||||
bitset_type a;
|
||||
Tests::resize( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( "0" );
|
||||
Tests::resize( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( "1" );
|
||||
Tests::resize( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string );
|
||||
Tests::resize( a );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test clear
|
||||
{
|
||||
bitset_type a;
|
||||
Tests::clear( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string );
|
||||
Tests::clear( a );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test pop back
|
||||
{
|
||||
bitset_type a( "01" );
|
||||
Tests::pop_back( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( "10" );
|
||||
Tests::pop_back( a );
|
||||
}
|
||||
{
|
||||
const int size_to_fill_all_blocks = 4 * bits_per_block;
|
||||
bitset_type a( size_to_fill_all_blocks, 255ul );
|
||||
Tests::pop_back( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string.c_str() );
|
||||
Tests::pop_back( a );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test pop_front
|
||||
{
|
||||
bitset_type a( "01" );
|
||||
Tests::pop_front( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( "10" );
|
||||
Tests::pop_front( a );
|
||||
}
|
||||
{
|
||||
const int size_to_fill_all_blocks = 4 * bits_per_block;
|
||||
bitset_type a( size_to_fill_all_blocks, 255ul );
|
||||
Tests::pop_front( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string.c_str() );
|
||||
Tests::pop_front( a );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test append bit
|
||||
{
|
||||
bitset_type a;
|
||||
Tests::append_bit( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( "0" );
|
||||
Tests::append_bit( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( "1" );
|
||||
Tests::append_bit( a );
|
||||
}
|
||||
{
|
||||
const int size_to_fill_all_blocks = 4 * bits_per_block;
|
||||
bitset_type a( size_to_fill_all_blocks, 255ul );
|
||||
Tests::append_bit( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string );
|
||||
Tests::append_bit( a );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test push_front
|
||||
{
|
||||
bitset_type a;
|
||||
Tests::prepend_bit( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( "0" );
|
||||
Tests::prepend_bit( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( "1" );
|
||||
Tests::prepend_bit( a );
|
||||
}
|
||||
{
|
||||
const int size_to_fill_all_blocks = 4 * bits_per_block;
|
||||
bitset_type a( size_to_fill_all_blocks, 255ul );
|
||||
Tests::prepend_bit( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string );
|
||||
Tests::prepend_bit( a );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test append block
|
||||
{
|
||||
bitset_type a;
|
||||
Tests::append_block( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( "0" );
|
||||
Tests::append_block( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( "1" );
|
||||
Tests::append_block( a );
|
||||
}
|
||||
{
|
||||
const int size_to_fill_all_blocks = 4 * bits_per_block;
|
||||
bitset_type a( size_to_fill_all_blocks, 15ul );
|
||||
Tests::append_block( a );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string.c_str() );
|
||||
Tests::append_block( a );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test append block range
|
||||
{
|
||||
bitset_type a;
|
||||
std::vector< Block > blocks;
|
||||
Tests::append_block_range( a, blocks );
|
||||
}
|
||||
{
|
||||
bitset_type a( "0" );
|
||||
std::vector< Block > blocks( 3 );
|
||||
blocks[ 0 ] = static_cast< Block >( 0 );
|
||||
blocks[ 1 ] = static_cast< Block >( 1 );
|
||||
blocks[ 2 ] = all_1s;
|
||||
Tests::append_block_range( a, blocks );
|
||||
}
|
||||
{
|
||||
bitset_type a( "1" );
|
||||
const unsigned int n = ( std::numeric_limits< unsigned char >::max )();
|
||||
std::vector< Block > blocks( n );
|
||||
for ( typename std::vector< Block >::size_type i = 0; i < n; ++i )
|
||||
blocks[ i ] = static_cast< Block >( i );
|
||||
Tests::append_block_range( a, blocks );
|
||||
}
|
||||
{
|
||||
bitset_type a;
|
||||
a.append( Block( 1 ) );
|
||||
a.append( Block( 2 ) );
|
||||
Block x[] = { 3, 4, 5 };
|
||||
std::size_t sz = sizeof( x ) / sizeof( x[ 0 ] );
|
||||
std::vector< Block > blocks( x, x + sz );
|
||||
Tests::append_block_range( a, blocks );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string.c_str() );
|
||||
std::vector< Block > blocks( 3 );
|
||||
blocks[ 0 ] = static_cast< Block >( 0 );
|
||||
blocks[ 1 ] = static_cast< Block >( 1 );
|
||||
blocks[ 2 ] = all_1s;
|
||||
Tests::append_block_range( a, blocks );
|
||||
}
|
||||
// Test with input iterators
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::append_block_range_input_iter( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( "0" );
|
||||
Tests::append_block_range_input_iter( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string.c_str() );
|
||||
Tests::append_block_range_input_iter( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test bracket operator
|
||||
{
|
||||
bitset_type b1;
|
||||
std::vector< bool > bitvec1;
|
||||
Tests::operator_bracket( b1, bitvec1 );
|
||||
}
|
||||
{
|
||||
bitset_type b( "1" );
|
||||
std::vector< bool > bit_vec( 1, true );
|
||||
Tests::operator_bracket( b, bit_vec );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string.c_str() );
|
||||
std::size_t n = long_string.size();
|
||||
std::vector< bool > bit_vec( n );
|
||||
for ( std::size_t i = 0; i < n; ++i )
|
||||
bit_vec[ i ] = long_string[ n - 1 - i ] == '0' ? 0 : 1;
|
||||
Tests::operator_bracket( b, bit_vec );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test at
|
||||
{
|
||||
bitset_type b1;
|
||||
std::vector< bool > bitvec1;
|
||||
Tests::at( b1, bitvec1 );
|
||||
}
|
||||
{
|
||||
bitset_type b( "1" );
|
||||
std::vector< bool > bit_vec( 1, true );
|
||||
Tests::at( b, bit_vec );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string.c_str() );
|
||||
std::size_t n = long_string.size();
|
||||
std::vector< bool > bit_vec( n );
|
||||
for ( std::size_t i = 0; i < n; ++i )
|
||||
bit_vec[ i ] = long_string[ n - 1 - i ] == '0' ? 0 : 1;
|
||||
Tests::at( b, bit_vec );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test max_size
|
||||
#if ! defined( BOOST_NO_CXX11_ALLOCATOR )
|
||||
{
|
||||
typedef boost::dynamic_bitset< Block, minimal_allocator< Block > > Bitset;
|
||||
Bitset b;
|
||||
bitset_test< Bitset >::max_size( b );
|
||||
}
|
||||
#endif
|
||||
{
|
||||
typedef boost::dynamic_bitset< Block, small_vector< Block > > Bitset;
|
||||
Bitset b;
|
||||
bitset_test< Bitset >::max_size( b );
|
||||
}
|
||||
// Test copy-initialize with default constructor
|
||||
{
|
||||
bitset_type b[ 1 ] = {};
|
||||
(void)b;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
run_test_cases< unsigned char >();
|
||||
run_test_cases< unsigned char, small_vector< unsigned char > >();
|
||||
run_test_cases< unsigned short >();
|
||||
run_test_cases< unsigned short, small_vector< unsigned short > >();
|
||||
run_test_cases< unsigned int >();
|
||||
run_test_cases< unsigned int, small_vector< unsigned int > >();
|
||||
run_test_cases< unsigned long >();
|
||||
run_test_cases< unsigned long, small_vector< unsigned long > >();
|
||||
run_test_cases< unsigned long long >();
|
||||
run_test_cases< unsigned long long, small_vector< unsigned long long > >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,387 +0,0 @@
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006, 2025 Gennaro Prota
|
||||
// Copyright (c) 2014 Ahmed Charles
|
||||
// Copyright (c) 2018 Evgeny Shulgin
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
|
||||
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
|
||||
void
|
||||
run_test_cases()
|
||||
{
|
||||
typedef boost::dynamic_bitset< Block, AllocatorOrContainer > bitset_type;
|
||||
typedef bitset_test< bitset_type > Tests;
|
||||
const int bits_per_block = bitset_type::bits_per_block;
|
||||
|
||||
const std::string long_string = get_long_string();
|
||||
|
||||
//=====================================================================
|
||||
// Test operator&=
|
||||
{
|
||||
bitset_type lhs, rhs;
|
||||
Tests::and_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
|
||||
Tests::and_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
|
||||
Tests::and_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
|
||||
Tests::and_assignment( lhs, rhs );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator |=
|
||||
{
|
||||
bitset_type lhs, rhs;
|
||||
Tests::or_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
|
||||
Tests::or_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
|
||||
Tests::or_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
|
||||
Tests::or_assignment( lhs, rhs );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator^=
|
||||
{
|
||||
bitset_type lhs, rhs;
|
||||
Tests::xor_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
|
||||
Tests::xor_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
|
||||
Tests::xor_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string ), rhs( long_string );
|
||||
Tests::xor_assignment( lhs, rhs );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator-=
|
||||
{
|
||||
bitset_type lhs, rhs;
|
||||
Tests::sub_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
|
||||
Tests::sub_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( std::string( "0" ) ), rhs( std::string( "1" ) );
|
||||
Tests::sub_assignment( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string ), rhs( long_string );
|
||||
Tests::sub_assignment( lhs, rhs );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator<<=
|
||||
{ // case pos == 0
|
||||
std::size_t pos = 0;
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::shift_left_assignment( b, pos );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "1010" ) );
|
||||
Tests::shift_left_assignment( b, pos );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::shift_left_assignment( b, pos );
|
||||
}
|
||||
}
|
||||
{
|
||||
// test with both multiple and
|
||||
// non multiple of bits_per_block
|
||||
const int how_many = 10;
|
||||
for ( int i = 1; i <= how_many; ++i ) {
|
||||
std::size_t multiple = i * bits_per_block;
|
||||
std::size_t non_multiple = multiple - 1;
|
||||
bitset_type b( long_string );
|
||||
|
||||
Tests::shift_left_assignment( b, multiple );
|
||||
Tests::shift_left_assignment( b, non_multiple );
|
||||
}
|
||||
}
|
||||
{ // case pos == size()/2
|
||||
std::size_t pos = long_string.size() / 2;
|
||||
bitset_type b( long_string );
|
||||
Tests::shift_left_assignment( b, pos );
|
||||
}
|
||||
{ // case pos >= n
|
||||
std::size_t pos = long_string.size();
|
||||
bitset_type b( long_string );
|
||||
Tests::shift_left_assignment( b, pos );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator>>=
|
||||
{ // case pos == 0
|
||||
std::size_t pos = 0;
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::shift_right_assignment( b, pos );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "1010" ) );
|
||||
Tests::shift_right_assignment( b, pos );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::shift_right_assignment( b, pos );
|
||||
}
|
||||
}
|
||||
{
|
||||
// test with both multiple and
|
||||
// non multiple of bits_per_block
|
||||
const int how_many = 10;
|
||||
for ( int i = 1; i <= how_many; ++i ) {
|
||||
std::size_t multiple = i * bits_per_block;
|
||||
std::size_t non_multiple = multiple - 1;
|
||||
bitset_type b( long_string );
|
||||
|
||||
Tests::shift_right_assignment( b, multiple );
|
||||
Tests::shift_right_assignment( b, non_multiple );
|
||||
}
|
||||
}
|
||||
{ // case pos == size()/2
|
||||
std::size_t pos = long_string.size() / 2;
|
||||
bitset_type b( long_string );
|
||||
Tests::shift_right_assignment( b, pos );
|
||||
}
|
||||
{ // case pos >= n
|
||||
std::size_t pos = long_string.size();
|
||||
bitset_type b( long_string );
|
||||
Tests::shift_right_assignment( b, pos );
|
||||
}
|
||||
//=====================================================================
|
||||
// test b.set()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::set_all( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::set_all( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::set_all( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.set(pos)
|
||||
{ // case pos >= b.size()
|
||||
bitset_type b;
|
||||
Tests::set_one( b, 0, true );
|
||||
Tests::set_one( b, 0, false );
|
||||
}
|
||||
{ // case pos < b.size()
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::set_one( b, 0, true );
|
||||
Tests::set_one( b, 0, false );
|
||||
}
|
||||
{ // case pos == b.size() / 2
|
||||
bitset_type b( long_string );
|
||||
Tests::set_one( b, long_string.size() / 2, true );
|
||||
Tests::set_one( b, long_string.size() / 2, false );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.set(pos, len)
|
||||
|
||||
// case size is 0
|
||||
{
|
||||
bitset_type b( std::string( "10" ) ) ;
|
||||
Tests::set_segment( b, 0, 0, true );
|
||||
Tests::set_segment( b, 0, 0, false );
|
||||
}
|
||||
{ // case size is 1
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::set_segment( b, 0, 1, true );
|
||||
Tests::set_segment( b, 0, 1, false );
|
||||
}
|
||||
{ // case fill the whole set
|
||||
bitset_type b( long_string );
|
||||
Tests::set_segment( b, 0, b.size(), true );
|
||||
Tests::set_segment( b, 0, b.size(), false );
|
||||
}
|
||||
{ // case pos = size / 4, len = size / 2
|
||||
bitset_type b( long_string );
|
||||
Tests::set_segment( b, b.size() / 4, b.size() / 2, true );
|
||||
Tests::set_segment( b, b.size() / 4, b.size() / 2, false );
|
||||
}
|
||||
{ // case pos = block_size / 2, len = size - block_size
|
||||
bitset_type b( long_string );
|
||||
Tests::set_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block, true );
|
||||
Tests::set_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block, false );
|
||||
}
|
||||
{ // case pos = 1, len = size - 2
|
||||
bitset_type b( long_string );
|
||||
Tests::set_segment( b, 1, b.size() - 2, true );
|
||||
Tests::set_segment( b, 1, b.size() - 2, false );
|
||||
}
|
||||
{ // case pos = 3, len = 7
|
||||
bitset_type b( long_string );
|
||||
Tests::set_segment( b, 3, 7, true );
|
||||
Tests::set_segment( b, 3, 7, false );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.reset()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::reset_all( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::reset_all( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::reset_all( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.reset(pos)
|
||||
{ // case pos >= b.size()
|
||||
bitset_type b;
|
||||
Tests::reset_one( b, 0 );
|
||||
}
|
||||
{ // case pos < b.size()
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::reset_one( b, 0 );
|
||||
}
|
||||
{ // case pos == b.size() / 2
|
||||
bitset_type b( long_string );
|
||||
Tests::reset_one( b, long_string.size() / 2 );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.reset(pos, len)
|
||||
{ // case size is 1
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::reset_segment( b, 0, 1 );
|
||||
}
|
||||
{ // case fill the whole set
|
||||
bitset_type b( long_string );
|
||||
Tests::reset_segment( b, 0, b.size() );
|
||||
}
|
||||
{ // case pos = size / 4, len = size / 2
|
||||
bitset_type b( long_string );
|
||||
Tests::reset_segment( b, b.size() / 4, b.size() / 2 );
|
||||
}
|
||||
{ // case pos = block_size / 2, len = size - block_size
|
||||
bitset_type b( long_string );
|
||||
Tests::reset_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block );
|
||||
}
|
||||
{ // case pos = 1, len = size - 2
|
||||
bitset_type b( long_string );
|
||||
Tests::reset_segment( b, 1, b.size() - 2 );
|
||||
}
|
||||
{ // case pos = 3, len = 7
|
||||
bitset_type b( long_string );
|
||||
Tests::reset_segment( b, 3, 7 );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test ~b
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::operator_flip( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "1" ) );
|
||||
Tests::operator_flip( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::operator_flip( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.flip()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::flip_all( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "1" ) );
|
||||
Tests::flip_all( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::flip_all( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.flip(pos)
|
||||
{ // case pos >= b.size()
|
||||
bitset_type b;
|
||||
Tests::flip_one( b, 0 );
|
||||
}
|
||||
{ // case pos < b.size()
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::flip_one( b, 0 );
|
||||
}
|
||||
{ // case pos == b.size() / 2
|
||||
bitset_type b( long_string );
|
||||
Tests::flip_one( b, long_string.size() / 2 );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.flip(pos, len)
|
||||
{ // case size is 1
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::flip_segment( b, 0, 1 );
|
||||
}
|
||||
{ // case fill the whole set
|
||||
bitset_type b( long_string );
|
||||
Tests::flip_segment( b, 0, b.size() );
|
||||
}
|
||||
{ // case pos = size / 4, len = size / 2
|
||||
bitset_type b( long_string );
|
||||
Tests::flip_segment( b, b.size() / 4, b.size() / 2 );
|
||||
}
|
||||
{ // case pos = block_size / 2, len = size - block_size
|
||||
bitset_type b( long_string );
|
||||
Tests::flip_segment( b, bitset_type::bits_per_block / 2, b.size() - bitset_type::bits_per_block );
|
||||
}
|
||||
{ // case pos = 1, len = size - 2
|
||||
bitset_type b( long_string );
|
||||
Tests::flip_segment( b, 1, b.size() - 2 );
|
||||
}
|
||||
{ // case pos = 3, len = 7
|
||||
bitset_type b( long_string );
|
||||
Tests::flip_segment( b, 3, 7 );
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
run_test_cases< unsigned char >();
|
||||
run_test_cases< unsigned char, small_vector< unsigned char > >();
|
||||
run_test_cases< unsigned short >();
|
||||
run_test_cases< unsigned short, small_vector< unsigned short > >();
|
||||
run_test_cases< unsigned int >();
|
||||
run_test_cases< unsigned int, small_vector< unsigned int > >();
|
||||
run_test_cases< unsigned long >();
|
||||
run_test_cases< unsigned long, small_vector< unsigned long > >();
|
||||
run_test_cases< unsigned long long >();
|
||||
run_test_cases< unsigned long long, small_vector< unsigned long long > >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,841 +0,0 @@
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006, 2025 Gennaro Prota
|
||||
// Copyright (c) 2014 Ahmed Charles
|
||||
// Copyright (c) 2014 Riccardo Marcangelo
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include "boost/limits.hpp"
|
||||
#include <assert.h>
|
||||
|
||||
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
|
||||
void
|
||||
run_test_cases()
|
||||
{
|
||||
// a bunch of typedefs which will be handy later on
|
||||
typedef boost::dynamic_bitset< Block, AllocatorOrContainer > bitset_type;
|
||||
typedef bitset_test< bitset_type > Tests;
|
||||
// typedef typename bitset_type::size_type size_type; // unusable with Borland 5.5.1
|
||||
|
||||
const std::string long_string = get_long_string();
|
||||
const std::size_t ul_width = std::numeric_limits< unsigned long >::digits;
|
||||
|
||||
//=====================================================================
|
||||
// Test b.empty()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::empty( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( 1, 1ul );
|
||||
Tests::empty( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( bitset_type::bits_per_block + bitset_type::bits_per_block / 2, 15ul );
|
||||
Tests::empty( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.to_long()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::to_ulong( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "1" ) );
|
||||
Tests::to_ulong( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( bitset_type::bits_per_block, static_cast< unsigned long >( -1 ) );
|
||||
Tests::to_ulong( b );
|
||||
}
|
||||
{
|
||||
std::string str( ul_width - 1, '1' );
|
||||
bitset_type b( str );
|
||||
Tests::to_ulong( b );
|
||||
}
|
||||
{
|
||||
std::string ul_str( ul_width, '1' );
|
||||
bitset_type b( ul_str );
|
||||
Tests::to_ulong( b );
|
||||
}
|
||||
{ // case overflow
|
||||
bitset_type b( long_string );
|
||||
Tests::to_ulong( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test to_string(b, str)
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::to_string( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::to_string( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::to_string( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.count()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::count( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::count( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "1" ) );
|
||||
Tests::count( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( 8, 255ul );
|
||||
Tests::count( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::count( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.size()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::size( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::size( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::size( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.capacity()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::capacity( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( 100 );
|
||||
Tests::capacity( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.reserve()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::reserve_test_one( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( 100 );
|
||||
Tests::reserve_test_two( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.shrink_to_fit()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::shrink_to_fit_test_one( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( 100 );
|
||||
Tests::shrink_to_fit_test_two( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.all()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::all( b );
|
||||
Tests::all( ~b );
|
||||
Tests::all( b.set() );
|
||||
Tests::all( b.reset() );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::all( b );
|
||||
Tests::all( ~b );
|
||||
Tests::all( b.set() );
|
||||
Tests::all( b.reset() );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::all( b );
|
||||
Tests::all( ~b );
|
||||
Tests::all( b.set() );
|
||||
Tests::all( b.reset() );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.any()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::any( b );
|
||||
Tests::any( ~b );
|
||||
Tests::any( b.set() );
|
||||
Tests::any( b.reset() );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::any( b );
|
||||
Tests::any( ~b );
|
||||
Tests::any( b.set() );
|
||||
Tests::any( b.reset() );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::any( b );
|
||||
Tests::any( ~b );
|
||||
Tests::any( b.set() );
|
||||
Tests::any( b.reset() );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.none()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::none( b );
|
||||
Tests::none( ~b );
|
||||
Tests::none( b.set() );
|
||||
Tests::none( b.reset() );
|
||||
}
|
||||
{
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::none( b );
|
||||
Tests::none( ~b );
|
||||
Tests::none( b.set() );
|
||||
Tests::none( b.reset() );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string );
|
||||
Tests::none( b );
|
||||
Tests::none( ~b );
|
||||
Tests::none( b.set() );
|
||||
Tests::none( b.reset() );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a.is_subset_of(b)
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::subset( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
|
||||
Tests::subset( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
|
||||
Tests::subset( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
Tests::subset( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
a[ long_string.size() / 2 ].flip();
|
||||
Tests::subset( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
b[ long_string.size() / 2 ].flip();
|
||||
Tests::subset( a, b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a.is_proper_subset_of(b)
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::proper_subset( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
|
||||
Tests::proper_subset( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
|
||||
Tests::proper_subset( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
Tests::proper_subset( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
a[ long_string.size() / 2 ].flip();
|
||||
Tests::proper_subset( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
b[ long_string.size() / 2 ].flip();
|
||||
Tests::proper_subset( a, b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test intersects
|
||||
{
|
||||
bitset_type a; // empty
|
||||
bitset_type b;
|
||||
Tests::intersects( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a;
|
||||
bitset_type b( 5, 8ul );
|
||||
Tests::intersects( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( 8, 0ul );
|
||||
bitset_type b( 15, 0ul );
|
||||
b[ 9 ] = 1;
|
||||
Tests::intersects( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( 15, 0ul );
|
||||
bitset_type b( 22, 0ul );
|
||||
a[ 14 ] = b[ 14 ] = 1;
|
||||
Tests::intersects( a, b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test find_first
|
||||
{
|
||||
// empty bitset
|
||||
bitset_type b;
|
||||
Tests::find_first( b );
|
||||
Tests::find_first( b, 0, false );
|
||||
}
|
||||
{
|
||||
// bitset of size 1
|
||||
bitset_type b( 1, 1ul );
|
||||
Tests::find_first( b );
|
||||
Tests::find_first( b, 0, false );
|
||||
}
|
||||
{
|
||||
// all-0s bitset
|
||||
bitset_type b( 4 * bitset_type::bits_per_block, 0ul );
|
||||
Tests::find_first( b );
|
||||
Tests::find_first( b, 0, false );
|
||||
}
|
||||
{
|
||||
// first bit on or off
|
||||
bitset_type b( 1, 1ul );
|
||||
Tests::find_first( b );
|
||||
b.set( 0, false );
|
||||
Tests::find_first( b, 0, false );
|
||||
}
|
||||
{
|
||||
// last bit on or off
|
||||
bitset_type b( 4 * bitset_type::bits_per_block - 1, 0ul );
|
||||
b.set( b.size() - 1 );
|
||||
Tests::find_first( b );
|
||||
b.set( b.size() - 1, false );
|
||||
Tests::find_first( b, 0, false );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test find_next, find_next_off, offset find_first and offset find_first_off
|
||||
{
|
||||
// empty bitset
|
||||
bitset_type b;
|
||||
|
||||
// check
|
||||
Tests::find_pos( b, 0 );
|
||||
Tests::find_pos( b, 1 );
|
||||
Tests::find_pos( b, 200 );
|
||||
Tests::find_pos( b, b.npos );
|
||||
Tests::find_pos( b, 0, false );
|
||||
Tests::find_pos( b, 1, false );
|
||||
Tests::find_pos( b, 200, false );
|
||||
Tests::find_pos( b, b.npos, false );
|
||||
}
|
||||
{
|
||||
// bitset of size 1 (find_next can never find)
|
||||
bitset_type b( 1, 1ul );
|
||||
|
||||
// check
|
||||
Tests::find_pos( b, 0 );
|
||||
Tests::find_pos( b, 1 );
|
||||
Tests::find_pos( b, 200 );
|
||||
Tests::find_pos( b, b.npos );
|
||||
Tests::find_pos( b, 0, false );
|
||||
Tests::find_pos( b, 1, false );
|
||||
Tests::find_pos( b, 200, false );
|
||||
Tests::find_pos( b, b.npos, false );
|
||||
}
|
||||
{
|
||||
// all-1s bitset
|
||||
bitset_type b( 16 * bitset_type::bits_per_block );
|
||||
b.set();
|
||||
|
||||
// check
|
||||
const typename bitset_type::size_type larger_than_size = 5 + b.size();
|
||||
for ( typename bitset_type::size_type i = 0; i <= larger_than_size; ++i ) {
|
||||
Tests::find_pos( b, i );
|
||||
Tests::find_pos( b, i, false );
|
||||
}
|
||||
Tests::find_pos( b, b.npos );
|
||||
Tests::find_pos( b, b.npos, false );
|
||||
}
|
||||
{
|
||||
// a bitset with 1s at block boundary only
|
||||
const int num_blocks = 32;
|
||||
const int block_width = bitset_type::bits_per_block;
|
||||
|
||||
bitset_type b( num_blocks * block_width );
|
||||
typename bitset_type::size_type i = block_width - 1;
|
||||
for ( ; i < b.size(); i += block_width ) {
|
||||
b.set( i );
|
||||
typename bitset_type::size_type first_in_block = i - ( block_width - 1 );
|
||||
b.set( first_in_block );
|
||||
}
|
||||
|
||||
// check
|
||||
const typename bitset_type::size_type larger_than_size = 5 + b.size();
|
||||
for ( i = 0; i <= larger_than_size; ++i ) {
|
||||
Tests::find_pos( b, i );
|
||||
Tests::find_pos( b, i, false );
|
||||
}
|
||||
Tests::find_pos( b, b.npos );
|
||||
Tests::find_pos( b, b.npos, false );
|
||||
}
|
||||
{
|
||||
// bitset with alternate 1s and 0s
|
||||
const typename bitset_type::size_type sz = 1000;
|
||||
bitset_type b( sz );
|
||||
|
||||
typename bitset_type::size_type i = 0;
|
||||
for ( ; i < sz; ++i ) {
|
||||
b[ i ] = ( i % 2 == 0 );
|
||||
}
|
||||
|
||||
// check
|
||||
const typename bitset_type::size_type larger_than_size = 5 + b.size();
|
||||
for ( i = 0; i <= larger_than_size; ++i ) {
|
||||
Tests::find_pos( b, i );
|
||||
Tests::find_pos( b, i, false );
|
||||
}
|
||||
Tests::find_pos( b, b.npos );
|
||||
Tests::find_pos( b, b.npos, false );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator==
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::operator_equal( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
|
||||
Tests::operator_equal( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
|
||||
Tests::operator_equal( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
Tests::operator_equal( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
a[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_equal( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
b[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_equal( a, b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator!=
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::operator_not_equal( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
|
||||
Tests::operator_not_equal( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
|
||||
Tests::operator_not_equal( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
Tests::operator_not_equal( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
a[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_not_equal( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
b[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_not_equal( a, b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator<
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::operator_less_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a;
|
||||
bitset_type b( std::string( "1" ) );
|
||||
Tests::operator_less_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
|
||||
Tests::operator_less_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
|
||||
Tests::operator_less_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "10" ) ), b( std::string( "11" ) );
|
||||
Tests::operator_less_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "101" ) ), b( std::string( "11" ) );
|
||||
Tests::operator_less_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "10" ) ), b( std::string( "111" ) );
|
||||
Tests::operator_less_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "11" ) ), b( std::string( "111" ) );
|
||||
Tests::operator_less_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
Tests::operator_less_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
a[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_less_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
b[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_less_than( a, b );
|
||||
}
|
||||
// check for consistency with ulong behaviour when the sizes are equal
|
||||
{
|
||||
bitset_type a( 3, 4ul ), b( 3, 5ul );
|
||||
BOOST_TEST( a < b );
|
||||
}
|
||||
{
|
||||
bitset_type a( 3, 4ul ), b( 3, 4ul );
|
||||
BOOST_TEST( ! ( a < b ) );
|
||||
}
|
||||
{
|
||||
bitset_type a( 3, 5ul ), b( 3, 4ul );
|
||||
BOOST_TEST( ! ( a < b ) );
|
||||
}
|
||||
// when the sizes are not equal lexicographic compare does not necessarily correspond to ulong behavior
|
||||
{
|
||||
bitset_type a( 4, 4ul ), b( 3, 5ul );
|
||||
BOOST_TEST( a < b );
|
||||
}
|
||||
{
|
||||
bitset_type a( 3, 4ul ), b( 4, 5ul );
|
||||
BOOST_TEST( ! ( a < b ) );
|
||||
}
|
||||
{
|
||||
bitset_type a( 4, 4ul ), b( 3, 4ul );
|
||||
BOOST_TEST( a < b );
|
||||
}
|
||||
{
|
||||
bitset_type a( 3, 4ul ), b( 4, 4ul );
|
||||
BOOST_TEST( ! ( a < b ) );
|
||||
}
|
||||
{
|
||||
bitset_type a( 4, 5ul ), b( 3, 4ul );
|
||||
BOOST_TEST( a < b );
|
||||
}
|
||||
{
|
||||
bitset_type a( 3, 5ul ), b( 4, 4ul );
|
||||
BOOST_TEST( ! ( a < b ) );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator<=
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::operator_less_than_eq( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
|
||||
Tests::operator_less_than_eq( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
|
||||
Tests::operator_less_than_eq( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
Tests::operator_less_than_eq( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
a[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_less_than_eq( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
b[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_less_than_eq( a, b );
|
||||
}
|
||||
// check for consistency with ulong behaviour
|
||||
{
|
||||
bitset_type a( 3, 4ul ), b( 3, 5ul );
|
||||
BOOST_TEST( a <= b );
|
||||
}
|
||||
{
|
||||
bitset_type a( 3, 4ul ), b( 3, 4ul );
|
||||
BOOST_TEST( a <= b );
|
||||
}
|
||||
{
|
||||
bitset_type a( 3, 5ul ), b( 3, 4ul );
|
||||
BOOST_TEST( ! ( a <= b ) );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator>
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::operator_greater_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
|
||||
Tests::operator_greater_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
|
||||
Tests::operator_greater_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
Tests::operator_greater_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
a[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_greater_than( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
b[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_greater_than( a, b );
|
||||
}
|
||||
// check for consistency with ulong behaviour
|
||||
{
|
||||
bitset_type a( 3, 4ul ), b( 3, 5ul );
|
||||
BOOST_TEST( ! ( a > b ) );
|
||||
}
|
||||
{
|
||||
bitset_type a( 3, 4ul ), b( 3, 4ul );
|
||||
BOOST_TEST( ! ( a > b ) );
|
||||
}
|
||||
{
|
||||
bitset_type a( 3, 5ul ), b( 3, 4ul );
|
||||
BOOST_TEST( a > b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator<=
|
||||
{
|
||||
bitset_type a, b;
|
||||
Tests::operator_greater_than_eq( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "0" ) ), b( std::string( "0" ) );
|
||||
Tests::operator_greater_than_eq( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( std::string( "1" ) ), b( std::string( "1" ) );
|
||||
Tests::operator_greater_than_eq( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
Tests::operator_greater_than_eq( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
a[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_greater_than_eq( a, b );
|
||||
}
|
||||
{
|
||||
bitset_type a( long_string ), b( long_string );
|
||||
b[ long_string.size() / 2 ].flip();
|
||||
Tests::operator_greater_than_eq( a, b );
|
||||
}
|
||||
// check for consistency with ulong behaviour
|
||||
{
|
||||
bitset_type a( 3, 4ul ), b( 3, 5ul );
|
||||
BOOST_TEST( ! ( a >= b ) );
|
||||
}
|
||||
{
|
||||
bitset_type a( 3, 4ul ), b( 3, 4ul );
|
||||
BOOST_TEST( a >= b );
|
||||
}
|
||||
{
|
||||
bitset_type a( 3, 5ul ), b( 3, 4ul );
|
||||
BOOST_TEST( a >= b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.test(pos)
|
||||
{ // case pos >= b.size()
|
||||
bitset_type b;
|
||||
Tests::test_bit( b, 0 );
|
||||
}
|
||||
{ // case pos < b.size()
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::test_bit( b, 0 );
|
||||
}
|
||||
{ // case pos == b.size() / 2
|
||||
bitset_type b( long_string );
|
||||
Tests::test_bit( b, long_string.size() / 2 );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.test_set(pos)
|
||||
{ // case pos >= b.size()
|
||||
bitset_type b;
|
||||
Tests::test_set_bit( b, 0, true );
|
||||
Tests::test_set_bit( b, 0, false );
|
||||
}
|
||||
{ // case pos < b.size()
|
||||
bitset_type b( std::string( "0" ) );
|
||||
Tests::test_set_bit( b, 0, true );
|
||||
Tests::test_set_bit( b, 0, false );
|
||||
}
|
||||
{ // case pos == b.size() / 2
|
||||
bitset_type b( long_string );
|
||||
Tests::test_set_bit( b, long_string.size() / 2, true );
|
||||
Tests::test_set_bit( b, long_string.size() / 2, false );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b << pos
|
||||
{ // case pos == 0
|
||||
std::size_t pos = 0;
|
||||
bitset_type b( std::string( "1010" ) );
|
||||
Tests::operator_shift_left( b, pos );
|
||||
}
|
||||
{ // case pos == size()/2
|
||||
std::size_t pos = long_string.size() / 2;
|
||||
bitset_type b( long_string );
|
||||
Tests::operator_shift_left( b, pos );
|
||||
}
|
||||
{ // case pos >= n
|
||||
std::size_t pos = long_string.size();
|
||||
bitset_type b( long_string );
|
||||
Tests::operator_shift_left( b, pos );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b >> pos
|
||||
{ // case pos == 0
|
||||
std::size_t pos = 0;
|
||||
bitset_type b( std::string( "1010" ) );
|
||||
Tests::operator_shift_right( b, pos );
|
||||
}
|
||||
{ // case pos == size()/2
|
||||
std::size_t pos = long_string.size() / 2;
|
||||
bitset_type b( long_string );
|
||||
Tests::operator_shift_right( b, pos );
|
||||
}
|
||||
{ // case pos >= n
|
||||
std::size_t pos = long_string.size();
|
||||
bitset_type b( long_string );
|
||||
Tests::operator_shift_right( b, pos );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a & b
|
||||
{
|
||||
bitset_type lhs, rhs;
|
||||
Tests::operator_and( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
|
||||
Tests::operator_and( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
|
||||
Tests::operator_and( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
|
||||
Tests::operator_and( lhs, rhs );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a | b
|
||||
{
|
||||
bitset_type lhs, rhs;
|
||||
Tests::operator_or( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
|
||||
Tests::operator_or( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
|
||||
Tests::operator_or( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
|
||||
Tests::operator_or( lhs, rhs );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a^b
|
||||
{
|
||||
bitset_type lhs, rhs;
|
||||
Tests::operator_xor( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
|
||||
Tests::operator_xor( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
|
||||
Tests::operator_xor( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
|
||||
Tests::operator_xor( lhs, rhs );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a-b
|
||||
{
|
||||
bitset_type lhs, rhs;
|
||||
Tests::operator_sub( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( std::string( "1" ) ), rhs( std::string( "0" ) );
|
||||
Tests::operator_sub( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 0 ), rhs( long_string );
|
||||
Tests::operator_sub( lhs, rhs );
|
||||
}
|
||||
{
|
||||
bitset_type lhs( long_string.size(), 1 ), rhs( long_string );
|
||||
Tests::operator_sub( lhs, rhs );
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
run_test_cases< unsigned char >();
|
||||
run_test_cases< unsigned char, small_vector< unsigned char > >();
|
||||
run_test_cases< unsigned short >();
|
||||
run_test_cases< unsigned short, small_vector< unsigned short > >();
|
||||
run_test_cases< unsigned int >();
|
||||
run_test_cases< unsigned int, small_vector< unsigned int > >();
|
||||
run_test_cases< unsigned long >();
|
||||
run_test_cases< unsigned long, small_vector< unsigned long > >();
|
||||
run_test_cases< unsigned long long >();
|
||||
run_test_cases< unsigned long long, small_vector< unsigned long long > >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,313 +0,0 @@
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006, 2025 Gennaro Prota
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include <assert.h>
|
||||
#include <cstddef>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#if ! defined( BOOST_NO_STRINGSTREAM )
|
||||
# include <sstream>
|
||||
#endif
|
||||
|
||||
#if defined BOOST_NO_STD_WSTRING
|
||||
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
|
||||
#endif
|
||||
|
||||
#if ! defined BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
|
||||
std::wstring
|
||||
widen_string( const std::string & str, const std::locale & loc = std::locale() )
|
||||
{
|
||||
std::wstring result;
|
||||
const std::string::size_type len = str.length();
|
||||
if ( len != 0 ) {
|
||||
typedef std::ctype< wchar_t > ct_type;
|
||||
typedef std::wstring::traits_type tr_type;
|
||||
const ct_type & ct = std::use_facet< ct_type >( loc );
|
||||
|
||||
result.resize( len );
|
||||
for ( std::size_t i = 0; i < len; ++i )
|
||||
tr_type::assign( result[ i ], ct.widen( str[ i ] ) );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
template< typename Block, typename AllocatorOrContainer = std::allocator< Block > >
|
||||
void
|
||||
run_test_cases()
|
||||
{
|
||||
typedef boost::dynamic_bitset< Block, AllocatorOrContainer > bitset_type;
|
||||
typedef bitset_test< bitset_type > Tests;
|
||||
|
||||
//=====================================================================
|
||||
// Test stream operator<<
|
||||
{
|
||||
// The test "variables" are: the stream type and its state, the
|
||||
// exception mask, the width, the fill char and the padding side (left/right)
|
||||
|
||||
std::ios::iostate masks[] = {
|
||||
std::ios::goodbit,
|
||||
std::ios::eofbit,
|
||||
std::ios::failbit,
|
||||
std::ios::eofbit | std::ios::failbit
|
||||
};
|
||||
|
||||
static std::string strings[] = {
|
||||
std::string( "" ),
|
||||
std::string( "0" ),
|
||||
std::string( "1" ),
|
||||
std::string( "11100" ),
|
||||
get_long_string()
|
||||
};
|
||||
|
||||
char fill_chars[] = { '*', 'x', ' ' };
|
||||
|
||||
std::size_t num_masks = sizeof( masks ) / sizeof( masks[ 0 ] );
|
||||
std::size_t num_strings = sizeof( strings ) / sizeof( strings[ 0 ] );
|
||||
std::size_t num_chars = sizeof( fill_chars ) / sizeof( fill_chars[ 0 ] );
|
||||
|
||||
std::fstream not_good_stream( "dynamic_bitset_tests - this file shouldn't exist", std::ios::in );
|
||||
|
||||
for ( std::size_t mi = 0; mi < num_masks; ++mi ) {
|
||||
for ( std::size_t si = 0; si < num_strings; ++si ) {
|
||||
std::streamsize slen = (std::streamsize)( strings[ si ].length() );
|
||||
|
||||
assert( ( std::numeric_limits< std::streamsize >::max )() >= (std::streamsize)( 1 + slen * 2 ) );
|
||||
|
||||
for ( std::size_t ci = 0; ci < num_chars; ++ci ) {
|
||||
// note how "negative widths" are tested too
|
||||
const std::streamsize widths[] = { -1 - slen / 2, 0, slen / 2, 1 + slen * 2 };
|
||||
std::size_t num_widths = sizeof( widths ) / sizeof( widths[ 0 ] );
|
||||
|
||||
for ( std::size_t wi = 0; wi < num_widths; ++wi ) {
|
||||
std::streamsize w = widths[ wi ];
|
||||
{
|
||||
// test 0 - stream !good()
|
||||
if ( not_good_stream.good() )
|
||||
throw std::logic_error( "Error in operator << tests"
|
||||
" - please, double check" );
|
||||
bitset_type b( strings[ si ] );
|
||||
not_good_stream.width( w );
|
||||
not_good_stream.fill( fill_chars[ ci ] );
|
||||
try {
|
||||
not_good_stream.exceptions( masks[ mi ] );
|
||||
} catch ( ... ) {
|
||||
}
|
||||
|
||||
Tests::stream_inserter( b, not_good_stream, "<unused_string>" );
|
||||
}
|
||||
{
|
||||
// test 1a - file stream
|
||||
scoped_temp_file stf;
|
||||
bitset_type b( strings[ si ] );
|
||||
std::ofstream file( stf.path().string().c_str(), std::ios::trunc );
|
||||
file.width( w );
|
||||
file.fill( fill_chars[ ci ] );
|
||||
file.exceptions( masks[ mi ] );
|
||||
Tests::stream_inserter( b, file, stf.path().string().c_str() );
|
||||
}
|
||||
{
|
||||
// NOTE: there are NO string stream tests
|
||||
}
|
||||
#if ! defined( BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS )
|
||||
{
|
||||
// test 1b - wide file stream
|
||||
scoped_temp_file stf;
|
||||
bitset_type b( strings[ si ] );
|
||||
std::wofstream file( stf.path().string().c_str() );
|
||||
file.width( w );
|
||||
file.fill( fill_chars[ ci ] );
|
||||
file.exceptions( masks[ mi ] );
|
||||
Tests::stream_inserter( b, file, stf.path().string().c_str() );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
} // for (; mi..)
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
// Test stream operator>>
|
||||
{
|
||||
// The test "variables" are: the stream type, the exception mask,
|
||||
// the actual contents (and/or state) of the stream, and width.
|
||||
//
|
||||
// With few exceptions, each test case consists of writing a different
|
||||
// assortment of digits and "whitespaces" to a text stream and then checking
|
||||
// that what was written gets read back unchanged. That's NOT guaranteed by
|
||||
// the standard, unless the assortment always ends with a '\n' and satisfies
|
||||
// other conditions (see C99, 7.19.2/2), however it works in practice and is
|
||||
// a good "real life" test. Some characters, such as '\v' and '\f', are not
|
||||
// used exactly because they are the ones which will most likely give problems
|
||||
// on some systems (for instance '\f' could actually be written as a sequence
|
||||
// of new-lines, and we could never be able to read it back)
|
||||
//
|
||||
// Note how the bitset object is not initially empty. That helps checking
|
||||
// that it isn't erroneously clear()ed by operator>>.
|
||||
|
||||
std::ios::iostate masks[] = {
|
||||
std::ios::goodbit,
|
||||
std::ios::eofbit,
|
||||
std::ios::failbit,
|
||||
std::ios::eofbit | std::ios::failbit
|
||||
};
|
||||
|
||||
const std::string spaces = "\t\n "; //"\t\n\v\f ";
|
||||
|
||||
const std::string long_string = get_long_string();
|
||||
const static std::string strings[] = {
|
||||
|
||||
// empty string
|
||||
std::string( "" ),
|
||||
// no bitset
|
||||
spaces,
|
||||
|
||||
// no bitset
|
||||
std::string( "x" ),
|
||||
std::string( "\t xyz" ),
|
||||
|
||||
// bitset of size 1
|
||||
std::string( "0" ),
|
||||
std::string( "1" ),
|
||||
|
||||
std::string( " 0 " ),
|
||||
std::string( " 1 " ),
|
||||
spaces + "1",
|
||||
"1" + spaces,
|
||||
spaces + "1" + spaces,
|
||||
std::string( " x1x " ),
|
||||
std::string( " 1x " ),
|
||||
|
||||
// long bitset
|
||||
long_string,
|
||||
" " + long_string + " xyz",
|
||||
spaces + long_string,
|
||||
spaces + long_string + spaces
|
||||
};
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
||||
std::stringstream not_good_stream;
|
||||
not_good_stream << "test";
|
||||
std::string sink;
|
||||
not_good_stream >> sink; // now the stream should be in eof state
|
||||
|
||||
const std::size_t num_masks = sizeof( masks ) / sizeof( masks[ 0 ] );
|
||||
const std::size_t num_strings = sizeof( strings ) / sizeof( strings[ 0 ] );
|
||||
|
||||
for ( std::size_t mi = 0; mi < num_masks; ++mi ) {
|
||||
for ( std::size_t si = 0; si < num_strings; ++si ) {
|
||||
const std::streamsize slen = (std::streamsize)( strings[ si ].length() );
|
||||
assert( ( std::numeric_limits< std::streamsize >::max )() >= (std::streamsize)( 1 + slen * 2 ) );
|
||||
|
||||
std::streamsize widths[] = { -1, 0, slen / 2, slen, 1 + slen * 2 };
|
||||
std::size_t num_widths = sizeof( widths ) / sizeof( widths[ 0 ] );
|
||||
|
||||
for ( std::size_t wi = 0; wi < num_widths; ++wi ) {
|
||||
const std::streamsize w = widths[ wi ];
|
||||
|
||||
// test 0 - !good() stream
|
||||
{
|
||||
if ( not_good_stream.good() )
|
||||
throw std::logic_error( "Error in operator >> tests"
|
||||
" - please, double check" );
|
||||
bitset_type b( 1, 15ul ); // note: b is not empty
|
||||
not_good_stream.width( w );
|
||||
try {
|
||||
not_good_stream.exceptions( masks[ mi ] );
|
||||
} catch ( ... ) {
|
||||
}
|
||||
std::string irrelevant;
|
||||
Tests::stream_extractor( b, not_good_stream, irrelevant );
|
||||
}
|
||||
// test 1a - (narrow) file stream
|
||||
{
|
||||
scoped_temp_file stf;
|
||||
bitset_type b( 1, 255ul );
|
||||
{
|
||||
std::ofstream f( stf.path().string().c_str() );
|
||||
f << strings[ si ];
|
||||
}
|
||||
|
||||
std::ifstream f( stf.path().string().c_str() );
|
||||
f.width( w );
|
||||
f.exceptions( masks[ mi ] );
|
||||
Tests::stream_extractor( b, f, strings[ si ] );
|
||||
}
|
||||
#if ! defined( BOOST_NO_STRINGSTREAM )
|
||||
// test 2a - stringstream
|
||||
{
|
||||
bitset_type b( 1, 255ul );
|
||||
std::istringstream stream( strings[ si ] );
|
||||
stream.width( w );
|
||||
stream.exceptions( masks[ mi ] );
|
||||
Tests::stream_extractor( b, stream, strings[ si ] );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ! defined( BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS )
|
||||
// test 1b - wchar_t file stream
|
||||
{
|
||||
scoped_temp_file stf;
|
||||
std::wstring wstr = widen_string( strings[ si ] );
|
||||
bitset_type b( 1, 255ul );
|
||||
{
|
||||
std::basic_ofstream< wchar_t > of( stf.path().string().c_str() );
|
||||
of << wstr;
|
||||
}
|
||||
|
||||
std::basic_ifstream< wchar_t > f( stf.path().string().c_str() );
|
||||
f.width( w );
|
||||
f.exceptions( masks[ mi ] );
|
||||
Tests::stream_extractor( b, f, wstr );
|
||||
}
|
||||
// test 2b - wstringstream
|
||||
{
|
||||
bitset_type b( 1, 255ul );
|
||||
std::wstring wstr = widen_string( strings[ si ] );
|
||||
|
||||
std::wistringstream wstream( wstr );
|
||||
wstream.width( w );
|
||||
wstream.exceptions( masks[ mi ] );
|
||||
Tests::stream_extractor( b, wstream, wstr );
|
||||
}
|
||||
#endif // BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
|
||||
}
|
||||
}
|
||||
|
||||
} // for ( mi = 0; ...)
|
||||
}
|
||||
//=====================================================================
|
||||
// << Any other tests go here >>
|
||||
// .....
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
run_test_cases< unsigned char >();
|
||||
run_test_cases< unsigned char, small_vector< unsigned char > >();
|
||||
run_test_cases< unsigned short >();
|
||||
run_test_cases< unsigned short, small_vector< unsigned short > >();
|
||||
run_test_cases< unsigned int >();
|
||||
run_test_cases< unsigned int, small_vector< unsigned int > >();
|
||||
run_test_cases< unsigned long >();
|
||||
run_test_cases< unsigned long, small_vector< unsigned long > >();
|
||||
run_test_cases< unsigned long long >();
|
||||
run_test_cases< unsigned long long, small_vector< unsigned long long > >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006, 2025 Gennaro Prota
|
||||
//
|
||||
// Copyright (c) 2015 Seth Heeren
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
#include "boost/archive/binary_iarchive.hpp"
|
||||
#include "boost/archive/binary_oarchive.hpp"
|
||||
#include "boost/archive/xml_iarchive.hpp"
|
||||
#include "boost/archive/xml_oarchive.hpp"
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/dynamic_bitset/serialization.hpp"
|
||||
#include "boost/serialization/vector.hpp"
|
||||
|
||||
#if ! defined( BOOST_NO_STRINGSTREAM )
|
||||
# include <sstream>
|
||||
#endif
|
||||
|
||||
#if defined BOOST_NO_STD_WSTRING
|
||||
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
template< typename Block >
|
||||
struct SerializableType
|
||||
{
|
||||
boost::dynamic_bitset< Block > x;
|
||||
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
template< class Archive >
|
||||
void
|
||||
serialize( Archive & ar, unsigned int )
|
||||
{
|
||||
ar & BOOST_SERIALIZATION_NVP( x );
|
||||
}
|
||||
};
|
||||
|
||||
template< typename Block, typename IArchive, typename OArchive >
|
||||
void
|
||||
test_serialization()
|
||||
{
|
||||
SerializableType< Block > a;
|
||||
|
||||
for ( int i = 0; i < 128; ++i )
|
||||
a.x.resize( 11 * i, i % 2 );
|
||||
|
||||
#if ! defined( BOOST_NO_STRINGSTREAM )
|
||||
std::stringstream ss;
|
||||
|
||||
// test serialization
|
||||
{
|
||||
OArchive oa( ss );
|
||||
oa << BOOST_SERIALIZATION_NVP( a );
|
||||
}
|
||||
|
||||
// test de-serialization
|
||||
{
|
||||
IArchive ia( ss );
|
||||
SerializableType< Block > b;
|
||||
ia >> BOOST_SERIALIZATION_NVP( b );
|
||||
|
||||
BOOST_TEST( a.x == b.x );
|
||||
}
|
||||
#else
|
||||
# error "TODO implement file-based test path?"
|
||||
#endif
|
||||
}
|
||||
|
||||
template< typename Block >
|
||||
void
|
||||
test_binary_archive()
|
||||
{
|
||||
test_serialization< Block, boost::archive::binary_iarchive, boost::archive::binary_oarchive >();
|
||||
}
|
||||
|
||||
template< typename Block >
|
||||
void
|
||||
test_xml_archive()
|
||||
{
|
||||
test_serialization< Block, boost::archive::xml_iarchive, boost::archive::xml_oarchive >();
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Block >
|
||||
void
|
||||
run_test_cases()
|
||||
{
|
||||
test_binary_archive< Block >();
|
||||
test_xml_archive< Block >();
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
run_test_cases< unsigned char >();
|
||||
run_test_cases< unsigned short >();
|
||||
run_test_cases< unsigned int >();
|
||||
run_test_cases< unsigned long >();
|
||||
run_test_cases< unsigned long long >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
//
|
||||
// Copyright (C) 2018 James E. King III
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
|
||||
int
|
||||
main( int, char *[] )
|
||||
{
|
||||
boost::dynamic_bitset<> x( 5 ); // all 0's by default
|
||||
x.set( 1, 2 );
|
||||
x.set( 3, 1, true );
|
||||
x.set( 2, 1, false );
|
||||
BOOST_TEST( ! x.test( 0 ) );
|
||||
BOOST_TEST( x.test( 1 ) );
|
||||
BOOST_TEST( ! x.test( 2 ) );
|
||||
BOOST_TEST( x.test( 3 ) );
|
||||
BOOST_TEST( ! x.test( 4 ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
//
|
||||
// Copyright (C) 2019 James E. King III
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include <set>
|
||||
|
||||
int
|
||||
main( int, char *[] )
|
||||
{
|
||||
typedef boost::dynamic_bitset< unsigned long > bitset_type;
|
||||
const std::string long_string =
|
||||
"01001110101110110101011010000000000011110101101111111111";
|
||||
const std::string long_string_prime_begin =
|
||||
"11001110101110110101011010000000000011110101101111111111";
|
||||
const std::string long_string_prime_end =
|
||||
"01001110101110110101011010000000000011110101101111111110";
|
||||
|
||||
bitset_type zeroes( long_string.size(), 0 );
|
||||
bitset_type stuff( long_string );
|
||||
bitset_type stupb( long_string_prime_begin );
|
||||
bitset_type stupe( long_string_prime_end );
|
||||
bitset_type ones( long_string.size(), 1 );
|
||||
|
||||
boost::hash< bitset_type > bitset_hasher;
|
||||
std::set< std::size_t > results;
|
||||
results.insert( bitset_hasher( zeroes ) );
|
||||
results.insert( bitset_hasher( stuff ) );
|
||||
results.insert( bitset_hasher( stupb ) );
|
||||
results.insert( bitset_hasher( stupe ) );
|
||||
results.insert( bitset_hasher( ones ) );
|
||||
|
||||
// if any hash is identical to another there will be less than 5
|
||||
BOOST_TEST_EQ( results.size(), 5 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
//
|
||||
// Copyright (C) 2018 James E. King III
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
#include "boost/cstdint.hpp"
|
||||
#include "boost/dynamic_bitset/detail/lowest_bit.hpp"
|
||||
|
||||
int
|
||||
main( int, char *[] )
|
||||
{
|
||||
for ( boost::int32_t i = 1; i < 32; ++i ) {
|
||||
BOOST_TEST_EQ( i, boost::detail::lowest_bit( 1u << i ) );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( 2, boost::detail::lowest_bit( 123456788 ) );
|
||||
BOOST_TEST_EQ( 30, boost::detail::lowest_bit( static_cast< boost::int64_t >( 1507208177123328 ) ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// Copyright (C) 2019 James E. King III
|
||||
// Copyright (C) 2025 Gennaro Prota
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include <unordered_set>
|
||||
|
||||
int
|
||||
main( int, char *[] )
|
||||
{
|
||||
typedef boost::dynamic_bitset< unsigned long > bitset_type;
|
||||
const std::string long_string =
|
||||
"01001110101110110101011010000000000011110101101111111111";
|
||||
|
||||
// Some bitsets with the same size but different underlying vectors.
|
||||
const bitset_type zeroes( long_string.size(), 0 );
|
||||
const bitset_type stuff( long_string );
|
||||
const bitset_type one( long_string.size(), 1 );
|
||||
|
||||
// Some bitsets with different sizes but equal underlying vectors.
|
||||
const bitset_type zeroes2( 2, 0 );
|
||||
const bitset_type zeroes3( 3, 0 );
|
||||
|
||||
std::unordered_set< bitset_type > bitsets;
|
||||
bitsets.insert( zeroes );
|
||||
bitsets.insert( stuff );
|
||||
bitsets.insert( one );
|
||||
bitsets.insert( zeroes2 );
|
||||
bitsets.insert( zeroes3 );
|
||||
|
||||
BOOST_TEST_EQ( bitsets.size(), 5 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
101
timing_tests.cpp
Normal file
101
timing_tests.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
// boost::dynamic_bitset timing test ---------------------------------------//
|
||||
|
||||
// (C) Copyright Gennaro Prota 2002.
|
||||
// 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.
|
||||
|
||||
|
||||
|
||||
//****************************************************************************//
|
||||
|
||||
// WARNING:
|
||||
// ~~~~~~~
|
||||
// This is a preliminary version, for internal testing only.
|
||||
// For now, it stresses the count() function only and has been executed
|
||||
// on a very few platforms. The previous version, for instance, was never
|
||||
// executed on MSVC (boost::bitset<> didn't even compile with it) and at
|
||||
// the first try it crashed at startup, presumably because of a linker bug.
|
||||
// To cope with it, the definition of
|
||||
//
|
||||
// template <typename T> void timing_test()
|
||||
//
|
||||
// has been moved before the definition of main()
|
||||
//
|
||||
// LAST MODIFIED: 2 Aug 2002
|
||||
//****************************************************************************//
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
#include <iomanip>
|
||||
|
||||
#include "boost/timer.hpp"
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include "boost/cstdlib.hpp"
|
||||
|
||||
|
||||
|
||||
void prologue()
|
||||
{
|
||||
std::cout << "Compiler: " << BOOST_COMPILER << '\n';
|
||||
std::cout << "STLPort used? ";
|
||||
# ifdef _STLPORT_VERSION
|
||||
std::cout << "Yes, v." << std::hex << _STLPORT_VERSION;
|
||||
# else
|
||||
std::cout << "No.";
|
||||
# endif
|
||||
std::cout << std::dec << "\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
void timing_test()
|
||||
{
|
||||
const unsigned long num = 10000;
|
||||
|
||||
std::size_t dummy = 0; // this is printed at the end of the test,
|
||||
// to prevent the optimizer to eliminate
|
||||
// the call to count() in the loop below :-)
|
||||
|
||||
|
||||
std::cout << "\n\nTimings for dynamic_bitset<" << typeid(T).name()
|
||||
<< "> [" << num << " iterations]\n";
|
||||
std::cout << "--------------------------------------------------\n";
|
||||
|
||||
{ // new implementation
|
||||
boost::timer time;
|
||||
|
||||
for (unsigned long i=0; i<num; ++i) {
|
||||
boost::dynamic_bitset<T> bs(std::size_t(5000), i);
|
||||
dummy += bs.count();
|
||||
}
|
||||
const double elaps = time.elapsed();
|
||||
std::cout << "Elapsed: " << elaps << '\n';
|
||||
}
|
||||
|
||||
std::cout << "(total count: " << dummy << ")\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
prologue();
|
||||
|
||||
timing_test<unsigned short>();
|
||||
timing_test<unsigned int>();
|
||||
timing_test<unsigned long>();
|
||||
# ifdef BOOST_HAS_LONG_LONG
|
||||
timing_test<unsigned long long>();
|
||||
# endif
|
||||
|
||||
return boost::exit_success;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user