forked from boostorg/variant2
Compare commits
87 Commits
feature/gc
...
boost-1.83
Author | SHA1 | Date | |
---|---|---|---|
e2546b70ca | |||
362224a009 | |||
2c590716ab | |||
82b98fb757 | |||
30afb9e183 | |||
129e27ce09 | |||
26595285d3 | |||
95a8c5ffec | |||
ec2819a05e | |||
fcf9746a2d | |||
a74ebd34dc | |||
1b34c20685 | |||
604d3700ad | |||
4d1fd43d72 | |||
376925a209 | |||
bcb8796225 | |||
a948b85c74 | |||
32862d6db7 | |||
423d350ff1 | |||
aad1f86fae | |||
1f8c4a1900 | |||
67a12199e6 | |||
457147d1b0 | |||
4a5f3dc498 | |||
6fe1c69bc8 | |||
78a974429a | |||
4c5f254b9c | |||
c633a953de | |||
8ee7c5aad0 | |||
d34658f4c8 | |||
5e2bce1baa | |||
573ef77382 | |||
f6cad272d4 | |||
3fc7540733 | |||
e4b4b3f02b | |||
44d38c4111 | |||
1ebfb3b689 | |||
8af1fbde8e | |||
26ce33597d | |||
c89713b978 | |||
10c441c8d7 | |||
09ec260780 | |||
2da13befd7 | |||
e668c099ce | |||
aebcb9792d | |||
8fd9f830a9 | |||
ed4bebff3d | |||
ad06c9b923 | |||
de4eb8b6d2 | |||
4d69db1441 | |||
095d9770c4 | |||
cca476fbbc | |||
c76af4d3cf | |||
1af7b165cf | |||
49bff72be0 | |||
59780ba08e | |||
edd70cfd66 | |||
86c2782dff | |||
dce8174550 | |||
9d40bc80f1 | |||
be6ddf9fdc | |||
4153a535a0 | |||
f374ad68a3 | |||
3bc9a57c9b | |||
3ca95a65df | |||
ae1f72671e | |||
a2dab8c7d3 | |||
f39a71ed2f | |||
06dde96400 | |||
8be0a4a5fe | |||
90cda5339f | |||
afb0aafd64 | |||
f586dc8848 | |||
20b9175932 | |||
fb3ce863ff | |||
8ec0bf448a | |||
6d19e6be68 | |||
d8552b23ae | |||
f44aba09a2 | |||
99cc1db385 | |||
6d848c5af6 | |||
3c9f4e56bf | |||
3015e56bcb | |||
7c37053950 | |||
60995edb41 | |||
6de876954a | |||
453b00dec8 |
383
.drone.jsonnet
Normal file
383
.drone.jsonnet
Normal file
@ -0,0 +1,383 @@
|
||||
# Copyright 2022 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
local library = "variant2";
|
||||
|
||||
local triggers =
|
||||
{
|
||||
branch: [ "master", "develop", "feature/*" ]
|
||||
};
|
||||
|
||||
local ubsan = { UBSAN: '1', UBSAN_OPTIONS: 'print_stacktrace=1' };
|
||||
local asan = { ASAN: '1' };
|
||||
|
||||
local linux_pipeline(name, image, environment, packages = "", sources = [], arch = "amd64") =
|
||||
{
|
||||
name: name,
|
||||
kind: "pipeline",
|
||||
type: "docker",
|
||||
trigger: triggers,
|
||||
platform:
|
||||
{
|
||||
os: "linux",
|
||||
arch: arch
|
||||
},
|
||||
steps:
|
||||
[
|
||||
{
|
||||
name: "everything",
|
||||
image: image,
|
||||
environment: environment,
|
||||
commands:
|
||||
[
|
||||
'set -e',
|
||||
'wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -',
|
||||
] +
|
||||
(if sources != [] then [ ('apt-add-repository "' + source + '"') for source in sources ] else []) +
|
||||
(if packages != "" then [ 'apt-get update', 'apt-get -y install ' + packages ] else []) +
|
||||
[
|
||||
'export LIBRARY=' + library,
|
||||
'./.drone/drone.sh',
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
local macos_pipeline(name, environment, xcode_version = "12.2", osx_version = "catalina", arch = "amd64") =
|
||||
{
|
||||
name: name,
|
||||
kind: "pipeline",
|
||||
type: "exec",
|
||||
trigger: triggers,
|
||||
platform: {
|
||||
"os": "darwin",
|
||||
"arch": arch
|
||||
},
|
||||
node: {
|
||||
"os": osx_version
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
name: "everything",
|
||||
environment: environment + { "DEVELOPER_DIR": "/Applications/Xcode-" + xcode_version + ".app/Contents/Developer" },
|
||||
commands:
|
||||
[
|
||||
'export LIBRARY=' + library,
|
||||
'./.drone/drone.sh',
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
{
|
||||
name: name,
|
||||
kind: "pipeline",
|
||||
type: "docker",
|
||||
trigger: triggers,
|
||||
platform:
|
||||
{
|
||||
os: "windows",
|
||||
arch: arch
|
||||
},
|
||||
"steps":
|
||||
[
|
||||
{
|
||||
name: "everything",
|
||||
image: image,
|
||||
environment: environment,
|
||||
commands:
|
||||
[
|
||||
'cmd /C .drone\\\\drone.bat ' + library,
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
[
|
||||
linux_pipeline(
|
||||
"Linux 14.04 GCC 4.8* 32/64",
|
||||
"cppalliance/droneubuntu1404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 14.04 GCC 4.9 32/64",
|
||||
"cppalliance/droneubuntu1404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-4.9', CXXSTD: '03,11', ADDRMD: '32,64' },
|
||||
"g++-4.9-multilib",
|
||||
[ "ppa:ubuntu-toolchain-r/test" ],
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 GCC 5* 32/64",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 GCC 6 32/64",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-6', CXXSTD: '03,11,14', ADDRMD: '32,64' },
|
||||
"g++-6-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 GCC 7* 32/64",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 GCC 8 32/64",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-8', CXXSTD: '03,11,14,17', ADDRMD: '32,64' },
|
||||
"g++-8-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* 32/64",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* ARM64",
|
||||
"cppalliance/droneubuntu2004:multiarch",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' },
|
||||
arch="arm64",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* S390x",
|
||||
"cppalliance/droneubuntu2004:multiarch",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' },
|
||||
arch="s390x",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 10 32/64",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '32,64' },
|
||||
"g++-10-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 GCC 11* 32/64",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 GCC 12 32 ASAN",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32' } + asan,
|
||||
"g++-12-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 GCC 12 64 ASAN",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '64' } + asan,
|
||||
"g++-12-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 23.04 GCC 13 32/64",
|
||||
"cppalliance/droneubuntu2304:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32,64' },
|
||||
"g++-13-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.5",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.5', CXXSTD: '03,11' },
|
||||
"clang-3.5",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.6",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.6', CXXSTD: '03,11,14' },
|
||||
"clang-3.6",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.7",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.7', CXXSTD: '03,11,14' },
|
||||
"clang-3.7",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.8",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.8', CXXSTD: '03,11,14' },
|
||||
"clang-3.8",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 Clang 3.9",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-3.9', CXXSTD: '03,11,14' },
|
||||
"clang-3.9",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 Clang 4.0",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-4.0', CXXSTD: '03,11,14' },
|
||||
"clang-4.0",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 Clang 5.0",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-5.0', CXXSTD: '03,11,14,1z' },
|
||||
"clang-5.0",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 Clang 6.0",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-6.0', CXXSTD: '03,11,14,17' },
|
||||
"clang-6.0",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 Clang 7",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-7', CXXSTD: '03,11,14,17' },
|
||||
"clang-7",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 Clang 8",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-8', CXXSTD: '03,11,14,17' },
|
||||
"clang-8",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 Clang 9",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-9', CXXSTD: '03,11,14,17,2a' },
|
||||
"clang-9",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 Clang 10",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-10', CXXSTD: '03,11,14,17,2a' },
|
||||
"clang-10",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 Clang 11",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-11', CXXSTD: '03,11,14,17,2a' },
|
||||
"clang-11",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 Clang 12",
|
||||
"cppalliance/droneubuntu2004:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-12', CXXSTD: '03,11,14,17,2a' },
|
||||
"clang-12",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 13",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-13', CXXSTD: '03,11,14,17,20,2b' },
|
||||
"clang-13",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 14",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20,2b' },
|
||||
"clang-14",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 15 UBSAN",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '03,11,14,17,20,2b' } + ubsan,
|
||||
"clang-15",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 15 ASAN",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '03,11,14,17,20,2b' } + asan,
|
||||
"clang-15",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 23.04 Clang 16",
|
||||
"cppalliance/droneubuntu2304:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-16', CXXSTD: '03,11,14,17,20,2b' },
|
||||
"clang-16",
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 UBSAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + ubsan,
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 ASAN",
|
||||
{ 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' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2017 msvc-14.1",
|
||||
"cppalliance/dronevs2017",
|
||||
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2017 msvc-14.1 Strict",
|
||||
"cppalliance/dronevs2017",
|
||||
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest', CXXFLAGS: '/permissive-' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2019 msvc-14.2",
|
||||
"cppalliance/dronevs2019",
|
||||
{ TOOLSET: 'msvc-14.2', CXXSTD: '14,17,20,latest' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2019 msvc-14.2 Strict",
|
||||
"cppalliance/dronevs2019",
|
||||
{ TOOLSET: 'msvc-14.2', CXXSTD: '14,17,20,latest', CXXFLAGS: '/permissive-' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2022 msvc-14.3",
|
||||
"cppalliance/dronevs2022:1",
|
||||
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17,20,latest' },
|
||||
),
|
||||
]
|
24
.drone/drone.bat
Normal file
24
.drone/drone.bat
Normal file
@ -0,0 +1,24 @@
|
||||
@REM Copyright 2022 Peter Dimov
|
||||
@REM Distributed under the Boost Software License, Version 1.0.
|
||||
@REM https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
@ECHO ON
|
||||
|
||||
set LIBRARY=%1
|
||||
set DRONE_BUILD_DIR=%CD%
|
||||
|
||||
set BOOST_BRANCH=develop
|
||||
if "%DRONE_BRANCH%" == "master" set BOOST_BRANCH=master
|
||||
cd ..
|
||||
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
git submodule update --init tools/boostdep
|
||||
xcopy /s /e /q %DRONE_BUILD_DIR% libs\%LIBRARY%\
|
||||
python tools/boostdep/depinst/depinst.py %LIBRARY%
|
||||
cmd /c bootstrap
|
||||
b2 -d0 headers
|
||||
|
||||
if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
|
||||
if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
|
||||
if not "%CXXFLAGS%" == "" set CXXFLAGS=cxxflags=%CXXFLAGS%
|
||||
b2 -j3 libs/%LIBRARY%/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% %CXXFLAGS% variant=debug,release embed-manifest-via=linker
|
25
.drone/drone.sh
Executable file
25
.drone/drone.sh
Executable file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2022 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
set -ex
|
||||
export PATH=~/.local/bin:/usr/local/bin:$PATH
|
||||
|
||||
DRONE_BUILD_DIR=$(pwd)
|
||||
|
||||
BOOST_BRANCH=develop
|
||||
if [ "$DRONE_BRANCH" = "master" ]; then BOOST_BRANCH=master; fi
|
||||
|
||||
cd ..
|
||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
git submodule update --init tools/boostdep
|
||||
cp -r $DRONE_BUILD_DIR/* libs/$LIBRARY
|
||||
python tools/boostdep/depinst/depinst.py $LIBRARY
|
||||
./bootstrap.sh
|
||||
./b2 -d0 headers
|
||||
|
||||
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
|
||||
./b2 -j3 libs/$LIBRARY/test toolset=$TOOLSET cxxstd=$CXXSTD variant=debug,release ${ADDRMD:+address-model=$ADDRMD} ${UBSAN:+undefined-sanitizer=norecover debug-symbols=on} ${ASAN:+address-sanitizer=norecover debug-symbols=on} ${LINKFLAGS:+linkflags=$LINKFLAGS}
|
505
.github/workflows/ci.yml
vendored
505
.github/workflows/ci.yml
vendored
@ -17,105 +17,154 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- toolset: gcc-4.7
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-16.04
|
||||
install: g++-4.7
|
||||
- toolset: gcc-4.8
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: g++-4.8
|
||||
- toolset: gcc-4.9
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-16.04
|
||||
install: g++-4.9
|
||||
- toolset: gcc-5
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: g++-5
|
||||
- toolset: gcc-6
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: g++-6
|
||||
- toolset: gcc-7
|
||||
cxxstd: "03,11,14,17"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
- toolset: gcc-8
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-20.04
|
||||
install: g++-8
|
||||
- toolset: gcc-9
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-20.04
|
||||
- toolset: gcc-10
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-18.04
|
||||
- toolset: clang
|
||||
compiler: clang++-3.5
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.5
|
||||
- toolset: clang
|
||||
compiler: clang++-3.6
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.6
|
||||
- toolset: clang
|
||||
compiler: clang++-3.7
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.7
|
||||
- toolset: clang
|
||||
compiler: clang++-3.8
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.8
|
||||
os: ubuntu-20.04
|
||||
install: g++-10
|
||||
- toolset: gcc-11
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: g++-11
|
||||
- toolset: gcc-12
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install: g++-12
|
||||
- toolset: gcc-13
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:23.04
|
||||
install: g++-13
|
||||
- toolset: clang
|
||||
compiler: clang++-3.9
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: clang-3.9
|
||||
- toolset: clang
|
||||
compiler: clang++-4.0
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: clang-4.0
|
||||
- toolset: clang
|
||||
compiler: clang++-5.0
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install: clang-5.0
|
||||
- toolset: clang
|
||||
compiler: clang++-6.0
|
||||
cxxstd: "03,11,14,17"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-20.04
|
||||
install: clang-6.0
|
||||
- toolset: clang
|
||||
compiler: clang++-7
|
||||
cxxstd: "03,11,14,17"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-20.04
|
||||
install: clang-7
|
||||
- toolset: clang
|
||||
compiler: clang++-8
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
cxxstd: "03,11,14,17"
|
||||
os: ubuntu-20.04
|
||||
install: clang-8
|
||||
- toolset: clang
|
||||
compiler: clang++-9
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: clang-9
|
||||
- toolset: clang
|
||||
compiler: clang++-10
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: clang-10
|
||||
- toolset: clang
|
||||
compiler: clang++-11
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: clang-11
|
||||
- toolset: clang
|
||||
compiler: clang++-12
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: clang-12
|
||||
- toolset: clang
|
||||
compiler: clang++-13
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install: clang-13
|
||||
- toolset: clang
|
||||
compiler: clang++-14
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install: clang-14
|
||||
- toolset: clang
|
||||
compiler: clang++-15
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install: clang-15
|
||||
- toolset: clang
|
||||
compiler: clang++-16
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:23.04
|
||||
install: clang-16
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: macos-10.15
|
||||
os: macos-11
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: macos-12
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: macos-13
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
container: ${{matrix.container}}
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup container environment
|
||||
if: matrix.container
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get -y install sudo python3 git g++
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
run: sudo apt install ${{matrix.install}}
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install ${{matrix.install}}
|
||||
|
||||
- name: Setup Boost
|
||||
run: |
|
||||
@ -135,7 +184,7 @@ jobs:
|
||||
cd boost-root
|
||||
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
|
||||
python3 tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
|
||||
./bootstrap.sh
|
||||
./b2 -d0 headers
|
||||
|
||||
@ -154,14 +203,22 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- toolset: msvc-14.1
|
||||
cxxstd: "14,17,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2016
|
||||
- toolset: msvc-14.2
|
||||
cxxstd: "14,17,latest"
|
||||
- toolset: msvc-14.0
|
||||
cxxstd: "14,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2019
|
||||
- toolset: msvc-14.2
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2019
|
||||
- toolset: msvc-14.3
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2022
|
||||
- toolset: clang-win
|
||||
cxxstd: "14,17,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2022
|
||||
- toolset: gcc
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
addrmd: 64
|
||||
@ -170,7 +227,7 @@ jobs:
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
@ -198,4 +255,346 @@ jobs:
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root
|
||||
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release
|
||||
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker
|
||||
|
||||
posix-cmake-subdir:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: macos-13
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
run: sudo apt-get -y install ${{matrix.install}}
|
||||
|
||||
- name: Setup Boost
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
|
||||
LIBRARY=${GITHUB_REPOSITORY#*/}
|
||||
echo LIBRARY: $LIBRARY
|
||||
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
|
||||
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
|
||||
echo GITHUB_REF: $GITHUB_REF
|
||||
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
|
||||
REF=${REF#refs/heads/}
|
||||
echo REF: $REF
|
||||
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
|
||||
echo BOOST_BRANCH: $BOOST_BRANCH
|
||||
cd ..
|
||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
cp -r $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
|
||||
run: |
|
||||
cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test
|
||||
mkdir __build__ && cd __build__
|
||||
cmake ..
|
||||
cmake --build .
|
||||
ctest --output-on-failure --no-tests=error
|
||||
|
||||
posix-cmake-install:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: macos-13
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
run: sudo apt-get -y install ${{matrix.install}}
|
||||
|
||||
- name: Setup Boost
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
|
||||
LIBRARY=${GITHUB_REPOSITORY#*/}
|
||||
echo LIBRARY: $LIBRARY
|
||||
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
|
||||
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
|
||||
echo GITHUB_REF: $GITHUB_REF
|
||||
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
|
||||
REF=${REF#refs/heads/}
|
||||
echo REF: $REF
|
||||
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
|
||||
echo BOOST_BRANCH: $BOOST_BRANCH
|
||||
cd ..
|
||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cd ../boost-root
|
||||
mkdir __build__ && cd __build__
|
||||
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local ..
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target install
|
||||
|
||||
- name: Use the installed library
|
||||
run: |
|
||||
cd ../boost-root/libs/$LIBRARY/test/cmake_install_test && mkdir __build__ && cd __build__
|
||||
cmake -DCMAKE_INSTALL_PREFIX=~/.local ..
|
||||
cmake --build .
|
||||
ctest --output-on-failure --no-tests=error
|
||||
|
||||
posix-cmake-test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: macos-13
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
run: sudo apt-get -y install ${{matrix.install}}
|
||||
|
||||
- name: Setup Boost
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
|
||||
LIBRARY=${GITHUB_REPOSITORY#*/}
|
||||
echo LIBRARY: $LIBRARY
|
||||
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
|
||||
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
|
||||
echo GITHUB_REF: $GITHUB_REF
|
||||
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
|
||||
REF=${REF#refs/heads/}
|
||||
echo REF: $REF
|
||||
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
|
||||
echo BOOST_BRANCH: $BOOST_BRANCH
|
||||
cd ..
|
||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cd ../boost-root
|
||||
mkdir __build__ && cd __build__
|
||||
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON ..
|
||||
|
||||
- name: Build tests
|
||||
run: |
|
||||
cd ../boost-root/__build__
|
||||
cmake --build . --target tests
|
||||
|
||||
- name: Run tests
|
||||
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
|
||||
|
68
.travis.yml
68
.travis.yml
@ -1,4 +1,4 @@
|
||||
# Copyright 2016-2019 Peter Dimov
|
||||
# Copyright 2016-2021 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
@ -95,7 +95,7 @@ matrix:
|
||||
- os: linux
|
||||
dist: bionic
|
||||
compiler: g++-10
|
||||
env: TOOLSET=gcc COMPILER=g++-10 CXXSTD=11,14,17,2a
|
||||
env: UBSAN=1 TOOLSET=gcc COMPILER=g++-10 CXXSTD=11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
@ -103,21 +103,6 @@ matrix:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-8
|
||||
env: UBSAN=1 TOOLSET=gcc COMPILER=g++-8 CXXSTD=11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: clang++
|
||||
env: DIST=trusty TOOLSET=clang COMPILER=clang++ CXXSTD=11,14,1z
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.5
|
||||
env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=11,14,1z
|
||||
@ -180,6 +165,7 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: bionic
|
||||
compiler: clang++-5.0
|
||||
env: TOOLSET=clang COMPILER=clang++-5.0 CXXSTD=11,14,1z
|
||||
addons:
|
||||
@ -190,6 +176,7 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: bionic
|
||||
compiler: clang++-6.0
|
||||
env: TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=11,14,17
|
||||
addons:
|
||||
@ -200,6 +187,7 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: bionic
|
||||
compiler: clang++-7
|
||||
env: TOOLSET=clang COMPILER=clang++-7 CXXSTD=11,14,17,2a
|
||||
addons:
|
||||
@ -208,9 +196,10 @@ matrix:
|
||||
- clang-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-xenial-7
|
||||
- llvm-toolchain-bionic-7
|
||||
|
||||
- os: linux
|
||||
dist: bionic
|
||||
compiler: clang++-8
|
||||
env: TOOLSET=clang COMPILER=clang++-8 CXXSTD=11,14,17,2a
|
||||
addons:
|
||||
@ -219,10 +208,10 @@ matrix:
|
||||
- clang-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-xenial-8
|
||||
- llvm-toolchain-bionic-8
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: clang++-9
|
||||
env: TOOLSET=clang COMPILER=clang++-9 CXXSTD=11,14,17,2a
|
||||
addons:
|
||||
@ -231,11 +220,11 @@ matrix:
|
||||
- clang-9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main'
|
||||
- sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
|
||||
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: clang++-10
|
||||
env: TOOLSET=clang COMPILER=clang++-10 CXXSTD=11,14,17,2a
|
||||
addons:
|
||||
@ -244,19 +233,34 @@ matrix:
|
||||
- clang-10
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main'
|
||||
- sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main'
|
||||
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-8
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-8 CXXSTD=11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1
|
||||
dist: bionic
|
||||
compiler: clang++-11
|
||||
env: TOOLSET=clang COMPILER=clang++-11 CXXSTD=11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-8
|
||||
- clang-11
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-xenial-8
|
||||
- sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main'
|
||||
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
|
||||
|
||||
- os: linux
|
||||
dist: bionic
|
||||
compiler: clang++-12
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-12 CXXSTD=11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-12
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main'
|
||||
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
@ -268,18 +272,14 @@ matrix:
|
||||
- libc++-dev
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
dist: bionic
|
||||
compiler: clang++-libc++
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=11,14,1z UBSAN_OPTIONS=print_stacktrace=1
|
||||
env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libc++-dev
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=11,14,1z
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++ CXXSTD=11,14,1z UBSAN_OPTIONS=print_stacktrace=1
|
||||
@ -288,7 +288,7 @@ matrix:
|
||||
env: CMAKE_TEST=1
|
||||
script:
|
||||
- mkdir __build__ && cd __build__
|
||||
- cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=variant2 ..
|
||||
- cmake -DBOOST_ENABLE_CMAKE=1 -DBUILD_TESTING=ON -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=variant2 ..
|
||||
- ctest --output-on-failure -R boost_variant2
|
||||
|
||||
- os: linux
|
||||
|
@ -1,8 +1,9 @@
|
||||
# Copyright 2018, 2019 Peter Dimov
|
||||
# Generated by `boostdep --cmake variant2`
|
||||
# Copyright 2020, 2021 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# http://www.boost.org/LICENSE_1_0.txt
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.16)
|
||||
cmake_minimum_required(VERSION 3.8...3.20)
|
||||
|
||||
project(boost_variant2 VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
|
||||
|
||||
@ -13,11 +14,23 @@ target_include_directories(boost_variant2 INTERFACE include)
|
||||
|
||||
target_link_libraries(boost_variant2
|
||||
INTERFACE
|
||||
Boost::assert
|
||||
Boost::config
|
||||
Boost::mp11
|
||||
)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.18 AND CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||
|
||||
file(GLOB_RECURSE boost_variant2_IDEFILES CONFIGURE_DEPENDS include/*.hpp)
|
||||
source_group(TREE ${PROJECT_SOURCE_DIR}/include FILES ${boost_variant2_IDEFILES} PREFIX "Header Files")
|
||||
list(APPEND boost_variant2_IDEFILES extra/boost_variant2.natvis)
|
||||
target_sources(boost_variant2 PRIVATE ${boost_variant2_IDEFILES})
|
||||
|
||||
endif()
|
||||
|
||||
target_compile_features(boost_variant2 INTERFACE cxx_std_11)
|
||||
|
||||
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
|
||||
|
||||
add_subdirectory(test)
|
||||
|
||||
|
15
README.md
15
README.md
@ -1,21 +1,18 @@
|
||||
# variant2
|
||||
# Boost.Variant2
|
||||
|
||||
This repository contains a never-valueless, strong guarantee, C++11/14/17
|
||||
implementation of [std::variant](http://en.cppreference.com/w/cpp/utility/variant).
|
||||
See [the documentation](https://www.boost.org/libs/variant2)
|
||||
for more information.
|
||||
|
||||
The code requires [Boost.Mp11](https://github.com/boostorg/mp11) and
|
||||
Boost.Config.
|
||||
|
||||
The library is part of Boost, starting from release 1.71, but the header
|
||||
`variant.hpp` will also work [standalone](https://godbolt.org/z/nVUNKX).
|
||||
The library is part of Boost, starting from release 1.71. It depends on
|
||||
Boost.Mp11, Boost.Config, and Boost.Assert.
|
||||
|
||||
Supported compilers:
|
||||
|
||||
* g++ 4.8 or later with `-std=c++11` or above
|
||||
* clang++ 3.5 or later with `-std=c++11` or above
|
||||
* Visual Studio 2015, 2017, 2019
|
||||
* clang++ 3.9 or later with `-std=c++11` or above
|
||||
* Visual Studio 2015 or later
|
||||
|
||||
Tested on [Travis](https://travis-ci.org/boostorg/variant2/) and
|
||||
Tested on [Github Actions](https://github.com/boostorg/variant2/actions) and
|
||||
[Appveyor](https://ci.appveyor.com/project/pdimov/variant2-fkab9).
|
||||
|
49
appveyor.yml
49
appveyor.yml
@ -1,4 +1,4 @@
|
||||
# Copyright 2016-2020 Peter Dimov
|
||||
# Copyright 2016-2021 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
@ -20,15 +20,26 @@ environment:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: msvc-14.1
|
||||
ADDRMD: 32,64
|
||||
CXXSTD: 14,17
|
||||
CXXSTD: 14,17,latest
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: msvc-14.1
|
||||
ADDRMD: 32,64
|
||||
CXXSTD: 14,17,latest
|
||||
CXXFLAGS: /permissive-
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: clang-win
|
||||
ADDRMD: 64
|
||||
CXXSTD: 14,17
|
||||
CXXSTD: 14,17,latest
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: msvc-14.2
|
||||
ADDRMD: 32,64
|
||||
CXXSTD: 14,17
|
||||
TOOLSET: clang-win
|
||||
ADDRMD: 64
|
||||
CXXSTD: 14,17,latest
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
CMAKE: 1
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
CMAKE_SUBDIR: 1
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
CMAKE_INSTALL: 1
|
||||
|
||||
install:
|
||||
- set BOOST_BRANCH=develop
|
||||
@ -47,4 +58,28 @@ build: off
|
||||
test_script:
|
||||
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
|
||||
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
|
||||
- b2 -j3 libs/variant2/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release
|
||||
- if not "%CXXFLAGS%" == "" set CXXFLAGS=cxxflags=%CXXFLAGS%
|
||||
- if "%CMAKE%%CMAKE_SUBDIR%%CMAKE_INSTALL%" == "" b2 -j3 libs/variant2/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% %CXXFLAGS% variant=debug,release embed-manifest-via=linker
|
||||
|
||||
- if not "%CMAKE%" == "" mkdir __build__ && cd __build__
|
||||
- if not "%CMAKE%" == "" cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=variant2 -DBoost_VERBOSE=ON ..
|
||||
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config Debug & ctest --output-on-failure --no-tests=error -j 3 -C Debug
|
||||
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config Release & ctest --output-on-failure --no-tests=error -j 3 -C Release
|
||||
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config MinSizeRel & ctest --output-on-failure --no-tests=error -j 3 -C MinSizeRel
|
||||
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config RelWithDebInfo & ctest --output-on-failure --no-tests=error -j 3 -C RelWithDebInfo
|
||||
|
||||
- if not "%CMAKE_SUBDIR%" == "" cd libs/variant2/test/cmake_subdir_test && mkdir __build__ && cd __build__
|
||||
- if not "%CMAKE_SUBDIR%" == "" cmake ..
|
||||
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config Debug && cmake --build . --target check --config Debug
|
||||
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config Release && cmake --build . --target check --config Release
|
||||
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config MinSizeRel && cmake --build . --target check --config MinSizeRel
|
||||
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config RelWithDebInfo && cmake --build . --target check --config RelWithDebInfo
|
||||
|
||||
- if not "%CMAKE_INSTALL%" == "" mkdir __build__ && cd __build__
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake -DBOOST_INCLUDE_LIBRARIES=variant2 -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Debug
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Release
|
||||
- if not "%CMAKE_INSTALL%" == "" cd ../libs/variant2/test/cmake_install_test && mkdir __build__ && cd __build__
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake --build . --config Debug && cmake --build . --target check --config Debug
|
||||
- if not "%CMAKE_INSTALL%" == "" cmake --build . --config Release && cmake --build . --target check --config Release
|
||||
|
@ -13,6 +13,8 @@ Peter Dimov
|
||||
:toclevels: 4
|
||||
:idprefix:
|
||||
:docinfo: private-footer
|
||||
:source-highlighter: rouge
|
||||
:source-language: c++
|
||||
|
||||
:leveloffset: +1
|
||||
|
||||
|
@ -1,16 +1,36 @@
|
||||
////
|
||||
Copyright 2019, 2020 Peter Dimov
|
||||
|
||||
Copyright 2019-2022 Peter Dimov
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt
|
||||
https://www.boost.org/LICENSE_1_0.txt
|
||||
////
|
||||
|
||||
[#changelog]
|
||||
# Revision History
|
||||
:idprefix: changelog_
|
||||
|
||||
## Changes in 1.83.0
|
||||
|
||||
* Added `uses_double_storage()`.
|
||||
|
||||
## Changes in 1.81.0
|
||||
|
||||
* Added support for `boost::json::value_from` and `boost::json::value_to`.
|
||||
|
||||
## Changes in 1.79.0
|
||||
|
||||
* Added `operator<<` for `monostate`.
|
||||
|
||||
## Changes in 1.78.0
|
||||
|
||||
* Added `<boost/variant2.hpp>`.
|
||||
* Added `unsafe_get<I>`.
|
||||
* Added `visit_by_index`.
|
||||
* Added `operator<<`.
|
||||
|
||||
## Changes in 1.76.0
|
||||
|
||||
* Improved generated code for the double buffered case.
|
||||
|
||||
## Changes in 1.74.0
|
||||
|
||||
* Added support for derived types in `visit`
|
||||
|
@ -169,6 +169,10 @@ The main differences between this implementation and `std::variant` are:
|
||||
`variant<int, float>` is provided as the member function `subset<U...>`.
|
||||
(This operation can throw if the current state of the variant cannot be
|
||||
represented.)
|
||||
* `unsafe_get`, an unchecked alternative to `get` and `get_if`, is provided
|
||||
as an extension.
|
||||
* `visit_by_index`, a visitation function that takes a single variant and a
|
||||
number of function objects, one per alternative, is provided as an extension.
|
||||
* The {cpp}20 additions and changes to `std::variant` have not yet been
|
||||
implemented.
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
////
|
||||
Copyright 2019 Peter Dimov
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt
|
||||
https://www.boost.org/LICENSE_1_0.txt
|
||||
////
|
||||
|
||||
[#implementation]
|
||||
@ -13,13 +10,13 @@ http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
## Dependencies
|
||||
|
||||
This implementation only depends on Boost.Config and Boost.Mp11.
|
||||
This implementation only depends on Boost.Config, Boost.Assert, and Boost.Mp11.
|
||||
|
||||
## Supported Compilers
|
||||
|
||||
* GCC 4.8 or later with `-std=c++11` or above
|
||||
* Clang 3.5 or later with `-std=c++11` or above
|
||||
* Visual Studio 2015, 2017, 2019
|
||||
* Clang 3.9 or later with `-std=c++11` or above
|
||||
* Visual Studio 2015 or later
|
||||
|
||||
Tested on https://travis-ci.org/boostorg/variant2/[Travis] and
|
||||
Tested on https://github.com/boostorg/variant2/actions[Github Actions] and
|
||||
https://ci.appveyor.com/project/pdimov/variant2-fkab9[Appveyor].
|
||||
|
@ -1,10 +1,7 @@
|
||||
////
|
||||
Copyright 2018, 2019 Peter Dimov
|
||||
|
||||
Copyright 2018-2021 Peter Dimov
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt
|
||||
https://www.boost.org/LICENSE_1_0.txt
|
||||
////
|
||||
|
||||
[#reference]
|
||||
@ -117,6 +114,21 @@ template<class U, class... T>
|
||||
constexpr add_pointer_t<const U>
|
||||
get_if(const variant<T...>* v) noexcept;
|
||||
|
||||
// unsafe_get (extension)
|
||||
|
||||
template<size_t I, class... T>
|
||||
constexpr variant_alternative_t<I, variant<T...>>&
|
||||
unsafe_get(variant<T...>& v);
|
||||
template<size_t I, class... T>
|
||||
constexpr variant_alternative_t<I, variant<T...>>&&
|
||||
unsafe_get(variant<T...>&& v);
|
||||
template<size_t I, class... T>
|
||||
constexpr const variant_alternative_t<I, variant<T...>>&
|
||||
unsafe_get(const variant<T...>& v);
|
||||
template<size_t I, class... T>
|
||||
constexpr const variant_alternative_t<I, variant<T...>>&&
|
||||
unsafe_get(const variant<T...>&& v);
|
||||
|
||||
// relational operators
|
||||
|
||||
template<class... T>
|
||||
@ -132,11 +144,21 @@ template<class... T>
|
||||
template<class... T>
|
||||
constexpr bool operator>=(const variant<T...>& v, const variant<T...>& w);
|
||||
|
||||
// swap
|
||||
|
||||
template<class... T>
|
||||
void swap(variant<T...>& v, variant<T...>& w) noexcept( /*see below*/ );
|
||||
|
||||
// visit
|
||||
|
||||
template<class R = /*unspecified*/, class F, class... V>
|
||||
constexpr /*see below*/ visit(F&& f, V&&... v);
|
||||
|
||||
// visit_by_index (extension)
|
||||
|
||||
template<class R = /*unspecified*/, class V, class... F>
|
||||
constexpr /*see below*/ visit_by_index(V&& v, F&&.. f);
|
||||
|
||||
// monostate
|
||||
|
||||
struct monostate {};
|
||||
@ -148,10 +170,15 @@ constexpr bool operator>(monostate, monostate) noexcept { return false; }
|
||||
constexpr bool operator<=(monostate, monostate) noexcept { return true; }
|
||||
constexpr bool operator>=(monostate, monostate) noexcept { return true; }
|
||||
|
||||
// swap
|
||||
// stream insertion (extension)
|
||||
|
||||
template<class... T>
|
||||
void swap(variant<T...>& v, variant<T...>& w) noexcept( /*see below*/ );
|
||||
template<class Ch, class Tr, class... T>
|
||||
std::basic_ostream<Ch, Tr>&
|
||||
operator<<( std::basic_ostream<Ch, Tr>& os, variant<T...> const& v );
|
||||
|
||||
template<class Ch, class Tr>
|
||||
std::basic_ostream<Ch, Tr>&
|
||||
operator<<( std::basic_ostream<Ch, Tr>& os, monostate const& v );
|
||||
|
||||
// bad_variant_access
|
||||
|
||||
@ -223,6 +250,8 @@ public:
|
||||
constexpr bool valueless_by_exception() const noexcept;
|
||||
constexpr size_t index() const noexcept;
|
||||
|
||||
static constexpr bool uses_double_storage() noexcept;
|
||||
|
||||
// swap
|
||||
|
||||
void swap( variant& r ) noexcept( /*see below*/ );
|
||||
@ -490,8 +519,8 @@ template<size_t I, class... A>
|
||||
+
|
||||
Requires: :: `I < sizeof...(T)`.
|
||||
Effects: ::
|
||||
Destroys the currently contained value, then initializes a new contained
|
||||
value as if using the expression `Ti(std::forward<A>(a)...)`.
|
||||
Initializes a new contained value as if using the expression
|
||||
`Ti(std::forward<A>(a)...)`, then destroys the currently contained value.
|
||||
Ensures: :: `index() == I`.
|
||||
Returns: :: A reference to the new contained value.
|
||||
Throws: ::
|
||||
@ -511,8 +540,8 @@ template<size_t I, class V, class... A>
|
||||
+
|
||||
Requires: :: `I < sizeof...(T)`.
|
||||
Effects: ::
|
||||
Destroys the currently contained value, then initializes a new contained
|
||||
value as if using the expression `Ti(il, std::forward<A>(a)...)`.
|
||||
Initializes a new contained value as if using the expression
|
||||
`Ti(il, std::forward<A>(a)...)`, then destroys the currently contained value.
|
||||
Ensures: :: `index() == I`.
|
||||
Returns: :: A reference to the new contained value.
|
||||
Throws: ::
|
||||
@ -543,6 +572,18 @@ constexpr size_t index() const noexcept;
|
||||
Returns: ::
|
||||
The zero-based index of the active alternative.
|
||||
|
||||
```
|
||||
static constexpr bool uses_double_storage() noexcept;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: ::
|
||||
`true` if the variant uses double storage to meet the never valueless
|
||||
guarantee because one of the alternatives is not nothrow move constructible,
|
||||
and `false` otherwise.
|
||||
|
||||
|
||||
#### Swap
|
||||
|
||||
```
|
||||
@ -775,6 +816,34 @@ Requires: :: The type `U` occurs exactly once in `T...`. Otherwise, the
|
||||
Effects: :: Equivalent to: `return get_if<I>(v);` with `I` being
|
||||
the zero-based index of `U` in `T...`.
|
||||
|
||||
### unsafe_get (extension)
|
||||
|
||||
```
|
||||
template<size_t I, class... T>
|
||||
constexpr variant_alternative_t<I, variant<T...>>&
|
||||
unsafe_get(variant<T...>& v);
|
||||
```
|
||||
```
|
||||
template<size_t I, class... T>
|
||||
constexpr variant_alternative_t<I, variant<T...>>&&
|
||||
unsafe_get(variant<T...>&& v);
|
||||
```
|
||||
```
|
||||
template<size_t I, class... T>
|
||||
constexpr const variant_alternative_t<I, variant<T...>>&
|
||||
unsafe_get(const variant<T...>& v);
|
||||
```
|
||||
```
|
||||
template<size_t I, class... T>
|
||||
constexpr const variant_alternative_t<I, variant<T...>>&&
|
||||
unsafe_get(const variant<T...>&& v);
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Requires: :: `v.index() == I`.
|
||||
Returns: :: a reference to the object stored in the variant.
|
||||
|
||||
### Relational Operators
|
||||
|
||||
```
|
||||
@ -835,6 +904,18 @@ template<class... T>
|
||||
Returns: ::
|
||||
`w \<= v`.
|
||||
|
||||
### swap
|
||||
|
||||
```
|
||||
template<class... T>
|
||||
void swap(variant<T...>& v, variant<T...>& w) noexcept( /*see below*/ );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
Equivalent to `v.swap(w)`.
|
||||
|
||||
### visit
|
||||
|
||||
```
|
||||
@ -851,17 +932,50 @@ Remarks: :: If `R` is given explicitly, as in `visit<int>`, the return
|
||||
of `F` to the variant alternatives must have the same return type for
|
||||
this deduction to succeed.
|
||||
|
||||
### swap
|
||||
### visit_by_index (extension)
|
||||
|
||||
```
|
||||
template<class... T>
|
||||
void swap(variant<T...>& v, variant<T...>& w) noexcept( /*see below*/ );
|
||||
template<class R = /*unspecified*/, class V, class... F>
|
||||
constexpr /*see below*/ visit_by_index(V&& v, F&&.. f);
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Requires: :: `variant_size<V>::value == sizeof...(F)`, or the program is ill-formed.
|
||||
Returns: :: `std::forward<Fi>(fi)(get<i>(std::forward<V>(v)))`, where
|
||||
`i` is `v.index()` and `Fi` and `fi` are the `i`-th element of `F...` and `f...`
|
||||
accordingly.
|
||||
Remarks: :: If `R` is given explicitly, as in `visit_by_index<int>`, the return
|
||||
type is `R`. Otherwise, it's deduced from `F...` and `V`. All the applications
|
||||
of `Fi` to the corresponding variant alternatives must have the same return type
|
||||
for this deduction to succeed.
|
||||
|
||||
### Stream Insertion (extension)
|
||||
```
|
||||
template<class Ch, class Tr, class... T>
|
||||
std::basic_ostream<Ch, Tr>&
|
||||
operator<<( std::basic_ostream<Ch, Tr>& os, variant<T...> const& v );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Requires: ::
|
||||
`sizeof...(T) != 0`.
|
||||
Returns: ::
|
||||
`os << get<I>(v)`, where `I` is `v.index()`.
|
||||
|
||||
```
|
||||
template<class Ch, class Tr>
|
||||
std::basic_ostream<Ch, Tr>&
|
||||
operator<<( std::basic_ostream<Ch, Tr>& os, monostate const& v );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: ::
|
||||
Equivalent to `v.swap(w)`.
|
||||
`os << "monostate"`.
|
||||
Returns: ::
|
||||
`os`.
|
||||
|
||||
### bad_variant_access
|
||||
|
||||
@ -878,3 +992,7 @@ public:
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## <boost/variant2.hpp>
|
||||
|
||||
This convenience header includes `<boost/variant2/variant.hpp>`.
|
||||
|
32
extra/boost_variant2.natvis
Normal file
32
extra/boost_variant2.natvis
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||
|
||||
<Type Name="boost::variant2::detail::variant_ma_base_impl<*>" Inheritable="true">
|
||||
<Intrinsic Name="index" Expression="$T2==1?((int)ix_-1):((int)((ix_-2)/2))"/>
|
||||
<DisplayString Condition="index()==0&&$T2==1" Optional="true">{st_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==1&&$T2==1" Optional="true">{st_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==2&&$T2==1" Optional="true">{st_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==3&&$T2==1" Optional="true">{st_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==4&&$T2==1" Optional="true">{st_.rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==5&&$T2==1" Optional="true">{st_.rest_.rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==6&&$T2==1" Optional="true">{st_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==7&&$T2==1" Optional="true">{st_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==8&&$T2==1" Optional="true">{st_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==9&&$T2==1" Optional="true">{st_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==0&&$T2==0" Optional="true">{st_[ix_%2].rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==1&&$T2==0" Optional="true">{st_[ix_%2].rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==2&&$T2==0" Optional="true">{st_[ix_%2].rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==3&&$T2==0" Optional="true">{st_[ix_%2].rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==4&&$T2==0" Optional="true">{st_[ix_%2].rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==5&&$T2==0" Optional="true">{st_[ix_%2].rest_.rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==6&&$T2==0" Optional="true">{st_[ix_%2].rest_.rest_.rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==7&&$T2==0" Optional="true">{st_[ix_%2].rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==8&&$T2==0" Optional="true">{st_[ix_%2].rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<DisplayString Condition="index()==9&&$T2==0" Optional="true">{st_[ix_%2].rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.rest_.first_} ({index()})</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="[index]">index()</Item>
|
||||
<Item Name="ix_">ix_</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
</AutoVisualizer>
|
10
include/boost/variant2.hpp
Normal file
10
include/boost/variant2.hpp
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef BOOST_VARIANT2_HPP_INCLUDED
|
||||
#define BOOST_VARIANT2_HPP_INCLUDED
|
||||
|
||||
// Copyright 2021 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_VARIANT2_HPP_INCLUDED
|
@ -13,19 +13,21 @@
|
||||
# pragma warning( disable: 4521 4522 ) // multiple copy operators
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_MP11_HPP_INCLUDED
|
||||
#include <boost/mp11.hpp>
|
||||
#endif
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/assert/source_location.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <exception>
|
||||
#include <cassert>
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
#include <functional> // std::hash
|
||||
#include <iosfwd>
|
||||
#include <cstdint>
|
||||
#include <cerrno>
|
||||
|
||||
//
|
||||
|
||||
@ -38,6 +40,8 @@ BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined
|
||||
|
||||
#endif
|
||||
|
||||
template<class T> struct hash;
|
||||
|
||||
namespace variant2
|
||||
{
|
||||
|
||||
@ -81,6 +85,8 @@ struct monostate
|
||||
{
|
||||
};
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1940)
|
||||
|
||||
constexpr bool operator<(monostate, monostate) noexcept { return false; }
|
||||
constexpr bool operator>(monostate, monostate) noexcept { return false; }
|
||||
constexpr bool operator<=(monostate, monostate) noexcept { return true; }
|
||||
@ -88,6 +94,17 @@ constexpr bool operator>=(monostate, monostate) noexcept { return true; }
|
||||
constexpr bool operator==(monostate, monostate) noexcept { return true; }
|
||||
constexpr bool operator!=(monostate, monostate) noexcept { return false; }
|
||||
|
||||
#else
|
||||
|
||||
constexpr bool operator<(monostate const&, monostate const&) noexcept { return false; }
|
||||
constexpr bool operator>(monostate const&, monostate const&) noexcept { return false; }
|
||||
constexpr bool operator<=(monostate const&, monostate const&) noexcept { return true; }
|
||||
constexpr bool operator>=(monostate const&, monostate const&) noexcept { return true; }
|
||||
constexpr bool operator==(monostate const&, monostate const&) noexcept { return true; }
|
||||
constexpr bool operator!=(monostate const&, monostate const&) noexcept { return false; }
|
||||
|
||||
#endif
|
||||
|
||||
// variant forward declaration
|
||||
|
||||
template<class... T> class variant;
|
||||
@ -351,37 +368,50 @@ template<std::size_t I, class... T> constexpr variant_alternative_t<I, variant<T
|
||||
#endif
|
||||
}
|
||||
|
||||
// detail::unsafe_get (for visit)
|
||||
// unsafe_get
|
||||
|
||||
namespace detail
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
# define BOOST_VARIANT2_CX14_ASSERT(expr) BOOST_ASSERT(expr);
|
||||
#else
|
||||
# define BOOST_VARIANT2_CX14_ASSERT(expr)
|
||||
#endif
|
||||
|
||||
template<std::size_t I, class... T> constexpr variant_alternative_t<I, variant<T...>>& unsafe_get(variant<T...>& v)
|
||||
{
|
||||
static_assert( I < sizeof...(T), "Index out of bounds" );
|
||||
|
||||
BOOST_VARIANT2_CX14_ASSERT( v.index() == I )
|
||||
|
||||
return v._get_impl( mp11::mp_size_t<I>() );
|
||||
}
|
||||
|
||||
template<std::size_t I, class... T> constexpr variant_alternative_t<I, variant<T...>>&& unsafe_get(variant<T...>&& v)
|
||||
{
|
||||
static_assert( I < sizeof...(T), "Index out of bounds" );
|
||||
|
||||
BOOST_VARIANT2_CX14_ASSERT( v.index() == I )
|
||||
|
||||
return std::move( v._get_impl( mp11::mp_size_t<I>() ) );
|
||||
}
|
||||
|
||||
template<std::size_t I, class... T> constexpr variant_alternative_t<I, variant<T...>> const& unsafe_get(variant<T...> const& v)
|
||||
{
|
||||
static_assert( I < sizeof...(T), "Index out of bounds" );
|
||||
|
||||
BOOST_VARIANT2_CX14_ASSERT( v.index() == I )
|
||||
|
||||
return v._get_impl( mp11::mp_size_t<I>() );
|
||||
}
|
||||
|
||||
template<std::size_t I, class... T> constexpr variant_alternative_t<I, variant<T...>> const&& unsafe_get(variant<T...> const&& v)
|
||||
{
|
||||
static_assert( I < sizeof...(T), "Index out of bounds" );
|
||||
|
||||
BOOST_VARIANT2_CX14_ASSERT( v.index() == I )
|
||||
|
||||
return std::move( v._get_impl( mp11::mp_size_t<I>() ) );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// get (type)
|
||||
|
||||
template<class U, class... T> constexpr U& get(variant<T...>& v)
|
||||
@ -520,11 +550,11 @@ template<class T1, class... T> union variant_storage_impl<mp11::mp_false, T1, T.
|
||||
T1 first_;
|
||||
variant_storage<T...> rest_;
|
||||
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<0>, A&&... a ): first_( std::forward<A>(a)... )
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<0>, A&&... a ): first_( std::forward<A>(a)... )
|
||||
{
|
||||
}
|
||||
|
||||
template<std::size_t I, class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<I>, A&&... a ): rest_( mp11::mp_size_t<I-1>(), std::forward<A>(a)... )
|
||||
template<std::size_t I, class... A> constexpr variant_storage_impl( mp11::mp_size_t<I>, A&&... a ): rest_( mp11::mp_size_t<I-1>(), std::forward<A>(a)... )
|
||||
{
|
||||
}
|
||||
|
||||
@ -564,18 +594,18 @@ template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, c
|
||||
|
||||
variant_storage<T...> rest_;
|
||||
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<0>, A&&... a ): t0_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<1>, A&&... a ): t1_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<2>, A&&... a ): t2_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<3>, A&&... a ): t3_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<4>, A&&... a ): t4_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<5>, A&&... a ): t5_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<6>, A&&... a ): t6_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<7>, A&&... a ): t7_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<8>, A&&... a ): t8_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<9>, A&&... a ): t9_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<0>, A&&... a ): t0_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<1>, A&&... a ): t1_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<2>, A&&... a ): t2_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<3>, A&&... a ): t3_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<4>, A&&... a ): t4_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<5>, A&&... a ): t5_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<6>, A&&... a ): t6_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<7>, A&&... a ): t7_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<8>, A&&... a ): t8_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<9>, A&&... a ): t9_( std::forward<A>(a)... ) {}
|
||||
|
||||
template<std::size_t I, class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<I>, A&&... a ): rest_( mp11::mp_size_t<I-10>(), std::forward<A>(a)... ) {}
|
||||
template<std::size_t I, class... A> constexpr variant_storage_impl( mp11::mp_size_t<I>, A&&... a ): rest_( mp11::mp_size_t<I-10>(), std::forward<A>(a)... ) {}
|
||||
|
||||
~variant_storage_impl()
|
||||
{
|
||||
@ -637,11 +667,11 @@ template<class T1, class... T> union variant_storage_impl<mp11::mp_true, T1, T..
|
||||
T1 first_;
|
||||
variant_storage<T...> rest_;
|
||||
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<0>, A&&... a ): first_( std::forward<A>(a)... )
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<0>, A&&... a ): first_( std::forward<A>(a)... )
|
||||
{
|
||||
}
|
||||
|
||||
template<std::size_t I, class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<I>, A&&... a ): rest_( mp11::mp_size_t<I-1>(), std::forward<A>(a)... )
|
||||
template<std::size_t I, class... A> constexpr variant_storage_impl( mp11::mp_size_t<I>, A&&... a ): rest_( mp11::mp_size_t<I-1>(), std::forward<A>(a)... )
|
||||
{
|
||||
}
|
||||
|
||||
@ -657,7 +687,17 @@ template<class T1, class... T> union variant_storage_impl<mp11::mp_true, T1, T..
|
||||
|
||||
template<std::size_t I, class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_true, mp11::mp_size_t<I>, A&&... a )
|
||||
{
|
||||
#if defined(BOOST_GCC) && (__GNUC__ >= 7)
|
||||
# pragma GCC diagnostic push
|
||||
// False positive in at least GCC 7 and GCC 10 ASAN triggered by monostate (via result<void>)
|
||||
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
|
||||
*this = variant_storage_impl( mp11::mp_size_t<I>(), std::forward<A>(a)... );
|
||||
|
||||
#if defined(BOOST_GCC) && (__GNUC__ >= 7)
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
}
|
||||
|
||||
template<std::size_t I, class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<I>, A&&... a )
|
||||
@ -687,18 +727,18 @@ template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, c
|
||||
|
||||
variant_storage<T...> rest_;
|
||||
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<0>, A&&... a ): t0_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<1>, A&&... a ): t1_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<2>, A&&... a ): t2_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<3>, A&&... a ): t3_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<4>, A&&... a ): t4_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<5>, A&&... a ): t5_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<6>, A&&... a ): t6_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<7>, A&&... a ): t7_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<8>, A&&... a ): t8_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<9>, A&&... a ): t9_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<0>, A&&... a ): t0_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<1>, A&&... a ): t1_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<2>, A&&... a ): t2_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<3>, A&&... a ): t3_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<4>, A&&... a ): t4_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<5>, A&&... a ): t5_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<6>, A&&... a ): t6_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<7>, A&&... a ): t7_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<8>, A&&... a ): t8_( std::forward<A>(a)... ) {}
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<9>, A&&... a ): t9_( std::forward<A>(a)... ) {}
|
||||
|
||||
template<std::size_t I, class... A> constexpr explicit variant_storage_impl( mp11::mp_size_t<I>, A&&... a ): rest_( mp11::mp_size_t<I-10>(), std::forward<A>(a)... ) {}
|
||||
template<std::size_t I, class... A> constexpr variant_storage_impl( mp11::mp_size_t<I>, A&&... a ): rest_( mp11::mp_size_t<I-10>(), std::forward<A>(a)... ) {}
|
||||
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<0>, A&&... a ) { ::new( &t0_ ) T0( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<1>, A&&... a ) { ::new( &t1_ ) T1( std::forward<A>(a)... ); }
|
||||
@ -814,21 +854,21 @@ struct none {};
|
||||
// trivially destructible, single buffered
|
||||
template<class... T> struct variant_base_impl<true, true, T...>
|
||||
{
|
||||
int ix_;
|
||||
variant_storage<none, T...> st1_;
|
||||
variant_storage<none, T...> st_;
|
||||
unsigned ix_;
|
||||
|
||||
constexpr variant_base_impl(): ix_( 0 ), st1_( mp11::mp_size_t<0>() )
|
||||
constexpr variant_base_impl(): st_( mp11::mp_size_t<0>() ), ix_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
template<class I, class... A> constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... )
|
||||
template<class I, class... A> constexpr explicit variant_base_impl( I, A&&... a ): st_( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... ), ix_( I::value + 1 )
|
||||
{
|
||||
}
|
||||
|
||||
// requires: ix_ == 0
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &st1_ ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
::new( &st_ ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
ix_ = I::value + 1;
|
||||
}
|
||||
|
||||
@ -841,24 +881,25 @@ template<class... T> struct variant_base_impl<true, true, T...>
|
||||
{
|
||||
size_t const J = I+1;
|
||||
|
||||
assert( ix_ == J );
|
||||
BOOST_ASSERT( ix_ == J );
|
||||
|
||||
return st1_.get( mp11::mp_size_t<J>() );
|
||||
return st_.get( mp11::mp_size_t<J>() );
|
||||
}
|
||||
|
||||
template<std::size_t I> constexpr mp11::mp_at_c<variant<T...>, I> const& _get_impl( mp11::mp_size_t<I> ) const noexcept
|
||||
{
|
||||
// size_t const J = I+1;
|
||||
// assert( ix_ == I+1 );
|
||||
|
||||
return st1_.get( mp11::mp_size_t<I+1>() );
|
||||
BOOST_VARIANT2_CX14_ASSERT( ix_ == I+1 )
|
||||
|
||||
return st_.get( mp11::mp_size_t<I+1>() );
|
||||
}
|
||||
|
||||
template<std::size_t J, class U, class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_true, A&&... a )
|
||||
{
|
||||
static_assert( std::is_nothrow_constructible<U, A&&...>::value, "Logic error: U must be nothrow constructible from A&&..." );
|
||||
|
||||
st1_.emplace( mp11::mp_size_t<J>(), std::forward<A>(a)... );
|
||||
st_.emplace( mp11::mp_size_t<J>(), std::forward<A>(a)... );
|
||||
ix_ = J;
|
||||
}
|
||||
|
||||
@ -868,7 +909,7 @@ template<class... T> struct variant_base_impl<true, true, T...>
|
||||
|
||||
U tmp( std::forward<A>(a)... );
|
||||
|
||||
st1_.emplace( mp11::mp_size_t<J>(), std::move(tmp) );
|
||||
st_.emplace( mp11::mp_size_t<J>(), std::move(tmp) );
|
||||
ix_ = J;
|
||||
}
|
||||
|
||||
@ -879,89 +920,94 @@ template<class... T> struct variant_base_impl<true, true, T...>
|
||||
|
||||
this->emplace_impl<J, U>( std::is_nothrow_constructible<U, A&&...>(), std::forward<A>(a)... );
|
||||
}
|
||||
|
||||
static constexpr bool uses_double_storage() noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// trivially destructible, double buffered
|
||||
template<class... T> struct variant_base_impl<true, false, T...>
|
||||
{
|
||||
int ix_;
|
||||
variant_storage<none, T...> st1_;
|
||||
variant_storage<none, T...> st2_;
|
||||
variant_storage<none, T...> st_[ 2 ];
|
||||
unsigned ix_;
|
||||
|
||||
constexpr variant_base_impl(): ix_( 0 ), st1_( mp11::mp_size_t<0>() ), st2_( mp11::mp_size_t<0>() )
|
||||
constexpr variant_base_impl(): st_{ { mp11::mp_size_t<0>() }, { mp11::mp_size_t<0>() } }, ix_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
template<class I, class... A> constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... ), st2_( mp11::mp_size_t<0>() )
|
||||
template<class I, class... A> constexpr explicit variant_base_impl( I, A&&... a ): st_{ { mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... }, { mp11::mp_size_t<0>() } }, ix_( ( I::value + 1 ) * 2 )
|
||||
{
|
||||
}
|
||||
|
||||
// requires: ix_ == 0
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &st1_ ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
ix_ = I::value + 1;
|
||||
::new( &st_[ 0 ] ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
ix_ = ( I::value + 1 ) * 2;
|
||||
}
|
||||
|
||||
constexpr std::size_t index() const noexcept
|
||||
{
|
||||
return ix_ >= 0? ix_ - 1: -ix_ - 1;
|
||||
return ix_ / 2 - 1;
|
||||
}
|
||||
|
||||
template<std::size_t I> BOOST_CXX14_CONSTEXPR mp11::mp_at_c<variant<T...>, I>& _get_impl( mp11::mp_size_t<I> ) noexcept
|
||||
{
|
||||
BOOST_ASSERT( index() == I );
|
||||
|
||||
size_t const J = I+1;
|
||||
|
||||
assert( ix_ == J || -ix_ == J );
|
||||
|
||||
constexpr mp11::mp_size_t<J> j{};
|
||||
return ix_ >= 0? st1_.get( j ): st2_.get( j );
|
||||
return st_[ ix_ & 1 ].get( j );
|
||||
}
|
||||
|
||||
template<std::size_t I> constexpr mp11::mp_at_c<variant<T...>, I> const& _get_impl( mp11::mp_size_t<I> ) const noexcept
|
||||
{
|
||||
BOOST_VARIANT2_CX14_ASSERT( index() == I )
|
||||
|
||||
// size_t const J = I+1;
|
||||
// assert( ix_ == J || -ix_ == J );
|
||||
// constexpr mp_size_t<J> j{};
|
||||
|
||||
return ix_ >= 0? st1_.get( mp11::mp_size_t<I+1>() ): st2_.get( mp11::mp_size_t<I+1>() );
|
||||
return st_[ ix_ & 1 ].get( mp11::mp_size_t<I+1>() );
|
||||
}
|
||||
|
||||
template<std::size_t I, class... A> BOOST_CXX14_CONSTEXPR void emplace( A&&... a )
|
||||
{
|
||||
size_t const J = I+1;
|
||||
|
||||
if( ix_ >= 0 )
|
||||
{
|
||||
st2_.emplace( mp11::mp_size_t<J>(), std::forward<A>(a)... );
|
||||
ix_ = -static_cast<int>( J );
|
||||
}
|
||||
else
|
||||
{
|
||||
st1_.emplace( mp11::mp_size_t<J>(), std::forward<A>(a)... );
|
||||
ix_ = J;
|
||||
}
|
||||
unsigned i2 = 1 - ( ix_ & 1 );
|
||||
|
||||
st_[ i2 ].emplace( mp11::mp_size_t<J>(), std::forward<A>(a)... );
|
||||
|
||||
ix_ = J * 2 + i2;
|
||||
}
|
||||
|
||||
static constexpr bool uses_double_storage() noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// not trivially destructible, single buffered
|
||||
template<class... T> struct variant_base_impl<false, true, T...>
|
||||
{
|
||||
int ix_;
|
||||
variant_storage<none, T...> st1_;
|
||||
variant_storage<none, T...> st_;
|
||||
unsigned ix_;
|
||||
|
||||
constexpr variant_base_impl(): ix_( 0 ), st1_( mp11::mp_size_t<0>() )
|
||||
constexpr variant_base_impl(): st_( mp11::mp_size_t<0>() ), ix_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
template<class I, class... A> constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... )
|
||||
template<class I, class... A> constexpr explicit variant_base_impl( I, A&&... a ): st_( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... ), ix_( I::value + 1 )
|
||||
{
|
||||
}
|
||||
|
||||
// requires: ix_ == 0
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &st1_ ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
::new( &st_ ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
ix_ = I::value + 1;
|
||||
}
|
||||
|
||||
@ -977,7 +1023,7 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
template<class I> void operator()( I ) const noexcept
|
||||
{
|
||||
using U = mp11::mp_at<mp11::mp_list<none, T...>, I>;
|
||||
this_->st1_.get( I() ).~U();
|
||||
this_->st_.get( I() ).~U();
|
||||
}
|
||||
};
|
||||
|
||||
@ -1003,17 +1049,18 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
{
|
||||
size_t const J = I+1;
|
||||
|
||||
assert( ix_ == J );
|
||||
BOOST_ASSERT( ix_ == J );
|
||||
|
||||
return st1_.get( mp11::mp_size_t<J>() );
|
||||
return st_.get( mp11::mp_size_t<J>() );
|
||||
}
|
||||
|
||||
template<std::size_t I> constexpr mp11::mp_at_c<variant<T...>, I> const& _get_impl( mp11::mp_size_t<I> ) const noexcept
|
||||
{
|
||||
// size_t const J = I+1;
|
||||
// assert( ix_ == J );
|
||||
|
||||
return st1_.get( mp11::mp_size_t<I+1>() );
|
||||
BOOST_VARIANT2_CX14_ASSERT( ix_ == I+1 )
|
||||
|
||||
return st_.get( mp11::mp_size_t<I+1>() );
|
||||
}
|
||||
|
||||
template<std::size_t I, class... A> void emplace( A&&... a )
|
||||
@ -1028,31 +1075,74 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
|
||||
_destroy();
|
||||
|
||||
st1_.emplace( mp11::mp_size_t<J>(), std::move(tmp) );
|
||||
st_.emplace( mp11::mp_size_t<J>(), std::move(tmp) );
|
||||
ix_ = J;
|
||||
}
|
||||
|
||||
static constexpr bool uses_double_storage() noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// not trivially destructible, double buffered
|
||||
template<class... T> struct variant_base_impl<false, false, T...>
|
||||
{
|
||||
int ix_;
|
||||
variant_storage<none, T...> st1_;
|
||||
variant_storage<none, T...> st2_;
|
||||
#if defined(__GNUC__) && __GNUC__ < 11 && !defined(__clang__) && !defined(__INTEL_COMPILER)
|
||||
|
||||
constexpr variant_base_impl(): ix_( 0 ), st1_( mp11::mp_size_t<0>() ), st2_( mp11::mp_size_t<0>() )
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63707 :-(
|
||||
|
||||
variant_storage<none, T...> st1_, st2_;
|
||||
unsigned ix_;
|
||||
|
||||
constexpr variant_base_impl(): st1_( mp11::mp_size_t<0>() ), st2_( mp11::mp_size_t<0>() ), ix_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
template<class I, class... A> constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... ), st2_( mp11::mp_size_t<0>() )
|
||||
template<class I, class... A> constexpr explicit variant_base_impl( I, A&&... a ): st1_( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... ), st2_( mp11::mp_size_t<0>() ), ix_( ( I::value + 1 ) * 2 )
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR variant_storage<none, T...>& storage( unsigned i2 ) noexcept
|
||||
{
|
||||
return i2 == 0? st1_: st2_;
|
||||
}
|
||||
|
||||
constexpr variant_storage<none, T...> const& storage( unsigned i2 ) const noexcept
|
||||
{
|
||||
return i2 == 0? st1_: st2_;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
variant_storage<none, T...> st_[ 2 ];
|
||||
unsigned ix_;
|
||||
|
||||
constexpr variant_base_impl(): st_{ { mp11::mp_size_t<0>() }, { mp11::mp_size_t<0>() } }, ix_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
template<class I, class... A> constexpr explicit variant_base_impl( I, A&&... a ): st_{ { mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... }, { mp11::mp_size_t<0>() } }, ix_( ( I::value + 1 ) * 2 )
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR variant_storage<none, T...>& storage( unsigned i2 ) noexcept
|
||||
{
|
||||
return st_[ i2 ];
|
||||
}
|
||||
|
||||
constexpr variant_storage<none, T...> const& storage( unsigned i2 ) const noexcept
|
||||
{
|
||||
return st_[ i2 ];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// requires: ix_ == 0
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &st1_ ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
ix_ = I::value + 1;
|
||||
::new( &storage( 0 ) ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
ix_ = ( I::value + 1 ) * 2;
|
||||
}
|
||||
|
||||
//[&]( auto I ){
|
||||
@ -1063,35 +1153,18 @@ template<class... T> struct variant_base_impl<false, false, T...>
|
||||
struct _destroy_L1
|
||||
{
|
||||
variant_base_impl * this_;
|
||||
unsigned i2_;
|
||||
|
||||
template<class I> void operator()( I ) const noexcept
|
||||
{
|
||||
using U = mp11::mp_at<mp11::mp_list<none, T...>, I>;
|
||||
this_->st1_.get( I() ).~U();
|
||||
}
|
||||
};
|
||||
|
||||
struct _destroy_L2
|
||||
{
|
||||
variant_base_impl * this_;
|
||||
|
||||
template<class I> void operator()( I ) const noexcept
|
||||
{
|
||||
using U = mp11::mp_at<mp11::mp_list<none, T...>, I>;
|
||||
this_->st2_.get( I() ).~U();
|
||||
this_->storage( i2_ ).get( I() ).~U();
|
||||
}
|
||||
};
|
||||
|
||||
void _destroy() noexcept
|
||||
{
|
||||
if( ix_ > 0 )
|
||||
{
|
||||
mp11::mp_with_index<1 + sizeof...(T)>( ix_, _destroy_L1{ this } );
|
||||
}
|
||||
else if( ix_ < 0 )
|
||||
{
|
||||
mp11::mp_with_index<1 + sizeof...(T)>( -ix_, _destroy_L2{ this } );
|
||||
}
|
||||
mp11::mp_with_index<1 + sizeof...(T)>( ix_ / 2, _destroy_L1{ this, ix_ & 1 } );
|
||||
}
|
||||
|
||||
~variant_base_impl() noexcept
|
||||
@ -1101,46 +1174,44 @@ template<class... T> struct variant_base_impl<false, false, T...>
|
||||
|
||||
constexpr std::size_t index() const noexcept
|
||||
{
|
||||
return ix_ >= 0? ix_ - 1: -ix_ - 1;
|
||||
return ix_ / 2 - 1;
|
||||
}
|
||||
|
||||
template<std::size_t I> BOOST_CXX14_CONSTEXPR mp11::mp_at_c<variant<T...>, I>& _get_impl( mp11::mp_size_t<I> ) noexcept
|
||||
{
|
||||
BOOST_ASSERT( index() == I );
|
||||
|
||||
size_t const J = I+1;
|
||||
|
||||
assert( ix_ == J || -ix_ == J );
|
||||
|
||||
constexpr mp11::mp_size_t<J> j{};
|
||||
return ix_ >= 0? st1_.get( j ): st2_.get( j );
|
||||
return storage( ix_ & 1 ).get( j );
|
||||
}
|
||||
|
||||
template<std::size_t I> constexpr mp11::mp_at_c<variant<T...>, I> const& _get_impl( mp11::mp_size_t<I> ) const noexcept
|
||||
{
|
||||
BOOST_VARIANT2_CX14_ASSERT( index() == I )
|
||||
|
||||
// size_t const J = I+1;
|
||||
// assert( ix_ == J || -ix_ == J );
|
||||
// constexpr mp_size_t<J> j{};
|
||||
|
||||
return ix_ >= 0? st1_.get( mp11::mp_size_t<I+1>() ): st2_.get( mp11::mp_size_t<I+1>() );
|
||||
return storage( ix_ & 1 ).get( mp11::mp_size_t<I+1>() );
|
||||
}
|
||||
|
||||
template<std::size_t I, class... A> void emplace( A&&... a )
|
||||
{
|
||||
size_t const J = I+1;
|
||||
|
||||
if( ix_ >= 0 )
|
||||
{
|
||||
st2_.emplace( mp11::mp_size_t<J>(), std::forward<A>(a)... );
|
||||
_destroy();
|
||||
unsigned i2 = 1 - ( ix_ & 1 );
|
||||
|
||||
ix_ = -static_cast<int>( J );
|
||||
}
|
||||
else
|
||||
{
|
||||
st1_.emplace( mp11::mp_size_t<J>(), std::forward<A>(a)... );
|
||||
_destroy();
|
||||
storage( i2 ).emplace( mp11::mp_size_t<J>(), std::forward<A>(a)... );
|
||||
_destroy();
|
||||
|
||||
ix_ = J;
|
||||
}
|
||||
ix_ = J * 2 + i2;
|
||||
}
|
||||
|
||||
static constexpr bool uses_double_storage() noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1561,7 +1632,7 @@ public:
|
||||
|
||||
template<class U,
|
||||
class Ud = typename std::decay<U>::type,
|
||||
class E1 = typename std::enable_if< !std::is_same<Ud, variant>::value && !detail::is_in_place_index<Ud>::value && !detail::is_in_place_type<Ud>::value >::type,
|
||||
class E1 = typename std::enable_if< !std::is_same<Ud, variant>::value && !std::is_base_of<variant, Ud>::value && !detail::is_in_place_index<Ud>::value && !detail::is_in_place_type<Ud>::value >::type,
|
||||
class V = detail::resolve_overload_type<U&&, T...>,
|
||||
class E2 = typename std::enable_if<std::is_constructible<V, U&&>::value>::type
|
||||
>
|
||||
@ -1652,6 +1723,8 @@ public:
|
||||
|
||||
using variant_base::index;
|
||||
|
||||
using variant_base::uses_double_storage;
|
||||
|
||||
// swap
|
||||
|
||||
private:
|
||||
@ -2085,7 +2158,7 @@ template<class R, class F, class V1, class V2> struct visit_L2
|
||||
template<class I> auto operator()( I ) const -> Vret<R, F, V1, V2>
|
||||
{
|
||||
auto f2 = bind_front( std::forward<F>(f), unsafe_get<I::value>( std::forward<V1>(v1) ) );
|
||||
return visit<R>( f2, std::forward<V2>(v2) );
|
||||
return visit<R>( f2, std::forward<V2>(v2) );
|
||||
}
|
||||
};
|
||||
|
||||
@ -2153,7 +2226,7 @@ template<class R = detail::deduced, class F, class V1, class V2, class... V> con
|
||||
{
|
||||
return mp11::mp_with_index<detail::variant_base_size<V1>>( v1.index(), [&]( auto I ){
|
||||
|
||||
auto f2 = [&]( auto&&... a ){ return std::forward<F>(f)( detail::unsafe_get<I.value>( std::forward<V1>(v1) ), std::forward<decltype(a)>(a)... ); };
|
||||
auto f2 = [&]( auto&&... a ){ return std::forward<F>(f)( unsafe_get<I.value>( std::forward<V1>(v1) ), std::forward<decltype(a)>(a)... ); };
|
||||
return visit<R>( f2, std::forward<V2>(v2), std::forward<V>(v)... );
|
||||
|
||||
});
|
||||
@ -2170,36 +2243,133 @@ void swap( variant<T...> & v, variant<T...> & w )
|
||||
v.swap( w );
|
||||
}
|
||||
|
||||
// visit_by_index
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class R, class V, class... F> using Vret2 = mp11::mp_eval_if_not< std::is_same<R, deduced>, R, front_if_same, mp11::mp_transform<mp11::mp_invoke_q, mp11::mp_list<Qret<F>...>, apply_cv_ref<V>> >;
|
||||
|
||||
template<class R, class V, class... F> struct visit_by_index_L
|
||||
{
|
||||
V&& v;
|
||||
std::tuple<F&&...> tp;
|
||||
|
||||
template<class I> constexpr detail::Vret2<R, V, F...> operator()( I ) const
|
||||
{
|
||||
return std::get<I::value>( std::move(tp) )( unsafe_get<I::value>( std::forward<V>(v) ) );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class R = detail::deduced, class V, class... F> constexpr auto visit_by_index( V&& v, F&&... f ) -> detail::Vret2<R, V, F...>
|
||||
{
|
||||
static_assert( variant_size<V>::value == sizeof...(F), "Incorrect number of function objects" );
|
||||
|
||||
return mp11::mp_with_index<variant_size<V>::value>( v.index(),
|
||||
detail::visit_by_index_L<R, V, F...>{ std::forward<V>(v), std::tuple<F&&...>( std::forward<F>(f)... ) } );
|
||||
}
|
||||
|
||||
// output streaming
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class Ch, class Tr, class... T> struct ostream_insert_L
|
||||
{
|
||||
std::basic_ostream<Ch, Tr>& os;
|
||||
variant<T...> const& v;
|
||||
|
||||
template<class I> std::basic_ostream<Ch, Tr>& operator()( I ) const
|
||||
{
|
||||
return os << unsafe_get<I::value>( v );
|
||||
}
|
||||
};
|
||||
|
||||
template<class Os, class T, class E = void> struct is_output_streamable: std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template<class Os, class T> struct is_output_streamable<Os, T, decltype( std::declval<Os&>() << std::declval<T const&>(), (void)0 )>: std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class Ch, class Tr>
|
||||
std::basic_ostream<Ch, Tr>& operator<<( std::basic_ostream<Ch, Tr>& os, monostate const& )
|
||||
{
|
||||
os << "monostate";
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class Ch, class Tr, class T1, class... T,
|
||||
class E = typename std::enable_if< mp11::mp_all< detail::is_output_streamable<std::basic_ostream<Ch, Tr>, T>... >::value >::type >
|
||||
std::basic_ostream<Ch, Tr>& operator<<( std::basic_ostream<Ch, Tr>& os, variant<T1, T...> const& v )
|
||||
{
|
||||
return mp11::mp_with_index<1 + sizeof...(T)>( v.index(),
|
||||
detail::ostream_insert_L<Ch, Tr, T1, T...>{ os, v } );
|
||||
}
|
||||
|
||||
// hashing support
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class V> struct hash_value_L
|
||||
inline std::size_t hash_value_impl_( mp11::mp_true, std::size_t index, std::size_t value )
|
||||
{
|
||||
boost::ulong_long_type hv = ( boost::ulong_long_type( 0xCBF29CE4 ) << 32 ) + 0x84222325;
|
||||
boost::ulong_long_type const prime = ( boost::ulong_long_type( 0x00000100 ) << 32 ) + 0x000001B3;
|
||||
|
||||
hv ^= index;
|
||||
hv *= prime;
|
||||
|
||||
hv ^= value;
|
||||
hv *= prime;
|
||||
|
||||
return static_cast<std::size_t>( hv );
|
||||
}
|
||||
|
||||
inline std::size_t hash_value_impl_( mp11::mp_false, std::size_t index, std::size_t value )
|
||||
{
|
||||
std::size_t hv = 0x811C9DC5;
|
||||
std::size_t const prime = 0x01000193;
|
||||
|
||||
hv ^= index;
|
||||
hv *= prime;
|
||||
|
||||
hv ^= value;
|
||||
hv *= prime;
|
||||
|
||||
return hv;
|
||||
}
|
||||
|
||||
inline std::size_t hash_value_impl( std::size_t index, std::size_t value )
|
||||
{
|
||||
return hash_value_impl_( mp11::mp_bool< (SIZE_MAX > UINT32_MAX) >(), index, value );
|
||||
}
|
||||
|
||||
template<template<class> class H, class V> struct hash_value_L
|
||||
{
|
||||
V const & v;
|
||||
|
||||
template<class I> std::size_t operator()( I ) const
|
||||
{
|
||||
boost::ulong_long_type hv = ( boost::ulong_long_type( 0xCBF29CE4 ) << 32 ) + 0x84222325;
|
||||
boost::ulong_long_type const prime = ( boost::ulong_long_type( 0x00000100 ) << 32 ) + 0x000001B3;
|
||||
|
||||
// index
|
||||
|
||||
hv ^= I::value;
|
||||
hv *= prime;
|
||||
|
||||
// value
|
||||
|
||||
auto const & t = unsafe_get<I::value>( v );
|
||||
|
||||
hv ^= std::hash<remove_cv_ref_t<decltype(t)>>()( t );
|
||||
hv *= prime;
|
||||
std::size_t index = I::value;
|
||||
std::size_t value = H<remove_cv_ref_t<decltype(t)>>()( t );
|
||||
|
||||
return static_cast<std::size_t>( hv );
|
||||
return hash_value_impl( index, value );
|
||||
}
|
||||
};
|
||||
|
||||
template<class... T> std::size_t hash_value_std( variant<T...> const & v )
|
||||
{
|
||||
return mp11::mp_with_index<sizeof...(T)>( v.index(), detail::hash_value_L< std::hash, variant<T...> >{ v } );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
inline std::size_t hash_value( monostate const & )
|
||||
@ -2209,7 +2379,7 @@ inline std::size_t hash_value( monostate const & )
|
||||
|
||||
template<class... T> std::size_t hash_value( variant<T...> const & v )
|
||||
{
|
||||
return mp11::mp_with_index<sizeof...(T)>( v.index(), detail::hash_value_L< variant<T...> >{ v } );
|
||||
return mp11::mp_with_index<sizeof...(T)>( v.index(), detail::hash_value_L< boost::hash, variant<T...> >{ v } );
|
||||
}
|
||||
|
||||
namespace detail
|
||||
@ -2230,7 +2400,7 @@ template<class V> struct std_hash_impl<V, true>
|
||||
{
|
||||
std::size_t operator()( V const & v ) const
|
||||
{
|
||||
return hash_value( v );
|
||||
return detail::hash_value_std( v );
|
||||
}
|
||||
};
|
||||
|
||||
@ -2256,6 +2426,111 @@ template<> struct hash< ::boost::variant2::monostate >
|
||||
|
||||
} // namespace std
|
||||
|
||||
// JSON support
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace json
|
||||
{
|
||||
|
||||
class value;
|
||||
|
||||
struct value_from_tag;
|
||||
|
||||
template<class T>
|
||||
void value_from( T&& t, value& jv );
|
||||
|
||||
template<class T>
|
||||
struct try_value_to_tag;
|
||||
|
||||
template<class T1, class T2>
|
||||
struct result_for;
|
||||
|
||||
template<class T>
|
||||
typename result_for<T, value>::type
|
||||
try_value_to( value const & jv );
|
||||
|
||||
template<class T>
|
||||
typename result_for<T, value>::type
|
||||
result_from_errno( int e, boost::source_location const* loc ) noexcept;
|
||||
|
||||
template<class T> struct is_null_like;
|
||||
|
||||
template<> struct is_null_like<variant2::monostate>: std::true_type {};
|
||||
|
||||
} // namespace json
|
||||
|
||||
namespace variant2
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct tag_invoke_L1
|
||||
{
|
||||
boost::json::value& v;
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC / 10 == 191
|
||||
// msvc-14.1 with /permissive- needs this
|
||||
explicit tag_invoke_L1( boost::json::value& v_ ): v( v_ ) {}
|
||||
#endif
|
||||
|
||||
template<class T> void operator()( T const& t ) const
|
||||
{
|
||||
boost::json::value_from( t, v );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class... T>
|
||||
void tag_invoke( boost::json::value_from_tag const&, boost::json::value& v, variant<T...> const & w )
|
||||
{
|
||||
visit( detail::tag_invoke_L1{ v }, w );
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class V> struct tag_invoke_L2
|
||||
{
|
||||
boost::json::value const& v;
|
||||
typename boost::json::result_for<V, boost::json::value>::type& r;
|
||||
|
||||
template<class I> void operator()( I i ) const
|
||||
{
|
||||
if( !r )
|
||||
{
|
||||
using Ti = mp11::mp_at_c<V, i>;
|
||||
auto r2 = boost::json::try_value_to<Ti>( v );
|
||||
|
||||
if( r2 )
|
||||
{
|
||||
r.emplace( in_place_index_t<i>{}, std::move( *r2 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class... T>
|
||||
typename boost::json::result_for<variant<T...>, boost::json::value>::type
|
||||
tag_invoke( boost::json::try_value_to_tag<variant<T...>> const&, boost::json::value const& v )
|
||||
{
|
||||
static constexpr boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
auto r = boost::json::result_from_errno< variant<T...> >( EINVAL, &loc );
|
||||
|
||||
mp11::mp_for_each<mp11::mp_iota_c<sizeof...(T)>>( detail::tag_invoke_L2< variant<T...> >{ v, r } );
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
} // namespace variant2
|
||||
} // namespace boost
|
||||
|
||||
#undef BOOST_VARIANT2_CX14_ASSERT
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910
|
||||
# pragma warning( pop )
|
||||
#endif
|
||||
|
14
test/Jamfile
14
test/Jamfile
@ -119,3 +119,17 @@ run variant_visit_r.cpp : : :
|
||||
<toolset>gcc,<target-os>windows:<variant>release
|
||||
<toolset>gcc,<target-os>cygwin:<variant>release
|
||||
;
|
||||
|
||||
compile variant_derived_construct.cpp ;
|
||||
|
||||
run variant_visit_by_index.cpp ;
|
||||
|
||||
run variant_ostream_insert.cpp ;
|
||||
run is_output_streamable.cpp ;
|
||||
|
||||
local JSON = <library>/boost//json/<warnings>off "<toolset>msvc-14.0:<build>no" "<toolset>msvc-14.2:<cxxflags>-wd5104" "<undefined-sanitizer>norecover:<link>static" ;
|
||||
|
||||
run variant_json_value_from.cpp : : : $(JSON) ;
|
||||
run variant_json_value_to.cpp : : : $(JSON) ;
|
||||
|
||||
compile variant_uses_double_storage.cpp ;
|
||||
|
@ -7,6 +7,8 @@ cmake_minimum_required(VERSION 3.5...3.16)
|
||||
project(cmake_subdir_test LANGUAGES CXX)
|
||||
|
||||
add_subdirectory(../.. boostorg/variant2)
|
||||
|
||||
add_subdirectory(../../../assert boostorg/assert)
|
||||
add_subdirectory(../../../config boostorg/config)
|
||||
add_subdirectory(../../../mp11 boostorg/mp11)
|
||||
|
||||
|
41
test/is_output_streamable.cpp
Normal file
41
test/is_output_streamable.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
};
|
||||
|
||||
std::ostream& operator<<( std::ostream& os, Y const& /*y*/ )
|
||||
{
|
||||
os << "Y()";
|
||||
return os;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, int>));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, float>));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, std::string>));
|
||||
BOOST_TEST_TRAIT_FALSE((boost::variant2::detail::is_output_streamable<std::ostream, void>));
|
||||
BOOST_TEST_TRAIT_FALSE((boost::variant2::detail::is_output_streamable<std::ostream, X>));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, Y>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, boost::variant2::monostate>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, boost::variant2::variant<int, float, std::string>>));
|
||||
BOOST_TEST_TRAIT_FALSE((boost::variant2::detail::is_output_streamable<std::ostream, boost::variant2::variant<int, float, X>>));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, boost::variant2::variant<int, float, Y>>));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, boost::variant2::variant<boost::variant2::monostate, int, float>>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
|
||||
// Copyright 2019 Peter Dimov.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/variant2.hpp>
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
|
33
test/variant_derived_construct.cpp
Normal file
33
test/variant_derived_construct.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2021 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
template<class... T> class X: variant<T...>
|
||||
{
|
||||
using base = variant<T...>;
|
||||
using base::base;
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
Y( Y const& rhs ) = default;
|
||||
|
||||
template<class T> Y( T const& t )
|
||||
{
|
||||
t.bar();
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
using W = X<int, double, Y>;
|
||||
|
||||
W a( 1 );
|
||||
W b( a );
|
||||
|
||||
(void)b;
|
||||
}
|
@ -288,5 +288,39 @@ int main()
|
||||
BOOST_TEST_EQ( Z1::instances, 0 );
|
||||
BOOST_TEST_EQ( Z2::instances, 0 );
|
||||
|
||||
{
|
||||
variant<monostate, monostate> v;
|
||||
BOOST_TEST_EQ( v.index(), 0 );
|
||||
|
||||
v.emplace<0>();
|
||||
BOOST_TEST_EQ( v.index(), 0 );
|
||||
|
||||
v.emplace<1>();
|
||||
BOOST_TEST_EQ( v.index(), 1 );
|
||||
|
||||
v.emplace<1>();
|
||||
BOOST_TEST_EQ( v.index(), 1 );
|
||||
|
||||
v.emplace<0>();
|
||||
BOOST_TEST_EQ( v.index(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
variant<monostate, int> v;
|
||||
BOOST_TEST_EQ( v.index(), 0 );
|
||||
|
||||
v.emplace<0>();
|
||||
BOOST_TEST_EQ( v.index(), 0 );
|
||||
|
||||
v.emplace<1>();
|
||||
BOOST_TEST_EQ( v.index(), 1 );
|
||||
|
||||
v.emplace<1>();
|
||||
BOOST_TEST_EQ( v.index(), 1 );
|
||||
|
||||
v.emplace<0>();
|
||||
BOOST_TEST_EQ( v.index(), 0 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -88,5 +88,12 @@ int main()
|
||||
BOOST_TEST_NOT( v1 != v2 );
|
||||
}
|
||||
|
||||
{
|
||||
variant<monostate> v1, v2;
|
||||
|
||||
BOOST_TEST( v1 == v2 );
|
||||
BOOST_TEST_NOT( v1 != v2 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -93,6 +93,13 @@ int main()
|
||||
STATIC_ASSERT( !(v1 == v2) );
|
||||
STATIC_ASSERT( !(v1 != v2) );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<monostate> v1, v2;
|
||||
|
||||
STATIC_ASSERT( v1 == v2 );
|
||||
STATIC_ASSERT( !(v1 != v2) );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -58,7 +58,7 @@ int main()
|
||||
{
|
||||
constexpr variant<int, float> v( 3.14f );
|
||||
|
||||
STATIC_ASSERT( get<1>(v) == 3.14f );
|
||||
STATIC_ASSERT( get<1>(v) == (float)3.14f ); // see FLT_EVAL_METHOD
|
||||
|
||||
STATIC_ASSERT_IF( get_if<0>(&v) == nullptr );
|
||||
STATIC_ASSERT_IF( get_if<1>(&v) == &get<1>(v) );
|
||||
@ -87,7 +87,7 @@ int main()
|
||||
{
|
||||
constexpr variant<int, int, float> v( 3.14f );
|
||||
|
||||
STATIC_ASSERT( get<2>(v) == 3.14f );
|
||||
STATIC_ASSERT( get<2>(v) == (float)3.14f );
|
||||
|
||||
STATIC_ASSERT_IF( get_if<0>(&v) == nullptr );
|
||||
STATIC_ASSERT_IF( get_if<1>(&v) == nullptr );
|
||||
|
@ -58,7 +58,7 @@ int main()
|
||||
{
|
||||
constexpr variant<int, float> v( 3.14f );
|
||||
|
||||
STATIC_ASSERT( get<float>(v) == 3.14f );
|
||||
STATIC_ASSERT( get<float>(v) == (float)3.14f ); // see FLT_EVAL_METHOD
|
||||
|
||||
STATIC_ASSERT_IF( get_if<int>(&v) == nullptr );
|
||||
STATIC_ASSERT_IF( get_if<float>(&v) == &get<float>(v) );
|
||||
@ -83,7 +83,7 @@ int main()
|
||||
{
|
||||
constexpr variant<int, int, float> v( 3.14f );
|
||||
|
||||
STATIC_ASSERT( get<float>(v) == 3.14f );
|
||||
STATIC_ASSERT( get<float>(v) == (float)3.14f );
|
||||
|
||||
STATIC_ASSERT_IF( get_if<float>(&v) == &get<float>(v) );
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <vector>
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@ -47,7 +48,17 @@ template<template<class...> class Hash, class T> void test2()
|
||||
BOOST_TEST_NE( h2, h3 );
|
||||
}
|
||||
|
||||
struct X {};
|
||||
struct X
|
||||
{
|
||||
int m = 0;
|
||||
};
|
||||
|
||||
std::size_t hash_value( X const& x )
|
||||
{
|
||||
return boost::hash<int>()( x.m );
|
||||
}
|
||||
|
||||
struct Y {}; // no hash support
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -57,6 +68,8 @@ int main()
|
||||
test<boost::hash, monostate, monostate, monostate>();
|
||||
test<boost::hash, int, int, float>();
|
||||
|
||||
test<boost::hash, monostate, X, std::vector<X>>();
|
||||
|
||||
test2<std::hash, int>();
|
||||
test2<std::hash, float>();
|
||||
|
||||
@ -65,7 +78,7 @@ int main()
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1910) && ( !defined(_LIBCPP_STD_VER) || _LIBCPP_STD_VER > 11 )
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE(( detail::is_hash_enabled<X> ));
|
||||
BOOST_TEST_TRAIT_FALSE(( detail::is_hash_enabled<Y> ));
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -68,7 +68,7 @@ int main()
|
||||
constexpr variant<int, float> v( in_place_index_t<1>{}, 3.14f );
|
||||
|
||||
STATIC_ASSERT( v.index() == 1 );
|
||||
STATIC_ASSERT( get<1>(v) == 3.14f );
|
||||
STATIC_ASSERT( get<1>(v) == (float)3.14f ); // see FLT_EVAL_METHOD
|
||||
}
|
||||
|
||||
{
|
||||
@ -89,14 +89,14 @@ int main()
|
||||
constexpr variant<int, int, float, float, X, X> v( in_place_index_t<2>{}, 3.14f );
|
||||
|
||||
STATIC_ASSERT( v.index() == 2 );
|
||||
STATIC_ASSERT( get<2>(v) == 3.14f );
|
||||
STATIC_ASSERT( get<2>(v) == (float)3.14f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float, float, X, X> v( in_place_index_t<3>{}, 3.14f );
|
||||
|
||||
STATIC_ASSERT( v.index() == 3 );
|
||||
STATIC_ASSERT( get<3>(v) == 3.14f );
|
||||
STATIC_ASSERT( get<3>(v) == (float)3.14f );
|
||||
}
|
||||
|
||||
{
|
||||
@ -105,9 +105,9 @@ int main()
|
||||
STATIC_ASSERT( v.index() == 4 );
|
||||
}
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_GCC, >= 100000 && BOOST_GCC < 100200)
|
||||
#if BOOST_WORKAROUND(BOOST_GCC, >= 100000 && BOOST_GCC < 120000)
|
||||
|
||||
// no idea why this fails on g++ 10
|
||||
// no idea why this fails on g++ 10/11
|
||||
|
||||
#else
|
||||
|
||||
|
@ -80,7 +80,7 @@ int main()
|
||||
constexpr variant<int, float> v( in_place_type_t<float>{}, 3.14f );
|
||||
|
||||
STATIC_ASSERT( v.index() == 1 );
|
||||
STATIC_ASSERT( get<1>(v) == 3.14f );
|
||||
STATIC_ASSERT( get<1>(v) == (float)3.14f ); // see FLT_EVAL_METHOD
|
||||
|
||||
STATIC_ASSERT( holds_alternative<float>(v) );
|
||||
}
|
||||
@ -89,7 +89,7 @@ int main()
|
||||
constexpr variant<int, int, float, X> v( in_place_type_t<float>{}, 3.14f );
|
||||
|
||||
STATIC_ASSERT( v.index() == 2 );
|
||||
STATIC_ASSERT( get<2>(v) == 3.14f );
|
||||
STATIC_ASSERT( get<2>(v) == (float)3.14f );
|
||||
|
||||
STATIC_ASSERT( holds_alternative<float>(v) );
|
||||
}
|
||||
@ -102,9 +102,9 @@ int main()
|
||||
STATIC_ASSERT( holds_alternative<X>(v) );
|
||||
}
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_GCC, >= 100000 && BOOST_GCC < 100200)
|
||||
#if BOOST_WORKAROUND(BOOST_GCC, >= 100000 && BOOST_GCC < 120000)
|
||||
|
||||
// no idea why this fails on g++ 10
|
||||
// no idea why this fails on g++ 10/11
|
||||
|
||||
#else
|
||||
|
||||
|
41
test/variant_json_value_from.cpp
Normal file
41
test/variant_json_value_from.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright 2022 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/json/value_from.hpp>
|
||||
#include <boost/json/serialize.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <string>
|
||||
|
||||
using namespace boost::variant2;
|
||||
namespace json = boost::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
monostate m;
|
||||
json::value w = json::value_from( m );
|
||||
BOOST_TEST_EQ( w, json::value( nullptr ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<monostate, int, std::string> v;
|
||||
json::value w = json::value_from( v );
|
||||
BOOST_TEST_EQ( w, json::value( nullptr ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<monostate, int, std::string> v( 17 );
|
||||
json::value w = json::value_from( v );
|
||||
BOOST_TEST_EQ( w, json::value( 17 ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<monostate, int, std::string> v( "test" );
|
||||
json::value w = json::value_from( v );
|
||||
BOOST_TEST_EQ( w, json::value( "test" ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
42
test/variant_json_value_to.cpp
Normal file
42
test/variant_json_value_to.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2022 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/json/value_to.hpp>
|
||||
#include <boost/json/serialize.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
using namespace boost::variant2;
|
||||
namespace json = boost::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
json::value v;
|
||||
auto r = json::try_value_to<monostate>( v );
|
||||
BOOST_TEST( r.has_value() );
|
||||
}
|
||||
|
||||
using V = variant<monostate, int, std::string>;
|
||||
|
||||
{
|
||||
json::value v;
|
||||
auto r = json::try_value_to<V>( v );
|
||||
BOOST_TEST( r.has_value() ) && BOOST_TEST_EQ( *r, V() );
|
||||
}
|
||||
|
||||
{
|
||||
json::value v( 12 );
|
||||
auto r = json::try_value_to<V>( v );
|
||||
BOOST_TEST( r.has_value() ) && BOOST_TEST_EQ( *r, V(12) );
|
||||
}
|
||||
|
||||
{
|
||||
json::value v( "test" );
|
||||
auto r = json::try_value_to<V>( v );
|
||||
BOOST_TEST( r.has_value() ) && BOOST_TEST_EQ( *r, V("test") );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -81,5 +81,14 @@ int main()
|
||||
BOOST_TEST_NOT( v1 >= v2 );
|
||||
}
|
||||
|
||||
{
|
||||
variant<monostate> v1, v2;
|
||||
|
||||
BOOST_TEST_NOT( v1 < v2 );
|
||||
BOOST_TEST_NOT( v1 > v2 );
|
||||
BOOST_TEST( v1 <= v2 );
|
||||
BOOST_TEST( v1 >= v2 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -86,6 +86,15 @@ int main()
|
||||
STATIC_ASSERT( !(v1 <= v2) );
|
||||
STATIC_ASSERT( !(v1 >= v2) );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<monostate> v1, v2;
|
||||
|
||||
STATIC_ASSERT( !(v1 < v2) );
|
||||
STATIC_ASSERT( !(v1 > v2) );
|
||||
STATIC_ASSERT( v1 <= v2 );
|
||||
STATIC_ASSERT( v1 >= v2 );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
43
test/variant_ostream_insert.cpp
Normal file
43
test/variant_ostream_insert.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
template<class T> std::string to_string( T const& t )
|
||||
{
|
||||
std::ostringstream os;
|
||||
|
||||
os << t;
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
BOOST_TEST_EQ( to_string( monostate() ), "monostate" );
|
||||
}
|
||||
|
||||
{
|
||||
variant<monostate, int, float, std::string> v;
|
||||
|
||||
BOOST_TEST_EQ( to_string( v ), to_string( monostate() ) );
|
||||
|
||||
v = 1;
|
||||
BOOST_TEST_EQ( to_string( v ), to_string( 1 ) );
|
||||
|
||||
v = 3.14f;
|
||||
BOOST_TEST_EQ( to_string( v ), to_string( 3.14f ) );
|
||||
|
||||
v = "test";
|
||||
BOOST_TEST_EQ( to_string( v ), to_string( "test" ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
50
test/variant_uses_double_storage.cpp
Normal file
50
test/variant_uses_double_storage.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright 2023 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
struct X1
|
||||
{
|
||||
};
|
||||
|
||||
STATIC_ASSERT( std::is_nothrow_move_constructible<X1>::value );
|
||||
STATIC_ASSERT( std::is_trivially_destructible<X1>::value );
|
||||
|
||||
struct X2
|
||||
{
|
||||
~X2() {}
|
||||
};
|
||||
|
||||
STATIC_ASSERT( std::is_nothrow_move_constructible<X2>::value );
|
||||
STATIC_ASSERT( !std::is_trivially_destructible<X2>::value );
|
||||
|
||||
struct X3
|
||||
{
|
||||
X3( X3&& ) {}
|
||||
};
|
||||
|
||||
STATIC_ASSERT( !std::is_nothrow_move_constructible<X3>::value );
|
||||
STATIC_ASSERT( std::is_trivially_destructible<X3>::value );
|
||||
|
||||
struct X4
|
||||
{
|
||||
~X4() {}
|
||||
X4( X4&& ) {}
|
||||
};
|
||||
|
||||
STATIC_ASSERT( !std::is_nothrow_move_constructible<X4>::value );
|
||||
STATIC_ASSERT( !std::is_trivially_destructible<X4>::value );
|
||||
|
||||
//
|
||||
|
||||
STATIC_ASSERT( !variant<int, float>::uses_double_storage() );
|
||||
STATIC_ASSERT( !variant<int, float, X1>::uses_double_storage() );
|
||||
STATIC_ASSERT( !variant<int, float, X2>::uses_double_storage() );
|
||||
STATIC_ASSERT( variant<int, float, X3>::uses_double_storage() );
|
||||
STATIC_ASSERT( variant<int, float, X4>::uses_double_storage() );
|
@ -82,7 +82,7 @@ int main()
|
||||
|
||||
STATIC_ASSERT( v.index() == 1 );
|
||||
STATIC_ASSERT( holds_alternative<float>(v) );
|
||||
STATIC_ASSERT( get<1>(v) == 3.14f );
|
||||
STATIC_ASSERT( get<1>(v) == (float)3.14f ); // see FLT_EVAL_METHOD
|
||||
}
|
||||
|
||||
{
|
||||
@ -97,7 +97,7 @@ int main()
|
||||
|
||||
STATIC_ASSERT( v.index() == 2 );
|
||||
STATIC_ASSERT( holds_alternative<float>(v) );
|
||||
STATIC_ASSERT( get<2>(v) == 3.14f );
|
||||
STATIC_ASSERT( get<2>(v) == (float)3.14f );
|
||||
}
|
||||
|
||||
{
|
||||
|
126
test/variant_visit_by_index.cpp
Normal file
126
test/variant_visit_by_index.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
// Copyright 2017, 2021 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <boost/mp11.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
using namespace boost::variant2;
|
||||
using boost::mp11::mp_int;
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct F1
|
||||
{
|
||||
int operator()( X& ) const { return 1; }
|
||||
int operator()( X const& ) const { return 2; }
|
||||
int operator()( X&& ) const { return 3; }
|
||||
int operator()( X const&& ) const { return 4; }
|
||||
};
|
||||
|
||||
struct F2
|
||||
{
|
||||
mp_int<1> operator()( X& ) const { return {}; }
|
||||
mp_int<2> operator()( X const& ) const { return {}; }
|
||||
mp_int<3> operator()( X&& ) const { return {}; }
|
||||
mp_int<4> operator()( X const&& ) const { return {}; }
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
variant<int, int, float> v;
|
||||
|
||||
visit_by_index( v,
|
||||
[]( int& x ){ BOOST_TEST_EQ( x, 0 ); },
|
||||
[]( int& ){ BOOST_ERROR( "incorrect alternative" ); },
|
||||
[]( float& ){ BOOST_ERROR( "incorrect alternative" ); } );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int const, int, float const> v( in_place_index_t<0>(), 1 );
|
||||
|
||||
visit_by_index( v,
|
||||
[]( int const& x ){ BOOST_TEST_EQ( x, 1 ); },
|
||||
[]( int& ){ BOOST_ERROR( "incorrect alternative" ); },
|
||||
[]( float const& ){ BOOST_ERROR( "incorrect alternative" ); } );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float> const v( in_place_index_t<1>(), 2 );
|
||||
|
||||
visit_by_index( v,
|
||||
[]( int const& ){ BOOST_ERROR( "incorrect alternative" ); },
|
||||
[]( int const& x ){ BOOST_TEST_EQ( x, 2 ); },
|
||||
[]( float const& ){ BOOST_ERROR( "incorrect alternative" ); } );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int const, int, float const> const v( 3.14f );
|
||||
|
||||
visit_by_index( v,
|
||||
[]( int const& ){ BOOST_ERROR( "incorrect alternative" ); },
|
||||
[]( int const& ){ BOOST_ERROR( "incorrect alternative" ); },
|
||||
[]( float const& x ){ BOOST_TEST_EQ( x, 3.14f ); } );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float> const v( 7 );
|
||||
|
||||
auto r = visit_by_index( v,
|
||||
[]( int const& x ) -> double { return x; },
|
||||
[]( float const& x ) -> double { return x; } );
|
||||
|
||||
BOOST_TEST_TRAIT_SAME( decltype(r), double );
|
||||
BOOST_TEST_EQ( r, 7.0 );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float> const v( 2.0f );
|
||||
|
||||
auto r = visit_by_index( v,
|
||||
[]( int const& x ) { return x + 0.0; },
|
||||
[]( float const& x ) { return x + 0.0; } );
|
||||
|
||||
BOOST_TEST_TRAIT_SAME( decltype(r), double );
|
||||
BOOST_TEST_EQ( r, 2.0 );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float, double> const v( 3.0 );
|
||||
|
||||
auto r = visit_by_index<double>( v,
|
||||
[]( int const& x ) { return x; },
|
||||
[]( float const& x ) { return x; },
|
||||
[]( double const& x ) { return x; } );
|
||||
|
||||
BOOST_TEST_TRAIT_SAME( decltype(r), double );
|
||||
BOOST_TEST_EQ( r, 3.0 );
|
||||
}
|
||||
|
||||
{
|
||||
variant<X> v;
|
||||
variant<X> const cv;
|
||||
|
||||
F1 f1;
|
||||
|
||||
BOOST_TEST_EQ( visit_by_index( v, f1 ), 1 );
|
||||
BOOST_TEST_EQ( visit_by_index( cv, f1 ), 2 );
|
||||
BOOST_TEST_EQ( visit_by_index( std::move( v ), f1 ), 3 );
|
||||
BOOST_TEST_EQ( visit_by_index( std::move( cv ), f1 ), 4 );
|
||||
|
||||
F2 f2;
|
||||
|
||||
BOOST_TEST_EQ( visit_by_index<int>( v, f2 ), 1 );
|
||||
BOOST_TEST_EQ( visit_by_index<int>( cv, f2 ), 2 );
|
||||
BOOST_TEST_EQ( visit_by_index<int>( std::move( v ), f2 ), 3 );
|
||||
BOOST_TEST_EQ( visit_by_index<int>( std::move( cv ), f2 ), 4 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
|
||||
// Copyright 2017, 2020 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
@ -15,7 +14,7 @@
|
||||
|
||||
struct X: boost::variant2::variant<int, float>
|
||||
{
|
||||
#if BOOST_WORKAROUND( BOOST_MSVC, < 1930 )
|
||||
#if BOOST_WORKAROUND( BOOST_MSVC, < 1940 )
|
||||
|
||||
template<class T> explicit X( T&& t ): variant( std::forward<T>( t ) ) {};
|
||||
|
||||
|
@ -61,18 +61,18 @@ int main()
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float> const v( 3.14f );
|
||||
variant<int, float> const v( 3.125f );
|
||||
|
||||
BOOST_TEST_EQ( visit<int>( F1(), v ), 3 );
|
||||
BOOST_TEST_EQ( visit<float>( F1(), v ), 3.14f );
|
||||
BOOST_TEST_EQ( visit<float>( F1(), v ), 3.125f );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float> v1( 1 );
|
||||
variant<int, float> const v2( 3.14f );
|
||||
variant<int, float> const v2( 3.125f );
|
||||
|
||||
BOOST_TEST_EQ( visit<int>( F2(), v1, v2 ), 4 );
|
||||
BOOST_TEST_EQ( visit<float>( F2(), v1, v2 ), 1 + 3.14f );
|
||||
BOOST_TEST_EQ( visit<float>( F2(), v1, v2 ), 1 + 3.125f );
|
||||
}
|
||||
|
||||
{
|
||||
|
Reference in New Issue
Block a user