forked from boostorg/core
Compare commits
50 Commits
feature/se
...
boost-1.83
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7134904e2 | ||
|
|
216999e552 | ||
|
|
66890c3f3d | ||
|
|
8d6d20059a | ||
|
|
ee596e3d37 | ||
|
|
de8fe4fad7 | ||
|
|
d4db3eccec | ||
|
|
3b96d237c0 | ||
|
|
0e71b6158d | ||
|
|
23ef6d3531 | ||
|
|
e088fb8929 | ||
|
|
57151ab82e | ||
|
|
992326b1c8 | ||
|
|
4e769d1cdd | ||
|
|
bf17035a2d | ||
|
|
5a3b4df5de | ||
|
|
85527c4045 | ||
|
|
7ab05d5de0 | ||
|
|
266fbe6449 | ||
|
|
fd0de5f538 | ||
|
|
350526f7c7 | ||
|
|
06fef712c9 | ||
|
|
b7f7eb4f90 | ||
|
|
f41b8f38c4 | ||
|
|
b591214103 | ||
|
|
6b9f0cbf57 | ||
|
|
ecee9257d5 | ||
|
|
6c7edac9b1 | ||
|
|
049d3447ca | ||
|
|
b2fe98edf8 | ||
|
|
42c8898d24 | ||
|
|
f2eab6d6ff | ||
|
|
36fa78f53c | ||
|
|
97606908b7 | ||
|
|
5eb54d1d36 | ||
|
|
c91f8fabff | ||
|
|
5904fb5636 | ||
|
|
39978bde2b | ||
|
|
d5fa9ae50f | ||
|
|
2814b4ca1c | ||
|
|
c4e420f69d | ||
|
|
94628cb2f9 | ||
|
|
19f9aa93e1 | ||
|
|
2691efd1ca | ||
|
|
b6b1498275 | ||
|
|
379899ef15 | ||
|
|
3ab949d321 | ||
|
|
dbf0ea98b9 | ||
|
|
5afc91d52d | ||
|
|
f2a1532105 |
@@ -334,6 +334,14 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
["deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main"],
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 16",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-16', CXXSTD: '03,11,14,17,20,2b' },
|
||||
"clang-16",
|
||||
["deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main"],
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 UBSAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + ubsan,
|
||||
@@ -344,27 +352,39 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + asan,
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 12.4 Xcode 13.4.1 UBSAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,17,20,2b' } + ubsan,
|
||||
xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64",
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 12.4 Xcode 13.4.1 ASAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,17,20,2b' } + asan,
|
||||
xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64",
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2015 msvc-14.0",
|
||||
"cppalliance/dronevs2015",
|
||||
{ TOOLSET: 'msvc-14.0', CXXSTD: '14,latest' },
|
||||
{ TOOLSET: 'msvc-14.0', CXXSTD: '14,latest', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2017 msvc-14.1",
|
||||
"cppalliance/dronevs2017",
|
||||
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest' },
|
||||
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2019 msvc-14.2",
|
||||
"cppalliance/dronevs2019",
|
||||
{ TOOLSET: 'msvc-14.2', CXXSTD: '14,17,20,latest' },
|
||||
{ TOOLSET: 'msvc-14.2', CXXSTD: '14,17,20,latest', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2022 msvc-14.3",
|
||||
"cppalliance/dronevs2022:1",
|
||||
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17,20,latest' },
|
||||
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17,20,latest', ADDRMD: '32,64' },
|
||||
),
|
||||
]
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
set -ex
|
||||
export PATH=~/.local/bin:/usr/local/bin:$PATH
|
||||
|
||||
DRONE_BUILD_DIR=$(pwd)
|
||||
|
||||
|
||||
206
.github/workflows/ci.yml
vendored
206
.github/workflows/ci.yml
vendored
@@ -245,10 +245,6 @@ jobs:
|
||||
os: ubuntu-22.04
|
||||
install:
|
||||
- clang-15
|
||||
sources:
|
||||
- "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main"
|
||||
source_keys:
|
||||
- "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
- toolset: clang
|
||||
compiler: clang++-15
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
@@ -257,24 +253,34 @@ jobs:
|
||||
- clang-15
|
||||
- libc++-15-dev
|
||||
- libc++abi-15-dev
|
||||
cxxflags: -stdlib=libc++
|
||||
linkflags: -stdlib=libc++
|
||||
- toolset: clang
|
||||
compiler: clang++-16
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install:
|
||||
- clang-16
|
||||
- libc++-16-dev
|
||||
- libc++abi-16-dev
|
||||
sources:
|
||||
- "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main"
|
||||
- "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main"
|
||||
source_keys:
|
||||
- "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
cxxflags: -stdlib=libc++
|
||||
linkflags: -stdlib=libc++
|
||||
- name: UBSAN
|
||||
toolset: clang
|
||||
compiler: clang++-14
|
||||
compiler: clang++-15
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
cxxflags: -stdlib=libc++
|
||||
linkflags: -stdlib=libc++
|
||||
ubsan: 1
|
||||
os: ubuntu-22.04
|
||||
install:
|
||||
- clang-14
|
||||
- libc++-14-dev
|
||||
- libc++abi-14-dev
|
||||
- clang-15
|
||||
- libc++-15-dev
|
||||
- libc++abi-15-dev
|
||||
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
@@ -466,7 +472,7 @@ jobs:
|
||||
if [ -n "${{matrix.ubsan}}" ]
|
||||
then
|
||||
export UBSAN_OPTIONS="print_stacktrace=1"
|
||||
B2_ARGS+=("cxxflags=-fsanitize=undefined -fno-sanitize-recover=undefined" "linkflags=-fsanitize=undefined -fuse-ld=gold" "define=UBSAN=1" "debug-symbols=on" "visibility=global")
|
||||
B2_ARGS+=("undefined-sanitizer=norecover" "linkflags=-fuse-ld=gold" "define=UBSAN=1" "debug-symbols=on" "visibility=global")
|
||||
fi
|
||||
if [ -n "${{matrix.cxxflags}}" ]
|
||||
then
|
||||
@@ -700,3 +706,183 @@ jobs:
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
ctest --output-on-failure --no-tests=error
|
||||
|
||||
windows-cmake-subdir:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
|
||||
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
|
||||
echo LIBRARY: %LIBRARY%
|
||||
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
|
||||
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
|
||||
echo GITHUB_REF: %GITHUB_REF%
|
||||
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
|
||||
set BOOST_BRANCH=develop
|
||||
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
|
||||
echo BOOST_BRANCH: %BOOST_BRANCH%
|
||||
cd ..
|
||||
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
|
||||
|
||||
- name: Use library with add_subdirectory (Debug)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test
|
||||
mkdir __build__ && cd __build__
|
||||
cmake ..
|
||||
cmake --build . --config Debug
|
||||
ctest --output-on-failure --no-tests=error -C Debug
|
||||
|
||||
- name: Use library with add_subdirectory (Release)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test/__build__
|
||||
cmake --build . --config Release
|
||||
ctest --output-on-failure --no-tests=error -C Release
|
||||
|
||||
windows-cmake-install:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
|
||||
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
|
||||
echo LIBRARY: %LIBRARY%
|
||||
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
|
||||
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
|
||||
echo GITHUB_REF: %GITHUB_REF%
|
||||
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
|
||||
set BOOST_BRANCH=develop
|
||||
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
|
||||
echo BOOST_BRANCH: %BOOST_BRANCH%
|
||||
cd ..
|
||||
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
|
||||
|
||||
- name: Configure
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root
|
||||
mkdir __build__ && cd __build__
|
||||
cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
|
||||
|
||||
- name: Install (Debug)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target install --config Debug
|
||||
|
||||
- name: Install (Release)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target install --config Release
|
||||
|
||||
- name: Use the installed library (Debug)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test && mkdir __build__ && cd __build__
|
||||
cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
|
||||
cmake --build . --config Debug
|
||||
ctest --output-on-failure --no-tests=error -C Debug
|
||||
|
||||
- name: Use the installed library (Release)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test/__build__
|
||||
cmake --build . --config Release
|
||||
ctest --output-on-failure --no-tests=error -C Release
|
||||
|
||||
windows-cmake-test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
|
||||
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
|
||||
echo LIBRARY: %LIBRARY%
|
||||
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
|
||||
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
|
||||
echo GITHUB_REF: %GITHUB_REF%
|
||||
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
|
||||
set BOOST_BRANCH=develop
|
||||
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
|
||||
echo BOOST_BRANCH: %BOOST_BRANCH%
|
||||
cd ..
|
||||
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
|
||||
|
||||
- name: Configure
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root
|
||||
mkdir __build__ && cd __build__
|
||||
cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DBUILD_TESTING=ON ..
|
||||
|
||||
- name: Build tests (Debug)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target tests --config Debug
|
||||
|
||||
- name: Run tests (Debug)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
ctest --output-on-failure --no-tests=error -C Debug
|
||||
|
||||
- name: Build tests (Release)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target tests --config Release
|
||||
|
||||
- name: Run tests (Release)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
ctest --output-on-failure --no-tests=error -C Release
|
||||
|
||||
16
doc/bit.qbk
16
doc/bit.qbk
@@ -33,6 +33,11 @@ namespace core
|
||||
template<class To, class From>
|
||||
To bit_cast(From const& from) noexcept;
|
||||
|
||||
// byteswap
|
||||
|
||||
template<class T>
|
||||
constexpr T byteswap(T x) noexcept;
|
||||
|
||||
// Integral powers of 2
|
||||
|
||||
template<class T>
|
||||
@@ -102,6 +107,17 @@ constant expression context.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section byteswap]
|
||||
|
||||
`template<class T> constexpr T byteswap(T x) noexcept;`
|
||||
|
||||
* *Requires:* `T` must be an integer type (i.e. one of `char`, `signed char`,
|
||||
`unsigned char`, `short`, `unsigned short`, `int`, `unsigned int`, `long`,
|
||||
`unsigned long`, `long long`, `unsigned long long`) without padding bits.
|
||||
* *Returns:* `x` with the storage bytes reversed.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Integral powers of 2]
|
||||
|
||||
`template<class T> constexpr bool has_single_bit(T x) noexcept;`
|
||||
|
||||
@@ -7,6 +7,18 @@
|
||||
|
||||
[section Revision History]
|
||||
|
||||
[section Changes in 1.83.0]
|
||||
|
||||
* Added support for incomplete types to [link core.type_name `boost::core::type_name`].
|
||||
* Bit manipulation functions in [link core.bit `boost/core/bit.hpp`] are now
|
||||
`constexpr` on recent MSVC versions (VS2019 update 5 and later.)
|
||||
* Added `boost::core::byteswap` (an implementation of `std::byteswap` from
|
||||
C++23) to [link core.bit `boost/core/bit.hpp`].
|
||||
* Moved the yield primitives `sp_thread_pause`, `sp_thread_yield`, `sp_thread_sleep`
|
||||
from SmartPtr implementation details to `boost/core/yield_primitives.hpp`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Changes in 1.82.0]
|
||||
|
||||
* Added [link core.snprintf `boost/core/snprintf.hpp`] header with portable definitions of `snprintf`, `vsnprintf` and
|
||||
@@ -22,6 +34,15 @@
|
||||
`boost::core::max_align`, the alignment of `max_align_t`.
|
||||
* Added [link core.memory_resource `boost::core::memory_resource`], a portable equivalent of `std::pmr::memory_resource`
|
||||
from C++17.
|
||||
* Added [link core.serialization `boost/core/serialization.hpp`], a collection of primitives allowing libraries to
|
||||
implement Boost.Serialization support for their types without including a Serialization header and thereby making
|
||||
their libraries depend on Serialization.
|
||||
* Added [link core.data `boost::data`], an implementation of `std::data`.
|
||||
* Added [link core.size `boost::size`], an implementation of `std::size`.
|
||||
* Updated `boost::span` to use `boost::data` which adds support for range
|
||||
construction from an `std::initializer_list`.
|
||||
* Added [link core.identity `boost::identity`], an implementation of
|
||||
`std::identity`. This facility has been moved from Boost.Functional.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ criteria for inclusion is that the utility component be:
|
||||
[include exchange.qbk]
|
||||
[include explicit_operator_bool.qbk]
|
||||
[include first_scalar.qbk]
|
||||
[include identity.qbk]
|
||||
[include ignore_unused.qbk]
|
||||
[include is_same.qbk]
|
||||
[include launder.qbk]
|
||||
@@ -72,6 +73,7 @@ criteria for inclusion is that the utility component be:
|
||||
[include quick_exit.qbk]
|
||||
[include ref.qbk]
|
||||
[include scoped_enum.qbk]
|
||||
[include serialization.qbk]
|
||||
[include size.qbk]
|
||||
[include span.qbk]
|
||||
[include swap.qbk]
|
||||
@@ -81,3 +83,4 @@ criteria for inclusion is that the utility component be:
|
||||
[include uncaught_exceptions.qbk]
|
||||
[include use_default.qbk]
|
||||
[include verbose_terminate_handler.qbk]
|
||||
[include yield_primitives.qbk]
|
||||
|
||||
@@ -50,10 +50,10 @@ data(std::initializer_list<T> l) noexcept;
|
||||
[variablelist
|
||||
[[`template<class C> constexpr auto data(C& c) noexcept(noexcept(c.data())) ->
|
||||
decltype(c.data());`]
|
||||
[Returns `c.begin()`.]]
|
||||
[Returns `c.data()`.]]
|
||||
[[`template<class C> constexpr auto data(const C& c)
|
||||
noexcept(noexcept(c.data())) -> decltype(c.data());`]
|
||||
[Returns `c.begin()`.]]
|
||||
[Returns `c.data()`.]]
|
||||
[[`template<class T, std::size_t N> constexpr T* data(T(&a)[N]) noexcept;`]
|
||||
[Returns `a`.]]
|
||||
[[`template<class T> constexpr const T* data(std::initializer_list<T> l)
|
||||
|
||||
61
doc/identity.qbk
Normal file
61
doc/identity.qbk
Normal file
@@ -0,0 +1,61 @@
|
||||
[/
|
||||
Copyright 2021-2023 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
]
|
||||
|
||||
[section:identity identity]
|
||||
|
||||
[simplesect Authors]
|
||||
|
||||
* Glen Fernandes
|
||||
|
||||
[endsimplesect]
|
||||
|
||||
[section Overview]
|
||||
|
||||
The header <boost/functional/identity.hpp> provides the function object
|
||||
`boost::identity` whose `operator()` returns its argument. It is an
|
||||
implementation of C++20's `std::identity` that supports C++03 and above.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Example]
|
||||
|
||||
It is commonly used as the default projection in constrained algorithms.
|
||||
|
||||
```
|
||||
template<class Range, class Projection = boost::identity>
|
||||
void print(Range&& range, Projection projection = {});
|
||||
```
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Reference]
|
||||
|
||||
```
|
||||
namespace boost {
|
||||
|
||||
struct identity {
|
||||
using is_transparent = unspecified;
|
||||
|
||||
template<class T>
|
||||
T&& operator()(T&& value) const noexcept;
|
||||
};
|
||||
|
||||
} /* boost */
|
||||
```
|
||||
|
||||
[section Operators]
|
||||
|
||||
[variablelist
|
||||
[[`template<class T> T&& operator()(T&& value) const noexcept;`]
|
||||
[Returns `std::forward<T>(value)`.]]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
145
doc/serialization.qbk
Normal file
145
doc/serialization.qbk
Normal file
@@ -0,0 +1,145 @@
|
||||
[/
|
||||
Copyright 2023 Peter Dimov
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
https://boost.org/LICENSE_1_0.txt
|
||||
]
|
||||
|
||||
[section:serialization serialization]
|
||||
|
||||
[simplesect Authors]
|
||||
|
||||
* Peter Dimov
|
||||
|
||||
[endsimplesect]
|
||||
|
||||
[section Header <boost/core/serialization.hpp>]
|
||||
|
||||
The header `<boost/core/serialization.hpp>` implements primitives
|
||||
that are necessary to implement Boost.Serialization support without
|
||||
including a Boost.Serialization header and thereby making a library
|
||||
dependent on Boost.Serialization.
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
``
|
||||
#include <boost/core/nvp.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace serialization
|
||||
{
|
||||
|
||||
// forward declarations
|
||||
|
||||
template<class T> struct version;
|
||||
class access;
|
||||
|
||||
// core_version_type
|
||||
|
||||
struct core_version_type;
|
||||
|
||||
} // namespace serialization
|
||||
|
||||
namespace core
|
||||
{
|
||||
|
||||
// nvp
|
||||
|
||||
using serialization::nvp;
|
||||
using serialization::make_nvp;
|
||||
|
||||
// split_free
|
||||
|
||||
template<class Ar, class T> void split_free( Ar& ar, T& t, unsigned int v );
|
||||
|
||||
// split_member
|
||||
|
||||
template<class Ar, class T> void split_member( Ar& ar, T& t, unsigned int v );
|
||||
|
||||
// load_construct_data_adl
|
||||
|
||||
template<class Ar, class T> void load_construct_data_adl( Ar& ar, T* t, unsigned int v );
|
||||
|
||||
// save_construct_data_adl
|
||||
|
||||
template<class Ar, class T> void save_construct_data_adl( Ar& ar, T const* t, unsigned int v );
|
||||
|
||||
} // namespace core
|
||||
} // namespace boost
|
||||
``
|
||||
|
||||
[endsect]
|
||||
|
||||
[section `core_version_type`]
|
||||
|
||||
``
|
||||
struct core_version_type
|
||||
{
|
||||
unsigned int version_;
|
||||
|
||||
core_version_type( unsigned int version ): version_( version ) {}
|
||||
operator unsigned int () const { return version_; }
|
||||
};
|
||||
``
|
||||
|
||||
`core_version_type` is a Core reimplementation of
|
||||
`boost::serialization::version_type`, needed to call ADL serialization
|
||||
primitives such as, for example, `load_construct_data` below.
|
||||
|
||||
It's defined in the `serialization` namespace instead of the `core`
|
||||
namespace because its only purpose is to add `boost::serialization` to
|
||||
the list of the associated namespaces of the corresponding call.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section `split_free`]
|
||||
|
||||
`template<class Ar, class T> inline void split_free( Ar& ar, T& t, unsigned int v );`
|
||||
|
||||
`boost::core::split_free` is a Core reimplementation of
|
||||
`boost::serialization::split_free`.
|
||||
|
||||
* *Effects:*
|
||||
* If `Ar::is_saving::value` is `true`, calls `save( ar, t, core_version_type( v ) )`;
|
||||
* Otherwise, calls `load( ar, t, core_version_type( v ) )`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section `split_member`]
|
||||
|
||||
`template<class Ar, class T> void split_member( Ar& ar, T& t, unsigned int v );`
|
||||
|
||||
`boost::core::split_member` is a Core reimplementation of
|
||||
`boost::serialization::split_member`.
|
||||
|
||||
* *Effects:*
|
||||
* If `Ar::is_saving::value` is `true`, calls `t.save( ar, v )`;
|
||||
* Otherwise, calls `t.load( ar, v )`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section `load_construct_data_adl`]
|
||||
|
||||
`template<class Ar, class T> void load_construct_data_adl( Ar& ar, T* t, unsigned int v );`
|
||||
|
||||
`boost::core::load_construct_data_adl` is a Core reimplementation of
|
||||
`boost::serialization::load_construct_data_adl`.
|
||||
|
||||
* *Effects:* `load_construct_data( ar, t, serialization::core_version_type( v ) );`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section `save_construct_data_adl`]
|
||||
|
||||
`template<class Ar, class T> void save_construct_data_adl( Ar& ar, T const* t, unsigned int v );`
|
||||
|
||||
`boost::core::save_construct_data_adl` is a Core reimplementation of
|
||||
`boost::serialization::save_construct_data_adl`.
|
||||
|
||||
* *Effects:* `save_construct_data( ar, t, serialization::core_version_type( v ) );`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
@@ -227,13 +227,13 @@ constexpr span(R&& r);`]
|
||||
[`remove_cvref_t<R>` is not a specialization of `span`,]
|
||||
[`remove_cvref_t<R>` is not a specialization of `array`,]
|
||||
[`is_array_v<remove_cvref_t<R>>` is `false`,]
|
||||
[`r.data()` is well-formed and
|
||||
[`data(r)` is well-formed and
|
||||
`is_convertible_v<remove_pointer_t<iterator_t<R> >(*)[],
|
||||
T(*)[]>` is `true`, and]
|
||||
[`r.size()` is well-formed and
|
||||
`is_convertible_v<decltype(declval<R&>().size()), size_t>` is `true`.]]]]
|
||||
[[Effects][Constructs a `span` with data `r.data()` and size `r.size()`.]]
|
||||
[[Throws][What and when r.data() and r.size() throw.]]]]]
|
||||
[[Effects][Constructs a `span` with data `data(r)` and size `r.size()`.]]
|
||||
[[Throws][What and when data(r) and r.size() throw.]]]]]
|
||||
[[`explicit(E != dynamic_extent && N == dynamic_extent)
|
||||
template<class U, std::size_t N>
|
||||
constexpr span(const span<U, N>& s) noexcept;`]
|
||||
|
||||
79
doc/yield_primitives.qbk
Normal file
79
doc/yield_primitives.qbk
Normal file
@@ -0,0 +1,79 @@
|
||||
[/
|
||||
Copyright 2023 Peter Dimov
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
https://boost.org/LICENSE_1_0.txt
|
||||
]
|
||||
|
||||
[section:yield_primitives Yield Primitives]
|
||||
|
||||
[simplesect Authors]
|
||||
|
||||
* Peter Dimov
|
||||
|
||||
[endsimplesect]
|
||||
|
||||
[section Header <boost/core/yield_primitives.hpp>]
|
||||
|
||||
The header `<boost/core/yield_primitives.hpp>` implements a
|
||||
collection of primitives that allow the current thread to
|
||||
yield the CPU in various ways.
|
||||
|
||||
Very low level, specialized functionality, generally only useful for
|
||||
implementing spinlocks. Normal synchronization primitives should
|
||||
almost always be preferable in application code.
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
``
|
||||
namespace boost
|
||||
{
|
||||
namespace core
|
||||
{
|
||||
|
||||
void sp_thread_pause() noexcept;
|
||||
void sp_thread_yield() noexcept;
|
||||
void sp_thread_sleep() noexcept;
|
||||
|
||||
} // namespace core
|
||||
} // namespace boost
|
||||
``
|
||||
|
||||
[endsect]
|
||||
|
||||
[section sp_thread_pause]
|
||||
|
||||
`void sp_thread_pause() noexcept;`
|
||||
|
||||
Emits a PAUSE instruction (on x86) or a YIELD instruction (on ARM).
|
||||
|
||||
A portable equivalent of the GCC builtin function `__builtin_ia32_pause`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section sp_thread_yield]
|
||||
|
||||
`void sp_thread_yield() noexcept;`
|
||||
|
||||
Informs the scheduler that the current thread wishes to relinquish
|
||||
the rest of its timeslice.
|
||||
|
||||
A portable equivalent of POSIX `sched_yield`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section sp_thread_sleep]
|
||||
|
||||
`void sp_thread_sleep() noexcept;`
|
||||
|
||||
Sleeps for a short period, as if by calling POSIX `nanosleep` with
|
||||
a small, implementation-dependent, interval (usually one microsecond).
|
||||
|
||||
A more forcing yield primitive than `sp_thread_yield`, because it's
|
||||
generally not ignored even if all other waiting threads are of lower
|
||||
priority.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <limits>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
@@ -38,6 +39,20 @@
|
||||
|
||||
#endif // defined(_MSC_VER)
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC >= 1925
|
||||
# define BOOST_CORE_HAS_BUILTIN_ISCONSTEVAL
|
||||
#endif
|
||||
|
||||
#if defined(__has_builtin)
|
||||
# if __has_builtin(__builtin_bit_cast)
|
||||
# define BOOST_CORE_HAS_BUILTIN_BIT_CAST
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC >= 1926
|
||||
# define BOOST_CORE_HAS_BUILTIN_BIT_CAST
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace core
|
||||
@@ -45,6 +60,16 @@ namespace core
|
||||
|
||||
// bit_cast
|
||||
|
||||
#if defined(BOOST_CORE_HAS_BUILTIN_BIT_CAST)
|
||||
|
||||
template<class To, class From>
|
||||
BOOST_CONSTEXPR To bit_cast( From const & from ) BOOST_NOEXCEPT
|
||||
{
|
||||
return __builtin_bit_cast( To, from );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template<class To, class From>
|
||||
To bit_cast( From const & from ) BOOST_NOEXCEPT
|
||||
{
|
||||
@@ -55,6 +80,8 @@ To bit_cast( From const & from ) BOOST_NOEXCEPT
|
||||
return to;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// countl
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
@@ -102,10 +129,51 @@ BOOST_CONSTEXPR int countl_zero( T x ) BOOST_NOEXCEPT
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if defined(_MSC_VER) && defined(BOOST_CORE_HAS_BUILTIN_ISCONSTEVAL)
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline int countl_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
if( __builtin_is_constant_evaluated() )
|
||||
{
|
||||
constexpr unsigned char mod37[ 37 ] = { 32, 31, 6, 30, 9, 5, 0, 29, 16, 8, 2, 4, 21, 0, 19, 28, 25, 15, 0, 7, 10, 1, 17, 3, 22, 20, 26, 0, 11, 18, 23, 27, 12, 24, 13, 14, 0 };
|
||||
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
|
||||
return mod37[ x % 37 ];
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned long r;
|
||||
|
||||
if( _BitScanReverse( &r, x ) )
|
||||
{
|
||||
return 31 - static_cast<int>( r );
|
||||
}
|
||||
else
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline int countl_impl( boost::uint8_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x ) ) - 24;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline int countl_impl( boost::uint16_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x ) ) - 16;
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
inline int countl_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
unsigned long r;
|
||||
|
||||
if( _BitScanReverse( &r, x ) )
|
||||
@@ -116,44 +184,6 @@ inline int countl_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static unsigned char const mod37[ 37 ] = { 32, 31, 6, 30, 9, 5, 0, 29, 16, 8, 2, 4, 21, 0, 19, 28, 25, 15, 0, 7, 10, 1, 17, 3, 22, 20, 26, 0, 11, 18, 23, 27, 12, 24, 13, 14, 0 };
|
||||
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
|
||||
return mod37[ x % 37 ];
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int countl_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
#if defined(_MSC_VER) && defined(_M_X64)
|
||||
|
||||
unsigned long r;
|
||||
|
||||
if( _BitScanReverse64( &r, x ) )
|
||||
{
|
||||
return 63 - static_cast<int>( r );
|
||||
}
|
||||
else
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
return static_cast<boost::uint32_t>( x >> 32 ) != 0?
|
||||
boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x >> 32 ) ):
|
||||
boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x ) ) + 32;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int countl_impl( boost::uint8_t x ) BOOST_NOEXCEPT
|
||||
@@ -166,10 +196,98 @@ inline int countl_impl( boost::uint16_t x ) BOOST_NOEXCEPT
|
||||
return boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x ) ) - 16;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline int countl_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
static unsigned char const mod37[ 37 ] = { 32, 31, 6, 30, 9, 5, 0, 29, 16, 8, 2, 4, 21, 0, 19, 28, 25, 15, 0, 7, 10, 1, 17, 3, 22, 20, 26, 0, 11, 18, 23, 27, 12, 24, 13, 14, 0 };
|
||||
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
|
||||
return mod37[ x % 37 ];
|
||||
}
|
||||
|
||||
inline int countl_impl( boost::uint8_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x ) ) - 24;
|
||||
}
|
||||
|
||||
inline int countl_impl( boost::uint16_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x ) ) - 16;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && defined(_M_X64) && defined(BOOST_CORE_HAS_BUILTIN_ISCONSTEVAL)
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline int countl_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
if( __builtin_is_constant_evaluated() )
|
||||
{
|
||||
return static_cast<boost::uint32_t>( x >> 32 ) != 0?
|
||||
boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x >> 32 ) ):
|
||||
boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x ) ) + 32;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned long r;
|
||||
|
||||
if( _BitScanReverse64( &r, x ) )
|
||||
{
|
||||
return 63 - static_cast<int>( r );
|
||||
}
|
||||
else
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER) && defined(_M_X64)
|
||||
|
||||
inline int countl_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
unsigned long r;
|
||||
|
||||
if( _BitScanReverse64( &r, x ) )
|
||||
{
|
||||
return 63 - static_cast<int>( r );
|
||||
}
|
||||
else
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER) && defined(BOOST_CORE_HAS_BUILTIN_ISCONSTEVAL)
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline int countl_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return static_cast<boost::uint32_t>( x >> 32 ) != 0?
|
||||
boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x >> 32 ) ):
|
||||
boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x ) ) + 32;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline int countl_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return static_cast<boost::uint32_t>( x >> 32 ) != 0?
|
||||
boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x >> 32 ) ):
|
||||
boost::core::detail::countl_impl( static_cast<boost::uint32_t>( x ) ) + 32;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class T>
|
||||
int countl_zero( T x ) BOOST_NOEXCEPT
|
||||
BOOST_CXX14_CONSTEXPR int countl_zero( T x ) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed );
|
||||
|
||||
@@ -250,10 +368,44 @@ BOOST_CONSTEXPR int countr_zero( T x ) BOOST_NOEXCEPT
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if defined(_MSC_VER) && defined(BOOST_CORE_HAS_BUILTIN_ISCONSTEVAL)
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline int countr_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
if( __builtin_is_constant_evaluated() )
|
||||
{
|
||||
constexpr unsigned char mod37[ 37 ] = { 32, 0, 1, 26, 2, 23, 27, 0, 3, 16, 24, 30, 28, 11, 0, 13, 4, 7, 17, 0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9, 5, 20, 8, 19, 18 };
|
||||
return mod37[ ( -(boost::int32_t)x & x ) % 37 ];
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned long r;
|
||||
|
||||
if( _BitScanForward( &r, x ) )
|
||||
{
|
||||
return static_cast<int>( r );
|
||||
}
|
||||
else
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline int countr_impl( boost::uint8_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x ) | 0x100 );
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline int countr_impl( boost::uint16_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x ) | 0x10000 );
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
inline int countr_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
unsigned long r;
|
||||
|
||||
if( _BitScanForward( &r, x ) )
|
||||
@@ -264,37 +416,6 @@ inline int countr_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static unsigned char const mod37[ 37 ] = { 32, 0, 1, 26, 2, 23, 27, 0, 3, 16, 24, 30, 28, 11, 0, 13, 4, 7, 17, 0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9, 5, 20, 8, 19, 18 };
|
||||
return mod37[ ( -(boost::int32_t)x & x ) % 37 ];
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int countr_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
#if defined(_MSC_VER) && defined(_M_X64)
|
||||
|
||||
unsigned long r;
|
||||
|
||||
if( _BitScanForward64( &r, x ) )
|
||||
{
|
||||
return static_cast<int>( r );
|
||||
}
|
||||
else
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
return static_cast<boost::uint32_t>( x ) != 0?
|
||||
boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x ) ):
|
||||
boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x >> 32 ) ) + 32;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int countr_impl( boost::uint8_t x ) BOOST_NOEXCEPT
|
||||
@@ -307,10 +428,91 @@ inline int countr_impl( boost::uint16_t x ) BOOST_NOEXCEPT
|
||||
return boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x ) | 0x10000 );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline int countr_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
static unsigned char const mod37[ 37 ] = { 32, 0, 1, 26, 2, 23, 27, 0, 3, 16, 24, 30, 28, 11, 0, 13, 4, 7, 17, 0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9, 5, 20, 8, 19, 18 };
|
||||
return mod37[ ( -(boost::int32_t)x & x ) % 37 ];
|
||||
}
|
||||
|
||||
inline int countr_impl( boost::uint8_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x ) | 0x100 );
|
||||
}
|
||||
|
||||
inline int countr_impl( boost::uint16_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x ) | 0x10000 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && defined(_M_X64) && defined(BOOST_CORE_HAS_BUILTIN_ISCONSTEVAL)
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline int countr_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
if( __builtin_is_constant_evaluated() )
|
||||
{
|
||||
return static_cast<boost::uint32_t>( x ) != 0?
|
||||
boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x ) ):
|
||||
boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x >> 32 ) ) + 32;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned long r;
|
||||
|
||||
if( _BitScanForward64( &r, x ) )
|
||||
{
|
||||
return static_cast<int>( r );
|
||||
}
|
||||
else
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER) && defined(_M_X64)
|
||||
|
||||
inline int countr_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
unsigned long r;
|
||||
|
||||
if( _BitScanForward64( &r, x ) )
|
||||
{
|
||||
return static_cast<int>( r );
|
||||
}
|
||||
else
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER) && defined(BOOST_CORE_HAS_BUILTIN_ISCONSTEVAL)
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline int countr_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return static_cast<boost::uint32_t>( x ) != 0?
|
||||
boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x ) ):
|
||||
boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x >> 32 ) ) + 32;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline int countr_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return static_cast<boost::uint32_t>( x ) != 0?
|
||||
boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x ) ):
|
||||
boost::core::detail::countr_impl( static_cast<boost::uint32_t>( x >> 32 ) ) + 32;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class T>
|
||||
int countr_zero( T x ) BOOST_NOEXCEPT
|
||||
BOOST_CXX14_CONSTEXPR int countr_zero( T x ) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed );
|
||||
|
||||
@@ -446,7 +648,7 @@ BOOST_CXX14_CONSTEXPR T rotl( T x, int s ) BOOST_NOEXCEPT
|
||||
BOOST_STATIC_ASSERT( std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed );
|
||||
|
||||
unsigned const mask = std::numeric_limits<T>::digits - 1;
|
||||
return x << (s & mask) | x >> ((-s) & mask);
|
||||
return static_cast<T>( x << (static_cast<unsigned>( s ) & mask) | x >> (static_cast<unsigned>( -s ) & mask) );
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -455,7 +657,7 @@ BOOST_CXX14_CONSTEXPR T rotr( T x, int s ) BOOST_NOEXCEPT
|
||||
BOOST_STATIC_ASSERT( std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed );
|
||||
|
||||
unsigned const mask = std::numeric_limits<T>::digits - 1;
|
||||
return x >> (s & mask) | x << ((-s) & mask);
|
||||
return static_cast<T>( x >> (static_cast<unsigned>( s ) & mask) | x << (static_cast<unsigned>( -s ) & mask) );
|
||||
}
|
||||
|
||||
// integral powers of 2
|
||||
@@ -484,7 +686,7 @@ BOOST_CONSTEXPR T bit_floor( T x ) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed );
|
||||
|
||||
return x == 0? 0: T(1) << ( boost::core::bit_width( x ) - 1 );
|
||||
return x == 0? T(0): static_cast<T>( T(1) << ( boost::core::bit_width( x ) - 1 ) );
|
||||
}
|
||||
|
||||
namespace detail
|
||||
@@ -613,6 +815,117 @@ typedef endian::type endian_type;
|
||||
|
||||
#undef BOOST_CORE_BIT_NATIVE_INITIALIZER
|
||||
|
||||
// byteswap
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
BOOST_CONSTEXPR inline boost::uint8_t byteswap_impl( boost::uint8_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR inline boost::uint16_t byteswap_impl( boost::uint16_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return static_cast<boost::uint16_t>( x << 8 | x >> 8 );
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline boost::uint32_t byteswap_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return __builtin_bswap32( x );
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline boost::uint64_t byteswap_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return __builtin_bswap64( x );
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER) && defined(BOOST_CORE_HAS_BUILTIN_ISCONSTEVAL)
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline boost::uint32_t byteswap_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
if( __builtin_is_constant_evaluated() )
|
||||
{
|
||||
boost::uint32_t step16 = x << 16 | x >> 16;
|
||||
return ((step16 << 8) & 0xff00ff00) | ((step16 >> 8) & 0x00ff00ff);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _byteswap_ulong( x );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline boost::uint64_t byteswap_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
if( __builtin_is_constant_evaluated() )
|
||||
{
|
||||
boost::uint64_t step32 = x << 32 | x >> 32;
|
||||
boost::uint64_t step16 = (step32 & 0x0000FFFF0000FFFFULL) << 16 | (step32 & 0xFFFF0000FFFF0000ULL) >> 16;
|
||||
return (step16 & 0x00FF00FF00FF00FFULL) << 8 | (step16 & 0xFF00FF00FF00FF00ULL) >> 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _byteswap_uint64( x );
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
inline boost::uint32_t byteswap_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return _byteswap_ulong( x );
|
||||
}
|
||||
|
||||
inline boost::uint64_t byteswap_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
return _byteswap_uint64( x );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline boost::uint32_t byteswap_impl( boost::uint32_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
boost::uint32_t step16 = x << 16 | x >> 16;
|
||||
return ((step16 << 8) & 0xff00ff00) | ((step16 >> 8) & 0x00ff00ff);
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline boost::uint64_t byteswap_impl( boost::uint64_t x ) BOOST_NOEXCEPT
|
||||
{
|
||||
boost::uint64_t step32 = x << 32 | x >> 32;
|
||||
boost::uint64_t step16 = (step32 & 0x0000FFFF0000FFFFULL) << 16 | (step32 & 0xFFFF0000FFFF0000ULL) >> 16;
|
||||
return (step16 & 0x00FF00FF00FF00FFULL) << 8 | (step16 & 0xFF00FF00FF00FF00ULL) >> 8;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class T> BOOST_CXX14_CONSTEXPR T byteswap( T x ) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT( std::numeric_limits<T>::is_integer );
|
||||
|
||||
BOOST_STATIC_ASSERT( sizeof(T) == sizeof(boost::uint8_t) || sizeof(T) == sizeof(boost::uint16_t) || sizeof(T) == sizeof(boost::uint32_t) || sizeof(T) == sizeof(boost::uint64_t) );
|
||||
|
||||
BOOST_IF_CONSTEXPR ( sizeof(T) == sizeof(boost::uint8_t) )
|
||||
{
|
||||
return static_cast<T>( boost::core::detail::byteswap_impl( static_cast<boost::uint8_t>( x ) ) );
|
||||
}
|
||||
else BOOST_IF_CONSTEXPR ( sizeof(T) == sizeof(boost::uint16_t) )
|
||||
{
|
||||
return static_cast<T>( boost::core::detail::byteswap_impl( static_cast<boost::uint16_t>( x ) ) );
|
||||
}
|
||||
else BOOST_IF_CONSTEXPR ( sizeof(T) == sizeof(boost::uint32_t) )
|
||||
{
|
||||
return static_cast<T>( boost::core::detail::byteswap_impl( static_cast<boost::uint32_t>( x ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return static_cast<T>( boost::core::detail::byteswap_impl( static_cast<boost::uint64_t>( x ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace boost
|
||||
|
||||
|
||||
@@ -30,16 +30,33 @@ namespace boost
|
||||
|
||||
template<class T> inline void checked_delete(T * x) BOOST_NOEXCEPT
|
||||
{
|
||||
// intentionally complex - simplification causes regressions
|
||||
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
|
||||
#if defined(__cpp_static_assert) && __cpp_static_assert >= 200410L
|
||||
|
||||
static_assert( sizeof(T) != 0, "Type must be complete" );
|
||||
|
||||
#else
|
||||
|
||||
typedef char type_must_be_complete[ sizeof(T) ];
|
||||
(void) sizeof(type_must_be_complete);
|
||||
|
||||
#endif
|
||||
|
||||
delete x;
|
||||
}
|
||||
|
||||
template<class T> inline void checked_array_delete(T * x) BOOST_NOEXCEPT
|
||||
{
|
||||
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
|
||||
#if defined(__cpp_static_assert) && __cpp_static_assert >= 200410L
|
||||
|
||||
static_assert( sizeof(T) != 0, "Type must be complete" );
|
||||
|
||||
#else
|
||||
|
||||
typedef char type_must_be_complete[ sizeof(T) ];
|
||||
(void) sizeof(type_must_be_complete);
|
||||
|
||||
#endif
|
||||
|
||||
delete [] x;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,9 +35,13 @@ inline void lwt_unattended()
|
||||
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
# endif
|
||||
|
||||
#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY == 100 /*WINAPI_FAMILY_DESKTOP_APP*/
|
||||
|
||||
// disable message box on crash
|
||||
::_seterrormode( /*SEM_NOGPFAULTERRORBOX*/ 0x0002 );
|
||||
|
||||
#endif
|
||||
|
||||
# if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
# endif
|
||||
|
||||
71
include/boost/core/detail/sp_thread_pause.hpp
Normal file
71
include/boost/core/detail/sp_thread_pause.hpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef BOOST_CORE_DETAIL_SP_THREAD_PAUSE_HPP_INCLUDED
|
||||
#define BOOST_CORE_DETAIL_SP_THREAD_PAUSE_HPP_INCLUDED
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
// boost/core/detail/sp_thread_pause.hpp
|
||||
//
|
||||
// inline void bost::core::sp_thread_pause();
|
||||
//
|
||||
// Emits a "pause" instruction.
|
||||
//
|
||||
// Copyright 2008, 2020, 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(__has_builtin)
|
||||
# if __has_builtin(__builtin_ia32_pause) && !defined(_INTEL_COMPILER)
|
||||
# define BOOST_CORE_HAS_BUILTIN_IA32_PAUSE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_CORE_HAS_BUILTIN_IA32_PAUSE)
|
||||
|
||||
# define BOOST_CORE_SP_PAUSE() __builtin_ia32_pause()
|
||||
|
||||
#elif defined(_MSC_VER) && ( defined(_M_IX86) || defined(_M_X64) )
|
||||
|
||||
# include <intrin.h>
|
||||
# define BOOST_CORE_SP_PAUSE() _mm_pause()
|
||||
|
||||
#elif defined(_MSC_VER) && ( defined(_M_ARM) || defined(_M_ARM64) )
|
||||
|
||||
# include <intrin.h>
|
||||
# define BOOST_CORE_SP_PAUSE() __yield()
|
||||
|
||||
#elif defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
|
||||
|
||||
# define BOOST_CORE_SP_PAUSE() __asm__ __volatile__( "rep; nop" : : : "memory" )
|
||||
|
||||
#elif defined(__GNUC__) && ( (defined(__ARM_ARCH) && __ARM_ARCH >= 8) || defined(__ARM_ARCH_8A__) || defined(__aarch64__) )
|
||||
|
||||
# define BOOST_CORE_SP_PAUSE() __asm__ __volatile__( "yield" : : : "memory" )
|
||||
|
||||
#else
|
||||
|
||||
# define BOOST_CORE_SP_PAUSE() ((void)0)
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace core
|
||||
{
|
||||
|
||||
BOOST_FORCEINLINE void sp_thread_pause() BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_CORE_SP_PAUSE();
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace boost
|
||||
|
||||
#undef BOOST_CORE_SP_PAUSE
|
||||
|
||||
#endif // #ifndef BOOST_CORE_DETAIL_SP_THREAD_PAUSE_HPP_INCLUDED
|
||||
122
include/boost/core/detail/sp_thread_sleep.hpp
Normal file
122
include/boost/core/detail/sp_thread_sleep.hpp
Normal file
@@ -0,0 +1,122 @@
|
||||
#ifndef BOOST_CORE_DETAIL_SP_THREAD_SLEEP_HPP_INCLUDED
|
||||
#define BOOST_CORE_DETAIL_SP_THREAD_SLEEP_HPP_INCLUDED
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
// boost/core/detail/sp_thread_sleep.hpp
|
||||
//
|
||||
// inline void bost::core::sp_thread_sleep();
|
||||
//
|
||||
// Cease execution for a while to yield to other threads,
|
||||
// as if by calling nanosleep() with an appropriate interval.
|
||||
//
|
||||
// Copyright 2008, 2020, 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
BOOST_PRAGMA_MESSAGE("Using Sleep(1) in sp_thread_sleep")
|
||||
#endif
|
||||
|
||||
#include <boost/core/detail/sp_win32_sleep.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace core
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline void sp_thread_sleep() BOOST_NOEXCEPT
|
||||
{
|
||||
Sleep( 1 );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using boost::core::detail::sp_thread_sleep;
|
||||
|
||||
} // namespace core
|
||||
} // namespace boost
|
||||
|
||||
#elif defined(BOOST_HAS_NANOSLEEP)
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
BOOST_PRAGMA_MESSAGE("Using nanosleep() in sp_thread_sleep")
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__)
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace core
|
||||
{
|
||||
|
||||
inline void sp_thread_sleep() BOOST_NOEXCEPT
|
||||
{
|
||||
#if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__)
|
||||
|
||||
int oldst;
|
||||
pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &oldst );
|
||||
|
||||
#endif
|
||||
|
||||
// g++ -Wextra warns on {} or {0}
|
||||
struct timespec rqtp = { 0, 0 };
|
||||
|
||||
// POSIX says that timespec has tv_sec and tv_nsec
|
||||
// But it doesn't guarantee order or placement
|
||||
|
||||
rqtp.tv_sec = 0;
|
||||
rqtp.tv_nsec = 1000;
|
||||
|
||||
nanosleep( &rqtp, 0 );
|
||||
|
||||
#if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__)
|
||||
|
||||
pthread_setcancelstate( oldst, &oldst );
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace boost
|
||||
|
||||
#else
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
BOOST_PRAGMA_MESSAGE("Using sp_thread_yield() in sp_thread_sleep")
|
||||
#endif
|
||||
|
||||
#include <boost/core/detail/sp_thread_yield.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace core
|
||||
{
|
||||
|
||||
inline void sp_thread_sleep() BOOST_NOEXCEPT
|
||||
{
|
||||
sp_thread_yield();
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_CORE_DETAIL_SP_THREAD_SLEEP_HPP_INCLUDED
|
||||
100
include/boost/core/detail/sp_thread_yield.hpp
Normal file
100
include/boost/core/detail/sp_thread_yield.hpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#ifndef BOOST_CORE_DETAIL_SP_THREAD_YIELD_HPP_INCLUDED
|
||||
#define BOOST_CORE_DETAIL_SP_THREAD_YIELD_HPP_INCLUDED
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
// boost/core/detail/sp_thread_yield.hpp
|
||||
//
|
||||
// inline void bost::core::sp_thread_yield();
|
||||
//
|
||||
// Gives up the remainder of the time slice,
|
||||
// as if by calling sched_yield().
|
||||
//
|
||||
// Copyright 2008, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
BOOST_PRAGMA_MESSAGE("Using SwitchToThread() in sp_thread_yield")
|
||||
#endif
|
||||
|
||||
#include <boost/core/detail/sp_win32_sleep.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace core
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline void sp_thread_yield() BOOST_NOEXCEPT
|
||||
{
|
||||
SwitchToThread();
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using boost::core::detail::sp_thread_yield;
|
||||
|
||||
} // namespace core
|
||||
} // namespace boost
|
||||
|
||||
#elif defined(BOOST_HAS_SCHED_YIELD)
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
BOOST_PRAGMA_MESSAGE("Using sched_yield() in sp_thread_yield")
|
||||
#endif
|
||||
|
||||
#ifndef _AIX
|
||||
# include <sched.h>
|
||||
#else
|
||||
// AIX's sched.h defines ::var which sometimes conflicts with Lambda's var
|
||||
extern "C" int sched_yield(void);
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace core
|
||||
{
|
||||
|
||||
inline void sp_thread_yield() BOOST_NOEXCEPT
|
||||
{
|
||||
sched_yield();
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace boost
|
||||
|
||||
#else
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
BOOST_PRAGMA_MESSAGE("Using sp_thread_pause() in sp_thread_yield")
|
||||
#endif
|
||||
|
||||
#include <boost/core/detail/sp_thread_pause.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace core
|
||||
{
|
||||
|
||||
inline void sp_thread_yield() BOOST_NOEXCEPT
|
||||
{
|
||||
sp_thread_pause();
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_CORE_DETAIL_SP_THREAD_YIELD_HPP_INCLUDED
|
||||
54
include/boost/core/detail/sp_win32_sleep.hpp
Normal file
54
include/boost/core/detail/sp_win32_sleep.hpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef BOOST_CORE_DETAIL_SP_WIN32_SLEEP_HPP_INCLUDED
|
||||
#define BOOST_CORE_DETAIL_SP_WIN32_SLEEP_HPP_INCLUDED
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
// boost/core/detail/sp_win32_sleep.hpp
|
||||
//
|
||||
// Declares the Win32 Sleep() function.
|
||||
//
|
||||
// Copyright 2008, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#if defined( BOOST_USE_WINDOWS_H )
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace core
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if !defined( BOOST_USE_WINDOWS_H )
|
||||
|
||||
#if defined(__clang__) && defined(__x86_64__)
|
||||
// clang x64 warns that __stdcall is ignored
|
||||
# define BOOST_CORE_SP_STDCALL
|
||||
#else
|
||||
# define BOOST_CORE_SP_STDCALL __stdcall
|
||||
#endif
|
||||
|
||||
#if defined(__LP64__) // Cygwin 64
|
||||
extern "C" __declspec(dllimport) void BOOST_CORE_SP_STDCALL Sleep( unsigned int ms );
|
||||
#else
|
||||
extern "C" __declspec(dllimport) void BOOST_CORE_SP_STDCALL Sleep( unsigned long ms );
|
||||
#endif
|
||||
|
||||
extern "C" __declspec(dllimport) int BOOST_CORE_SP_STDCALL SwitchToThread();
|
||||
|
||||
#undef BOOST_CORE_SP_STDCALL
|
||||
|
||||
#endif // !defined( BOOST_USE_WINDOWS_H )
|
||||
|
||||
} // namespace detail
|
||||
} // namespace core
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_CORE_DETAIL_SP_WIN32_SLEEP_HPP_INCLUDED
|
||||
61
include/boost/core/identity.hpp
Normal file
61
include/boost/core/identity.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright 2021-2023 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_CORE_IDENTITY_HPP
|
||||
#define BOOST_CORE_IDENTITY_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
struct identity {
|
||||
typedef void is_transparent;
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
template<class T>
|
||||
BOOST_CONSTEXPR T&& operator()(T&& value) const BOOST_NOEXCEPT {
|
||||
return std::forward<T>(value);
|
||||
}
|
||||
#else
|
||||
template<class T>
|
||||
BOOST_CONSTEXPR const T& operator()(const T& value) const BOOST_NOEXCEPT {
|
||||
return value;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BOOST_CONSTEXPR T& operator()(T& value) const BOOST_NOEXCEPT {
|
||||
return value;
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class>
|
||||
struct result { };
|
||||
|
||||
template<class T>
|
||||
struct result<identity(T&)> {
|
||||
typedef T& type;
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
template<class T>
|
||||
struct result<identity(T)> {
|
||||
typedef T&& type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct result<identity(T&&)> {
|
||||
typedef T&& type;
|
||||
};
|
||||
#endif
|
||||
};
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
@@ -8,11 +8,10 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
#ifndef BOOST_CORE_SPAN_HPP
|
||||
#define BOOST_CORE_SPAN_HPP
|
||||
|
||||
#include <boost/core/data.hpp>
|
||||
#include <array>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
|
||||
@@ -63,29 +62,8 @@ struct span_is_array<std::array<T, N> > {
|
||||
static constexpr bool value = true;
|
||||
};
|
||||
|
||||
template<class C>
|
||||
inline constexpr auto
|
||||
span_begin(C& c) noexcept(noexcept(c.data())) -> decltype(c.data())
|
||||
{
|
||||
return c.data();
|
||||
}
|
||||
|
||||
template<class C>
|
||||
inline constexpr auto
|
||||
span_begin(const C& c) noexcept(noexcept(c.data())) -> decltype(c.data())
|
||||
{
|
||||
return c.data();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline constexpr const T*
|
||||
span_begin(std::initializer_list<T> l) noexcept
|
||||
{
|
||||
return l.begin();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
using span_ptr = decltype(boost::detail::span_begin(std::declval<T&>()));
|
||||
using span_ptr = decltype(boost::data(std::declval<T&>()));
|
||||
|
||||
template<class, class = void>
|
||||
struct span_data { };
|
||||
@@ -245,16 +223,16 @@ public:
|
||||
template<class R,
|
||||
typename std::enable_if<E == dynamic_extent &&
|
||||
detail::span_is_range<R, T>::value, int>::type = 0>
|
||||
constexpr span(R&& r) noexcept(noexcept(detail::span_begin(r)) &&
|
||||
constexpr span(R&& r) noexcept(noexcept(boost::data(r)) &&
|
||||
noexcept(r.size()))
|
||||
: s_(detail::span_begin(r), r.size()) { }
|
||||
: s_(boost::data(r), r.size()) { }
|
||||
|
||||
template<class R,
|
||||
typename std::enable_if<E != dynamic_extent &&
|
||||
detail::span_is_range<R, T>::value, int>::type = 0>
|
||||
explicit constexpr span(R&& r) noexcept(noexcept(detail::span_begin(r)) &&
|
||||
explicit constexpr span(R&& r) noexcept(noexcept(boost::data(r)) &&
|
||||
noexcept(r.size()))
|
||||
: s_(detail::span_begin(r), r.size()) { }
|
||||
: s_(boost::data(r), r.size()) { }
|
||||
|
||||
template<class U, std::size_t N,
|
||||
typename std::enable_if<detail::span_implicit<E, N>::value &&
|
||||
|
||||
@@ -102,11 +102,23 @@ inline std::string fix_typeid_name( char const* n )
|
||||
return r;
|
||||
}
|
||||
|
||||
template<class T> std::string typeid_name()
|
||||
// class types can be incomplete
|
||||
template<class T> std::string typeid_name_impl( int T::* )
|
||||
{
|
||||
std::string r = fix_typeid_name( typeid(T[1]).name() );
|
||||
return r.substr( 0, r.size() - 4 ); // remove ' [1]' suffix
|
||||
}
|
||||
|
||||
template<class T> std::string typeid_name_impl( ... )
|
||||
{
|
||||
return fix_typeid_name( typeid(T).name() );
|
||||
}
|
||||
|
||||
template<class T> std::string typeid_name()
|
||||
{
|
||||
return typeid_name_impl<T>( 0 );
|
||||
}
|
||||
|
||||
// template names
|
||||
|
||||
template<class T> std::string class_template_name()
|
||||
@@ -862,6 +874,8 @@ template<class T, std::size_t N> struct tn_holder<T const volatile[N]>
|
||||
|
||||
// pointers to members
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
template<class R, class T> struct tn_holder<R T::*>
|
||||
{
|
||||
static std::string type_name( std::string const& suffix )
|
||||
@@ -870,7 +884,7 @@ template<class R, class T> struct tn_holder<R T::*>
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1900 && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1900
|
||||
|
||||
template<class R, class T, class... A> struct tn_holder<R(T::*)(A...)>
|
||||
{
|
||||
@@ -904,7 +918,9 @@ template<class R, class T, class... A> struct tn_holder<R(T::*)(A...) const vola
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // #if defined(BOOST_MSVC) && BOOST_MSVC < 1900
|
||||
|
||||
#endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
// strings
|
||||
|
||||
|
||||
12
include/boost/core/yield_primitives.hpp
Normal file
12
include/boost/core/yield_primitives.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef BOOST_CORE_YIELD_PRIMITIVES_HPP_INCLUDED
|
||||
#define BOOST_CORE_YIELD_PRIMITIVES_HPP_INCLUDED
|
||||
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/core/detail/sp_thread_pause.hpp>
|
||||
#include <boost/core/detail/sp_thread_yield.hpp>
|
||||
#include <boost/core/detail/sp_thread_sleep.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_CORE_YIELD_PRIMITIVES_HPP_INCLUDED
|
||||
@@ -38,6 +38,13 @@ boost_test(TYPE run SOURCES serialization_split_free_test.cpp)
|
||||
boost_test(TYPE run SOURCES serialization_split_member_test.cpp)
|
||||
boost_test(TYPE run SOURCES serialization_construct_data_test.cpp)
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
set(BOOST_TEST_LINK_LIBRARIES Boost::core Threads::Threads)
|
||||
|
||||
boost_test(TYPE run SOURCES yield_prim_pthread_cancel_test.cpp)
|
||||
|
||||
endif()
|
||||
|
||||
add_subdirectory(swap)
|
||||
|
||||
@@ -98,6 +98,8 @@ run visit_each_test.cpp ;
|
||||
run get_pointer_test.cpp ;
|
||||
|
||||
local pedantic-errors = <warnings>pedantic
|
||||
<toolset>gcc:<cxxflags>"-Wconversion"
|
||||
<toolset>clang:<cxxflags>"-Wconversion"
|
||||
<toolset>msvc:<warnings-as-errors>on
|
||||
<toolset>gcc:<warnings-as-errors>on
|
||||
<toolset>clang:<warnings-as-errors>on ;
|
||||
@@ -296,10 +298,23 @@ run bit_popcount_test.cpp
|
||||
: : : $(pedantic-errors) ;
|
||||
run bit_endian_test.cpp
|
||||
: : : $(pedantic-errors) ;
|
||||
run bit_byteswap_test.cpp
|
||||
: : : $(pedantic-errors) ;
|
||||
|
||||
compile-fail bit_width_fail.cpp
|
||||
: <warnings>off ;
|
||||
|
||||
compile bit_cast_test_cx.cpp ;
|
||||
compile bit_rotate_test_cx.cpp ;
|
||||
compile bit_countr_test_cx.cpp ;
|
||||
compile bit_countl_test_cx.cpp ;
|
||||
compile bit_width_test_cx.cpp ;
|
||||
compile has_single_bit_test_cx.cpp ;
|
||||
compile bit_floor_test_cx.cpp ;
|
||||
compile bit_ceil_test_cx.cpp ;
|
||||
compile bit_popcount_test_cx.cpp ;
|
||||
compile bit_byteswap_test_cx.cpp ;
|
||||
|
||||
run type_name_test.cpp ;
|
||||
|
||||
run snprintf_test.cpp ;
|
||||
@@ -363,10 +378,19 @@ run memory_resource_test.cpp ;
|
||||
run data_test.cpp ;
|
||||
run size_test.cpp ;
|
||||
|
||||
run serialization_nvp_test.cpp : : : <library>/boost//serialization/<warnings>off <toolset>clang,<undefined-sanitizer>norecover:<build>no ;
|
||||
run serialization_split_free_test.cpp : : : <library>/boost//serialization/<warnings>off ;
|
||||
run serialization_split_member_test.cpp : : : <library>/boost//serialization/<warnings>off ;
|
||||
run serialization_construct_data_test.cpp : : : <library>/boost//serialization/<warnings>off ;
|
||||
run serialization_nvp_test.cpp : : : <library>/boost//serialization/<warnings>off <undefined-sanitizer>norecover:<build>no ;
|
||||
run serialization_split_free_test.cpp : : : <library>/boost//serialization/<warnings>off <undefined-sanitizer>norecover:<link>static ;
|
||||
run serialization_split_member_test.cpp : : : <library>/boost//serialization/<warnings>off <undefined-sanitizer>norecover:<link>static ;
|
||||
run serialization_construct_data_test.cpp : : : <library>/boost//serialization/<warnings>off <undefined-sanitizer>norecover:<link>static ;
|
||||
|
||||
run identity_test.cpp ;
|
||||
run identity_rvalue_test.cpp ;
|
||||
|
||||
run sp_thread_pause_test.cpp ;
|
||||
run sp_thread_yield_test.cpp ;
|
||||
run sp_thread_sleep_test.cpp ;
|
||||
run yield_prim_windows_h_test.cpp ;
|
||||
run yield_prim_pthread_cancel_test.cpp : ;
|
||||
|
||||
use-project /boost/core/swap : ./swap ;
|
||||
build-project ./swap ;
|
||||
|
||||
26
test/bit_byteswap_test.cpp
Normal file
26
test/bit_byteswap_test.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// Test for boost/core/bit.hpp (byteswap)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_EQ( boost::core::byteswap( (boost::int8_t)0x01 ), 0x01 );
|
||||
BOOST_TEST_EQ( boost::core::byteswap( (boost::uint8_t)0xF1 ), 0xF1 );
|
||||
|
||||
BOOST_TEST_EQ( boost::core::byteswap( (boost::int16_t)0x0102 ), 0x0201 );
|
||||
BOOST_TEST_EQ( boost::core::byteswap( (boost::uint16_t)0xF1E2 ), 0xE2F1 );
|
||||
|
||||
BOOST_TEST_EQ( boost::core::byteswap( (boost::int32_t)0x01020304 ), 0x04030201 );
|
||||
BOOST_TEST_EQ( boost::core::byteswap( (boost::uint32_t)0xF1E2D3C4u ), 0xC4D3E2F1u );
|
||||
|
||||
BOOST_TEST_EQ( boost::core::byteswap( (boost::int64_t)0x01020304 << 32 | 0x05060708 ), (boost::int64_t)0x08070605 << 32 | 0x04030201 );
|
||||
BOOST_TEST_EQ( boost::core::byteswap( (boost::uint64_t)0xF1E2D3C4u << 32 | 0xB5A69788u ), (boost::uint64_t)0x8897A6B5u << 32 | 0xC4D3E2F1u );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
37
test/bit_byteswap_test_cx.cpp
Normal file
37
test/bit_byteswap_test_cx.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// constexpr test for boost/core/bit.hpp (bit_width)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC / 10 == 191
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC is " BOOST_STRINGIZE(BOOST_MSVC) )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::byteswap( (std::int8_t)0x01 ) == 0x01 );
|
||||
STATIC_ASSERT( boost::core::byteswap( (std::uint8_t)0xF1 ) == 0xF1 );
|
||||
|
||||
STATIC_ASSERT( boost::core::byteswap( (std::int16_t)0x0102 ) == 0x0201 );
|
||||
STATIC_ASSERT( boost::core::byteswap( (std::uint16_t)0xF1E2 ) == 0xE2F1 );
|
||||
|
||||
STATIC_ASSERT( boost::core::byteswap( (std::int32_t)0x01020304 ) == 0x04030201 );
|
||||
STATIC_ASSERT( boost::core::byteswap( (std::uint32_t)0xF1E2D3C4u ) == 0xC4D3E2F1u );
|
||||
|
||||
STATIC_ASSERT( boost::core::byteswap( (std::int64_t)0x0102030405060708ll ) == 0x0807060504030201ll );
|
||||
STATIC_ASSERT( boost::core::byteswap( (std::uint64_t)0xF1E2D3C4B5A69788ull ) == 0x8897A6B5C4D3E2F1ull );
|
||||
|
||||
#endif
|
||||
28
test/bit_cast_test_cx.cpp
Normal file
28
test/bit_cast_test_cx.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// constexpr test for boost/core/bit.hpp (bit_cast)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined" )
|
||||
|
||||
#elif !defined(BOOST_CORE_HAS_BUILTIN_BIT_CAST)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_CORE_HAS_BUILTIN_BIT_CAST is not defined" )
|
||||
|
||||
#else
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::bit_cast<boost::uint32_t>( 1.0f ) == 0x3F800000u );
|
||||
STATIC_ASSERT( boost::core::bit_cast<boost::uint64_t>( 1.0 ) == 0x3FF0000000000000ull );
|
||||
|
||||
#endif
|
||||
@@ -14,7 +14,7 @@ template<class T> void test_bit_ceil( T x )
|
||||
{
|
||||
if( !boost::core::has_single_bit( x ) )
|
||||
{
|
||||
x >>= 1;
|
||||
x = static_cast<T>( x >> 1 );
|
||||
}
|
||||
|
||||
T y = boost::core::bit_ceil( x );
|
||||
|
||||
26
test/bit_ceil_test_cx.cpp
Normal file
26
test/bit_ceil_test_cx.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// constexpr test for boost/core/bit.hpp (bit_ceil)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::bit_ceil( (unsigned char)0x74 ) == 0x80 );
|
||||
STATIC_ASSERT( boost::core::bit_ceil( (unsigned short)0x7400 ) == 0x8000 );
|
||||
STATIC_ASSERT( boost::core::bit_ceil( 0x740000u ) == 0x800000u );
|
||||
STATIC_ASSERT( boost::core::bit_ceil( 0x74000000ul ) == 0x80000000ul );
|
||||
STATIC_ASSERT( boost::core::bit_ceil( 0x7400000000ull ) == 0x8000000000ull );
|
||||
|
||||
#endif
|
||||
@@ -14,7 +14,7 @@ template<class T> void test_countl( T x )
|
||||
{
|
||||
x |= static_cast<T>( 1 ) << ( std::numeric_limits<T>::digits - 1 );
|
||||
|
||||
for( int i = 0; i <= std::numeric_limits<T>::digits; ++i, x >>= 1 )
|
||||
for( int i = 0; i <= std::numeric_limits<T>::digits; ++i, x = static_cast<T>( x >> 1 ) )
|
||||
{
|
||||
BOOST_TEST_EQ( boost::core::countl_zero( x ), i );
|
||||
BOOST_TEST_EQ( boost::core::countl_one( static_cast<T>( ~x ) ), i );
|
||||
|
||||
41
test/bit_countl_test_cx.cpp
Normal file
41
test/bit_countl_test_cx.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// constexpr test for boost/core/bit.hpp (countl_zero, countl_one)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(disable: 4310) // cast truncates constant value
|
||||
#endif
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC / 10 == 191
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC is " BOOST_STRINGIZE(BOOST_MSVC) )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
#include <climits>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::countl_zero( (unsigned char)0x1F ) == CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_zero( (unsigned short)0x1F ) == sizeof(unsigned short) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_zero( 0x1Fu ) == sizeof(unsigned int) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_zero( 0x1Ful ) == sizeof(unsigned long) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_zero( 0x1Full ) == sizeof(unsigned long long) * CHAR_BIT - 5 );
|
||||
|
||||
STATIC_ASSERT( boost::core::countl_one( (unsigned char)~0x1Fu ) == CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_one( (unsigned short)~0x1Fu ) == sizeof(unsigned short) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_one( ~0x1Fu ) == sizeof(unsigned int) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_one( ~0x1Ful ) == sizeof(unsigned long) * CHAR_BIT - 5 );
|
||||
STATIC_ASSERT( boost::core::countl_one( ~0x1Full ) == sizeof(unsigned long long) * CHAR_BIT - 5 );
|
||||
|
||||
#endif
|
||||
@@ -14,7 +14,7 @@ template<class T> void test_countr( T x )
|
||||
{
|
||||
x |= 1;
|
||||
|
||||
for( int i = 0; i <= std::numeric_limits<T>::digits; ++i, x <<= 1 )
|
||||
for( int i = 0; i <= std::numeric_limits<T>::digits; ++i, x = static_cast<T>( x << 1 ) )
|
||||
{
|
||||
BOOST_TEST_EQ( boost::core::countr_zero( x ), i );
|
||||
BOOST_TEST_EQ( boost::core::countr_one( static_cast<T>( ~x ) ), i );
|
||||
|
||||
41
test/bit_countr_test_cx.cpp
Normal file
41
test/bit_countr_test_cx.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// constexpr test for boost/core/bit.hpp (countr_zero, countr_one)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(disable: 4310) // cast truncates constant value
|
||||
#endif
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC / 10 == 191
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC is " BOOST_STRINGIZE(BOOST_MSVC) )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
#include <climits>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::countr_zero( (unsigned char)0xF8 ) == 3 );
|
||||
STATIC_ASSERT( boost::core::countr_zero( (unsigned short)0xF800 ) == 11 );
|
||||
STATIC_ASSERT( boost::core::countr_zero( 0xF80000u ) == 19 );
|
||||
STATIC_ASSERT( boost::core::countr_zero( 0xF8000000ul ) == 27 );
|
||||
STATIC_ASSERT( boost::core::countr_zero( 0xF800000000ull ) == 35 );
|
||||
|
||||
STATIC_ASSERT( boost::core::countr_one( (unsigned char)~0xF8u ) == 3 );
|
||||
STATIC_ASSERT( boost::core::countr_one( (unsigned short)~0xF800u ) == 11 );
|
||||
STATIC_ASSERT( boost::core::countr_one( ~0xF80000u ) == 19 );
|
||||
STATIC_ASSERT( boost::core::countr_one( ~0xF8000000ul ) == 27 );
|
||||
STATIC_ASSERT( boost::core::countr_one( ~0xF800000000ull ) == 35 );
|
||||
|
||||
#endif
|
||||
30
test/bit_floor_test_cx.cpp
Normal file
30
test/bit_floor_test_cx.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// constexpr test for boost/core/bit.hpp (bit_floor)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC / 10 == 191
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC is " BOOST_STRINGIZE(BOOST_MSVC) )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::bit_floor( (unsigned char)0x74 ) == 0x40 );
|
||||
STATIC_ASSERT( boost::core::bit_floor( (unsigned short)0x7400 ) == 0x4000 );
|
||||
STATIC_ASSERT( boost::core::bit_floor( 0x740000u ) == 0x400000u );
|
||||
STATIC_ASSERT( boost::core::bit_floor( 0x74000000ul ) == 0x40000000ul );
|
||||
STATIC_ASSERT( boost::core::bit_floor( 0x7400000000ull ) == 0x4000000000ull );
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
// Test for boost/core/bit.hpp (bit_ceil)
|
||||
// Test for boost/core/bit.hpp (popcount)
|
||||
//
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
@@ -14,7 +14,7 @@
|
||||
template<class T> void test_popcount( T x )
|
||||
{
|
||||
int k = 0;
|
||||
for( T y = x; y; y &= y - 1, ++k );
|
||||
for( T y = x; y; y = static_cast<T>( y & (y - 1) ), ++k );
|
||||
|
||||
BOOST_TEST_EQ( boost::core::popcount( x ), k ) || ( std::cerr << "x: " << +x << std::endl );
|
||||
}
|
||||
|
||||
30
test/bit_popcount_test_cx.cpp
Normal file
30
test/bit_popcount_test_cx.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// constexpr test for boost/core/bit.hpp (popcount)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER / 10 == 191
|
||||
# pragma warning(disable: 4307) // '*': integral constant overflow
|
||||
#endif
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::popcount( (unsigned char)0x74 ) == 4 );
|
||||
STATIC_ASSERT( boost::core::popcount( (unsigned short)0x7400 ) == 4 );
|
||||
STATIC_ASSERT( boost::core::popcount( 0x740000u ) == 4 );
|
||||
STATIC_ASSERT( boost::core::popcount( 0x74000000ul ) == 4 );
|
||||
STATIC_ASSERT( boost::core::popcount( 0x7400000000ull ) == 4 );
|
||||
|
||||
#endif
|
||||
@@ -20,7 +20,7 @@ template<class T> void test_rotate( T x )
|
||||
BOOST_TEST_EQ( +boost::core::rotl( x, -i ), +boost::core::rotr( x, i ) );
|
||||
|
||||
unsigned const width = std::numeric_limits<T>::digits;
|
||||
unsigned r = i & ( width - 1 );
|
||||
unsigned r = static_cast<unsigned>( i ) & ( width - 1 );
|
||||
|
||||
if( r == 0 )
|
||||
{
|
||||
|
||||
33
test/bit_rotate_test_cx.cpp
Normal file
33
test/bit_rotate_test_cx.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// constexpr test for boost/core/bit.hpp (rotl, rotr)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::rotl( (std::uint8_t)0x11, 1 ) == 0x22 );
|
||||
STATIC_ASSERT( boost::core::rotr( (std::uint8_t)0x11, 1 ) == 0x88 );
|
||||
|
||||
STATIC_ASSERT( boost::core::rotl( (std::uint16_t)0x1111, 1 ) == 0x2222 );
|
||||
STATIC_ASSERT( boost::core::rotr( (std::uint16_t)0x1111, 1 ) == 0x8888 );
|
||||
|
||||
STATIC_ASSERT( boost::core::rotl( (std::uint32_t)0x11111111, 1 ) == 0x22222222 );
|
||||
STATIC_ASSERT( boost::core::rotr( (std::uint32_t)0x11111111, 1 ) == 0x88888888 );
|
||||
|
||||
STATIC_ASSERT( boost::core::rotl( (std::uint64_t)0x1111111111111111, 1 ) == 0x2222222222222222 );
|
||||
STATIC_ASSERT( boost::core::rotr( (std::uint64_t)0x1111111111111111, 1 ) == 0x8888888888888888 );
|
||||
|
||||
#endif
|
||||
@@ -24,7 +24,7 @@ int main()
|
||||
|
||||
x = 1;
|
||||
|
||||
for( int i = 0; i < 8; ++i, x <<= 1 )
|
||||
for( int i = 0; i < 8; ++i, x = static_cast<boost::uint8_t>( x << 1 ) )
|
||||
{
|
||||
BOOST_TEST_EQ( boost::core::bit_width( x ), i+1 );
|
||||
BOOST_TEST_EQ( boost::core::bit_width( static_cast<boost::uint8_t>( x | ( x >> 1 ) ) ), i+1 );
|
||||
@@ -39,7 +39,7 @@ int main()
|
||||
|
||||
x = 1;
|
||||
|
||||
for( int i = 0; i < 16; ++i, x <<= 1 )
|
||||
for( int i = 0; i < 16; ++i, x = static_cast<boost::uint16_t>( x << 1 ) )
|
||||
{
|
||||
BOOST_TEST_EQ( boost::core::bit_width( x ), i+1 );
|
||||
BOOST_TEST_EQ( boost::core::bit_width( static_cast<boost::uint16_t>( x | ( x >> 1 ) ) ), i+1 );
|
||||
|
||||
30
test/bit_width_test_cx.cpp
Normal file
30
test/bit_width_test_cx.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// constexpr test for boost/core/bit.hpp (bit_width)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC / 10 == 191
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC is " BOOST_STRINGIZE(BOOST_MSVC) )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::bit_width( (unsigned char)0x74 ) == 7 );
|
||||
STATIC_ASSERT( boost::core::bit_width( (unsigned short)0x7400 ) == 15 );
|
||||
STATIC_ASSERT( boost::core::bit_width( 0x740000u ) == 23 );
|
||||
STATIC_ASSERT( boost::core::bit_width( 0x74000000ul ) == 31 );
|
||||
STATIC_ASSERT( boost::core::bit_width( 0x7400000000ull ) == 39 );
|
||||
|
||||
#endif
|
||||
@@ -28,7 +28,7 @@ int main()
|
||||
|
||||
x = 2;
|
||||
|
||||
for( int i = 1; i < 8; ++i, x <<= 1 )
|
||||
for( int i = 1; i < 8; ++i, x = static_cast<boost::uint8_t>( x << 1 ) )
|
||||
{
|
||||
BOOST_TEST_EQ( boost::core::has_single_bit( x ), true );
|
||||
BOOST_TEST_EQ( boost::core::has_single_bit( static_cast<boost::uint8_t>( x | ( x >> 1 ) ) ), false );
|
||||
@@ -47,7 +47,7 @@ int main()
|
||||
|
||||
x = 2;
|
||||
|
||||
for( int i = 1; i < 16; ++i, x <<= 1 )
|
||||
for( int i = 1; i < 16; ++i, x = static_cast<boost::uint16_t>( x << 1 ) )
|
||||
{
|
||||
BOOST_TEST_EQ( boost::core::has_single_bit( x ), true );
|
||||
BOOST_TEST_EQ( boost::core::has_single_bit( static_cast<boost::uint16_t>( x | ( x >> 1 ) ) ), false );
|
||||
|
||||
35
test/has_single_bit_test_cx.cpp
Normal file
35
test/has_single_bit_test_cx.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// constexpr test for boost/core/bit.hpp (has_single_bit)
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/core/bit.hpp>
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
STATIC_ASSERT( boost::core::has_single_bit( (unsigned char)0x80 ) == true );
|
||||
STATIC_ASSERT( boost::core::has_single_bit( (unsigned char)0x90 ) == false );
|
||||
|
||||
STATIC_ASSERT( boost::core::has_single_bit( (unsigned short)0x8000 ) == true );
|
||||
STATIC_ASSERT( boost::core::has_single_bit( (unsigned short)0x9000 ) == false );
|
||||
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x800000u ) == true );
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x900000u ) == false );
|
||||
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x80000000ul ) == true );
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x90000000ul ) == false );
|
||||
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x8000000000ull ) == true );
|
||||
STATIC_ASSERT( boost::core::has_single_bit( 0x9000000000ull ) == false );
|
||||
|
||||
#endif
|
||||
69
test/identity_rvalue_test.cpp
Normal file
69
test/identity_rvalue_test.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
Copyright 2021-2023 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#include <boost/core/identity.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
bool test(std::string&&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test(const std::string&&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool test(T&&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void simple_test()
|
||||
{
|
||||
typedef std::string string;
|
||||
BOOST_TEST(boost::identity()(string("a")) == string("a"));
|
||||
BOOST_TEST(test(boost::identity()(string("a"))));
|
||||
typedef const std::string cstring;
|
||||
BOOST_TEST(boost::identity()(cstring("a")) == cstring("a"));
|
||||
BOOST_TEST(test(boost::identity()(cstring("a"))));
|
||||
}
|
||||
|
||||
void algorithm_test()
|
||||
{
|
||||
std::vector<std::string> v1;
|
||||
v1.push_back(std::string("a"));
|
||||
v1.push_back(std::string("b"));
|
||||
v1.push_back(std::string("c"));
|
||||
std::vector<std::string> v2(v1);
|
||||
std::vector<std::string> v3;
|
||||
std::transform(std::make_move_iterator(v2.begin()),
|
||||
std::make_move_iterator(v2.end()),
|
||||
std::back_inserter(v3),
|
||||
boost::identity());
|
||||
BOOST_TEST(v3 == v1);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
simple_test();
|
||||
algorithm_test();
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
66
test/identity_test.cpp
Normal file
66
test/identity_test.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright 2021-2023 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/identity.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
bool test(std::string&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test(const std::string&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool test(T&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool test(const T&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void simple_test()
|
||||
{
|
||||
std::string s1("a");
|
||||
BOOST_TEST(boost::identity()(s1) == s1);
|
||||
BOOST_TEST(&boost::identity()(s1) == &s1);
|
||||
BOOST_TEST(test(boost::identity()(s1)));
|
||||
const std::string s2("a");
|
||||
BOOST_TEST(boost::identity()(s2) == s2);
|
||||
BOOST_TEST(&boost::identity()(s2) == &s2);
|
||||
BOOST_TEST(test(boost::identity()(s2)));
|
||||
}
|
||||
|
||||
void algorithm_test()
|
||||
{
|
||||
std::vector<std::string> v1;
|
||||
v1.push_back(std::string("a"));
|
||||
v1.push_back(std::string("b"));
|
||||
v1.push_back(std::string("c"));
|
||||
std::vector<std::string> v2;
|
||||
std::transform(v1.begin(), v1.end(), std::back_inserter(v2),
|
||||
boost::identity());
|
||||
BOOST_TEST(v2 == v1);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
simple_test();
|
||||
algorithm_test();
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -54,16 +54,9 @@ int main()
|
||||
BOOST_TEST_GE( boost::core::max_align, boost::alignment_of<void (X::*)()>::value );
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALIGNOF) && !defined(BOOST_NO_STD_MAX_ALIGN_T)
|
||||
# if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 70000
|
||||
|
||||
// libstdc++ 7 adds __float128 to std::max_align_t, but we always have it
|
||||
BOOST_TEST_GE( boost::core::max_align, alignof( std::max_align_t ) );
|
||||
|
||||
# else
|
||||
|
||||
BOOST_TEST_EQ( boost::core::max_align, alignof( std::max_align_t ) );
|
||||
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
|
||||
15
test/sp_thread_pause_test.cpp
Normal file
15
test/sp_thread_pause_test.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
// Test for sp_thread_pause
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/core/yield_primitives.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
for( int i = 0; i < 1048576; ++i )
|
||||
{
|
||||
boost::core::sp_thread_pause();
|
||||
}
|
||||
}
|
||||
15
test/sp_thread_sleep_test.cpp
Normal file
15
test/sp_thread_sleep_test.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
// Test for sp_thread_sleep
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/core/yield_primitives.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
for( int i = 0; i < 100; ++i )
|
||||
{
|
||||
boost::core::sp_thread_sleep();
|
||||
}
|
||||
}
|
||||
15
test/sp_thread_yield_test.cpp
Normal file
15
test/sp_thread_yield_test.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
// Test for sp_thread_yield
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/core/yield_primitives.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
for( int i = 0; i < 10000; ++i )
|
||||
{
|
||||
boost::core::sp_thread_yield();
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,19 @@
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <iterator>
|
||||
|
||||
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 160000
|
||||
|
||||
// std::char_traits<Ch> is deprecated for non-char types
|
||||
typedef wchar_t Ch;
|
||||
|
||||
#else
|
||||
|
||||
struct Ch
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::core::basic_string_view<Ch> ch_string_view;
|
||||
|
||||
@@ -47,10 +47,14 @@ class B
|
||||
{
|
||||
};
|
||||
|
||||
class C;
|
||||
|
||||
template<class T1, class T2> struct X
|
||||
{
|
||||
};
|
||||
|
||||
template<class T1, class T2> struct Y;
|
||||
|
||||
enum E1
|
||||
{
|
||||
e1
|
||||
@@ -63,6 +67,8 @@ enum class E2
|
||||
e2
|
||||
};
|
||||
|
||||
enum class E3;
|
||||
|
||||
#endif
|
||||
|
||||
struct Ch
|
||||
@@ -115,12 +121,14 @@ int main()
|
||||
|
||||
TEST(A);
|
||||
TEST(B);
|
||||
TEST(C);
|
||||
|
||||
TEST(E1);
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
|
||||
|
||||
TEST(E2);
|
||||
TEST(E3);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -131,6 +139,10 @@ int main()
|
||||
TEST(B&);
|
||||
TEST(B const&);
|
||||
|
||||
TEST(C volatile);
|
||||
TEST(C&);
|
||||
TEST(C const&);
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
|
||||
TEST(B&&);
|
||||
@@ -141,6 +153,9 @@ int main()
|
||||
TEST(A*);
|
||||
TEST(B const* volatile*);
|
||||
|
||||
TEST(C*);
|
||||
TEST(C const* volatile*);
|
||||
|
||||
TEST(void*);
|
||||
TEST(void const* volatile*);
|
||||
|
||||
@@ -239,9 +254,18 @@ int main()
|
||||
TEST(B(&)[1][2][3]);
|
||||
TEST(B const volatile(***)[1][2][3]);
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || !defined(BOOST_MSVC)
|
||||
|
||||
TEST(int A::*);
|
||||
TEST(int const B::*);
|
||||
|
||||
#else
|
||||
|
||||
boost::core::type_name<int A::*>();
|
||||
boost::core::type_name<int const B::*>();
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
TEST(void(A::*)());
|
||||
@@ -249,6 +273,13 @@ int main()
|
||||
TEST(void(A::*)() volatile);
|
||||
TEST(void(A::*)() const volatile);
|
||||
|
||||
#else
|
||||
|
||||
boost::core::type_name<void(A::*)()>();
|
||||
boost::core::type_name<void(A::*)() const>();
|
||||
boost::core::type_name<void(A::*)() volatile>();
|
||||
boost::core::type_name<void(A::*)() const volatile>();
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_REF_QUALIFIERS)
|
||||
@@ -274,10 +305,16 @@ int main()
|
||||
TEST(std::pair<A, B>);
|
||||
TEST(std::pair<A const*, B*> volatile&);
|
||||
|
||||
TEST(std::pair<C, C>);
|
||||
|
||||
TEST(std::pair<void, void>);
|
||||
TEST(std::pair<std::pair<void, void>, void>);
|
||||
|
||||
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 160000
|
||||
// std::char_traits<Ch> is deprecated for non-char types
|
||||
#else
|
||||
TEST(std::basic_string<Ch>);
|
||||
#endif
|
||||
|
||||
TEST(std::string);
|
||||
TEST(std::wstring);
|
||||
@@ -298,6 +335,11 @@ int main()
|
||||
TEST(X<A, B>);
|
||||
TEST(X<A const&, B&> volatile&);
|
||||
|
||||
TEST(X<C, C>);
|
||||
|
||||
TEST(Y<A, B>);
|
||||
TEST(Y<C, C>);
|
||||
|
||||
TEST(X<std::pair<void, void>, void>);
|
||||
|
||||
TEST(std::vector<int>);
|
||||
@@ -364,7 +406,11 @@ int main()
|
||||
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
|
||||
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 160000
|
||||
// std::char_traits<Ch> is deprecated for non-char types
|
||||
#else
|
||||
TEST(std::basic_string_view<Ch>);
|
||||
#endif
|
||||
|
||||
TEST(std::string_view);
|
||||
TEST(std::wstring_view);
|
||||
|
||||
54
test/yield_prim_pthread_cancel_test.cpp
Normal file
54
test/yield_prim_pthread_cancel_test.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
// Test that yield primitives aren't cancelation points
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/core/yield_primitives.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(BOOST_HAS_PTHREADS)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_HAS_PTHREADS is not defined" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
pthread_mutex_t s_mx = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void* threadfunc( void* )
|
||||
{
|
||||
pthread_mutex_lock( &s_mx );
|
||||
pthread_mutex_unlock( &s_mx );
|
||||
|
||||
boost::core::sp_thread_pause();
|
||||
boost::core::sp_thread_yield();
|
||||
boost::core::sp_thread_sleep();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_mutex_lock( &s_mx );
|
||||
|
||||
pthread_t th;
|
||||
pthread_create( &th, 0, threadfunc, 0 );
|
||||
|
||||
pthread_cancel( th );
|
||||
|
||||
pthread_mutex_unlock( &s_mx );
|
||||
|
||||
void* r;
|
||||
pthread_join( th, &r );
|
||||
|
||||
BOOST_TEST_EQ( r, (void*)0 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
18
test/yield_prim_windows_h_test.cpp
Normal file
18
test/yield_prim_windows_h_test.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// Test for yield_primitives.hpp compatibility with windows.h
|
||||
//
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <boost/core/yield_primitives.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::core::sp_thread_pause();
|
||||
boost::core::sp_thread_yield();
|
||||
boost::core::sp_thread_sleep();
|
||||
}
|
||||
Reference in New Issue
Block a user