Compare commits

...

145 Commits

Author SHA1 Message Date
8caa1a3484 Update revision history 2025-01-15 19:44:18 +02:00
6669e07071 Work around GCC 5, 6 failures 2024-12-22 20:12:08 +02:00
df84f1f146 Work around Clang 3.x failures 2024-12-22 20:10:16 +02:00
2630b3e572 Use the smallest appropriate unsigned type for the index. Closes #50. 2024-12-22 19:09:05 +02:00
010c78598e Split variant_index_type into separate runs for each variant size 2024-12-22 06:03:10 +02:00
d77d61c8ec Avoid use of mp_back in variant_index_type.cpp 2024-12-22 04:52:07 +02:00
8f6918554e Use -j2 on GHA and Appveyor to avoid MSVC out of heap errors 2024-12-22 04:31:47 +02:00
183aea23a9 Only use -ftemplate-depth for Clang on Linux, because clang-cl doesn't like it (and Mac doesn't need it) 2024-12-22 03:20:39 +02:00
7c64abd41c Remove clang-5.0/cxxstd=1z from Drone as well 2024-12-22 03:16:12 +02:00
7b8e8c33bb Disable variant_index_type.cpp for msvc-14.0, because GHA fails with 'out of heap space' 2024-12-22 03:09:28 +02:00
2f5dbc19b5 Remove cxxstd=1z for Clang 5.0 2024-12-22 03:03:57 +02:00
639bd0232b Add -ftemplate-depth=1024 for Clang (3.x needs it) 2024-12-22 03:03:35 +02:00
94749d088d Disable variant_index_type.cpp for MSVC 32 bit 2024-12-22 02:44:02 +02:00
e2fc107ac7 Add test/variant_index_type.cpp. Refs #50. 2024-12-21 20:15:45 +02:00
306a602d19 Compute the index type with a metafunction. Refs #50. 2024-12-21 19:01:18 +02:00
509ce1dc77 Merge pull request #49 from Lastique/patch-1
Add missing std namespace qualifiers
2024-12-18 06:55:12 +02:00
47e544959f Added missing std namespace qualifiers. 2024-12-18 02:57:01 +03:00
8333e9af93 Apply Node20 workaround 2024-12-12 19:50:00 +02:00
19b75fffe4 Add test/variant_visit_cx_2.cpp. Refs #47. 2024-11-23 04:11:30 +02:00
bdc1098c80 Add test/variant_visit_r_cx.cpp. Refs #47. 2024-11-23 03:38:27 +02:00
9061e427c2 Add test/variant_visit_cx.cpp. Refs #47. 2024-11-23 03:13:28 +02:00
1202390861 Update .drone.jsonnet 2024-11-22 23:06:34 +02:00
79061e470f Update ci.yml 2024-11-22 22:53:17 +02:00
a4b167b723 Add VERBATIM to add_custom_target 2024-08-28 20:45:54 +03:00
c7c5eb2510 Update .drone.jsonnet 2024-08-28 20:45:27 +03:00
acf24454d8 Update build.jam, test/Jamfile 2024-08-28 20:28:59 +03:00
f78343e18d Sync from upstream. 2024-07-25 17:19:46 -05:00
ea4394914c Move inter-lib dependencies to a project variable and into the build targets. 2024-07-23 22:34:24 -05:00
f5cd36af3d Update MSVC workaround 2024-07-21 22:55:40 +03:00
0e325dcf8d Update ci.yml 2024-07-21 22:38:06 +03:00
e3cf721a23 Define BOOST_ALLOW_DEPRECATED in JSON tests for g++ 4.x 2024-07-21 22:20:27 +03:00
d4f0e57b36 Update .drone.jsonnet 2024-07-21 21:54:28 +03:00
f874a2cb1b Update copyright dates. 2024-07-20 22:52:05 -05:00
fc088e7273 Change all <source> references to <library>. 2024-07-20 21:27:52 -05:00
4f207d7363 Bump B2 require to 5.2 2024-06-14 11:33:56 -05:00
429a82a52e Sync from upstream. 2024-05-19 23:15:27 -05:00
f9bdafd3ca Remove C++11 requirements from test/Jamfile 2024-05-18 03:18:56 +03:00
38293da18e Update .drone.jsonnet 2024-05-18 02:43:52 +03:00
65ab0f8cef Update ci.yml 2024-05-17 22:04:55 +03:00
78796d0e7d Increase workaround to < 1950, because VS2022 has reached _MSC_VER=1940. Refs #43. 2024-05-17 21:44:21 +03:00
bb13b5be08 Add requires-b2 check to top-level build file. 2024-05-05 09:00:01 -05:00
1324e32b33 Add missing import-search for cconfig/predef checks. 2024-05-04 23:33:36 -05:00
02303d662e Sync from upstream. 2024-04-10 07:58:16 -05:00
09f3802347 Switch to library requirements instead of source. As source puts extra source in install targets. 2024-03-29 21:16:00 -05:00
ff36c3aa1f Merge pull request #42 from K-ballo/more-natvis
Improve natvis
2024-03-25 02:22:20 +02:00
f0acc9326e Work around MSVC failures in variant_derived_construct2. Refs #43. 2024-03-24 19:16:09 +02:00
a936eae01b Add test/variant_derived_construct2. Refs #43. 2024-03-24 18:41:49 +02:00
77234b514c Improve natvis:
- extend support from 10 to 40 alternatives,
- split single-buffer vs double-buffer definitions,
- adjust display string to follow MS definition for std::variant
2024-03-23 16:04:54 -03:00
5c34125b14 Make the library modular usable. 2024-03-11 08:38:17 -05:00
c125b32938 Add msvc-14.3 /permissive- to Drone 2024-02-08 20:58:45 +02:00
3298078c8b Update .drone.jsonnet 2024-01-11 22:05:28 +02:00
a38839febc Update ci.yml 2024-01-11 21:20:40 +02:00
c3071b7d0b Merge pull request #40 from Lastique/patch-1
Add missing dots in visit_by_index docs
2024-01-11 21:03:37 +02:00
9cf32980a9 Add missing dots in visit_by_index docs 2024-01-11 20:18:06 +03:00
9e4234bfd5 Merge pull request #39 from 13steinj/develop
Suppress -Wuninitialized in emplace_impl
2023-10-24 12:42:10 +03:00
55f1332ce0 Suppress -Wuninitialized in emplace_impl
Closes #38
2023-10-23 15:46:15 -05:00
db12c36b89 Remove unnecessary includes 2023-10-11 18:28:11 +03:00
a5cb0582d5 Make tag_invoke_L2 more msvc-14.0-friendly 2023-09-03 18:28:49 +03:00
e2546b70ca Document uses_double_storage(). Refs #37. 2023-06-29 18:32:58 +03:00
362224a009 Update ci.yml 2023-06-29 16:44:47 +03:00
2c590716ab Use the exact 3.125f in variant_visit_r.cpp 2023-06-29 12:05:55 +03:00
82b98fb757 Cast 3.14f to float because FLT_EVAL_METHOD (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108742) for discussion 2023-06-29 10:46:54 +03:00
30afb9e183 Update test/Jamfile to fix Drone issues 2023-06-29 09:54:49 +03:00
129e27ce09 Update Drone files 2023-06-29 09:33:44 +03:00
26595285d3 Add variant<>::uses_double_storage(). Refs #37. 2023-06-28 22:14:56 +03:00
95a8c5ffec Update .drone.jsonnet 2023-01-23 03:53:25 +02:00
ec2819a05e Update CMakeLists.txt 2023-01-13 00:56:45 +02:00
fcf9746a2d Merge branch 'develop' of https://github.com/vinniefalco/boost-variant2 into feature/pr-36 2023-01-13 00:55:17 +02:00
a74ebd34dc Update appveyor.yml 2023-01-12 21:12:17 +02:00
1b34c20685 Update appveyor.yml 2023-01-12 18:38:10 +02:00
604d3700ad Add CMake tests to Appveyor 2023-01-12 10:49:41 +02:00
4d1fd43d72 Update supported compilers in documentation and README 2022-10-27 21:25:57 +03:00
376925a209 Work around msvc-14.1 /permissive- failure 2022-10-24 15:47:09 +03:00
bcb8796225 Add /permissive- jobs to Drone and Appveyor 2022-10-24 15:27:05 +03:00
a948b85c74 Update revision history 2022-10-18 17:38:59 +03:00
32862d6db7 Add missing std::move 2022-10-18 16:02:33 +03:00
423d350ff1 Remove unneeded forward declarations 2022-10-18 16:01:31 +03:00
aad1f86fae Reflect the change in is_null_like 2022-10-18 16:00:14 +03:00
1f8c4a1900 Replace polymorphic lambdas with function objects for C++11 2022-10-18 06:29:57 +03:00
67a12199e6 Add JSON support (refs #28) 2022-10-18 06:08:18 +03:00
457147d1b0 Suppress -Wmaybe-uninitialized in emplace_impl 2022-10-18 03:20:36 +03:00
4a5f3dc498 Add variant<monostate, T>::emplace tests to fish out -Wmaybe-uninitialized warnings 2022-10-18 02:56:15 +03:00
6fe1c69bc8 Add Drone support 2022-10-18 02:16:59 +03:00
78a974429a Update ci.yml 2022-10-15 19:39:32 +03:00
4c5f254b9c add boost_variant2.natvis and interface source files 2022-08-19 12:13:08 -07:00
c633a953de Change macos-10.15 to macos-11 in ci.yml 2022-08-15 19:26:35 +03:00
8ee7c5aad0 Update ci.yml 2022-07-14 14:47:06 +03:00
d34658f4c8 Document operator<< for monostate 2022-01-31 19:19:49 +02:00
5e2bce1baa Add operator<< for monostate 2022-01-31 17:55:26 +02:00
573ef77382 Move unsigned ix_ after the elements to avoid need to adjust rdi (closes #30) 2021-12-09 21:28:35 +02:00
f6cad272d4 Add msvc-14.0 to GHA 2021-12-09 19:59:01 +02:00
3fc7540733 Only define operator<< when all contained types are streamable (refs #31) 2021-12-09 18:39:03 +02:00
e4b4b3f02b Extend msvc-14.2 workaround to 14.3 2021-10-29 02:18:23 +03:00
44d38c4111 Enable syntax highlighting 2021-10-28 23:23:13 +03:00
1ebfb3b689 Add msvc-14.3 to ci.yml 2021-10-28 23:22:20 +03:00
8af1fbde8e Update cmake_subdir_test/CMakeLists.txt 2021-09-21 14:52:38 +03:00
26ce33597d Regenerate CMakeLists.txt 2021-09-21 14:45:20 +03:00
c89713b978 Add CMake tests to ci.yml 2021-09-21 14:31:47 +03:00
10c441c8d7 Update appveyor.yml 2021-09-15 15:11:54 +03:00
09ec260780 Document operator<< 2021-09-15 03:53:13 +03:00
2da13befd7 Work around mysterious errors with gcc, msvc-14.1, and clang-cl 2021-09-15 03:28:29 +03:00
e668c099ce Add operator<< for variant 2021-09-15 02:51:11 +03:00
aebcb9792d Update documentation of visit_by_index 2021-09-15 02:00:33 +03:00
8fd9f830a9 Add proper type deduction to visit_by_index 2021-09-15 01:30:09 +03:00
ed4bebff3d Document visit_by_index 2021-09-14 21:32:57 +03:00
ad06c9b923 Add visit_by_index 2021-09-14 21:06:01 +03:00
de4eb8b6d2 Update README.md 2021-09-11 19:47:34 +03:00
4d69db1441 Extend g++-10 workarounds to 11 2021-09-11 19:23:39 +03:00
095d9770c4 Update ci.yml 2021-09-11 18:36:43 +03:00
cca476fbbc Update documentation 2021-09-11 18:29:17 +03:00
c76af4d3cf Update README.md 2021-09-11 18:26:28 +03:00
1af7b165cf BOOST_VARIANT2_CX14_ASSERT must be empty under C++11 2021-09-11 18:22:46 +03:00
49bff72be0 Define and use a helper macro BOOST_VARIANT2_CX14_ASSERT in constexpr functions 2021-09-11 18:11:17 +03:00
59780ba08e Only assert when C++14 2021-09-11 18:00:29 +03:00
edd70cfd66 Update ci.yml 2021-09-11 17:43:05 +03:00
86c2782dff Update documentation 2021-09-11 17:39:55 +03:00
dce8174550 Make unsafe_get public 2021-09-11 17:29:21 +03:00
9d40bc80f1 Use BOOST_ASSERT instead of assert 2021-09-11 17:23:29 +03:00
be6ddf9fdc Add boost/variant2.hpp 2021-09-11 17:19:09 +03:00
4153a535a0 Update .github/workflows 2021-04-19 20:37:12 +03:00
f374ad68a3 Add -DBUILD_TESTING=ON to .yml files; it's not default anymore 2021-03-19 04:18:08 +02:00
3bc9a57c9b Merge branch 'feature/issue-26' into develop 2021-03-13 18:23:39 +02:00
3ca95a65df Use boost::hash in hash_value, not std::hash (closes #27) 2021-03-13 05:08:03 +02:00
ae1f72671e Add test for types supported by boost::hash, but not by std::hash 2021-03-13 04:50:01 +02:00
a2dab8c7d3 Refactor detail::hash_value_L 2021-03-13 04:10:41 +02:00
f39a71ed2f Merge branch 'feature/issue-26-nofix' into feature/issue-26 2021-03-13 01:09:46 +02:00
06dde96400 Merge branch 'develop' into feature/issue-26-nofix 2021-03-13 01:09:17 +02:00
8be0a4a5fe Update copyright 2021-03-12 23:42:32 +02:00
90cda5339f Disable U&& constructor for derived types 2021-03-12 23:40:14 +02:00
afb0aafd64 Change clangs to bionic 2021-03-12 20:18:24 +02:00
f586dc8848 Add test for inherited constructors (refs #26) 2021-03-12 20:15:09 +02:00
20b9175932 Add cxxstd=latest to Appveyor 2021-03-08 04:04:35 +02:00
fb3ce863ff Add MSVC workaround for monospace constexpr (refs #25) 2021-03-08 03:26:40 +02:00
8ec0bf448a Add monospace relational tests (refs #25) 2021-03-08 03:01:21 +02:00
6d19e6be68 Update revision history 2021-03-07 00:51:28 +02:00
d8552b23ae UBSan on clang 7 is broken on Ubuntu 2021-03-01 06:35:38 +02:00
f44aba09a2 Update .travis.yml 2021-03-01 00:26:43 +02:00
99cc1db385 Fix documentation for emplace effects 2021-01-25 03:49:42 +02:00
6d848c5af6 Update GCC workarounds in constexpr in-place construct tests 2021-01-25 03:44:24 +02:00
3c9f4e56bf Fix visit codegen regression when NDEBUG is not defined 2021-01-24 17:27:24 +02:00
3015e56bcb GCC bug 63707 has been fixed for GCC 11 2021-01-23 20:36:12 +02:00
7c37053950 Merge branch 'develop' into feature/double-opt 2021-01-13 05:06:00 +02:00
60995edb41 Remove g++ 4.7 from GHA 2021-01-13 05:01:44 +02:00
6de876954a Merge branch 'develop' into feature/double-opt 2021-01-13 02:32:32 +02:00
453b00dec8 Use (i+1)*2+j for the internal index in the double-buffered case, to avoid branches 2021-01-13 02:10:12 +02:00
46 changed files with 2811 additions and 340 deletions

440
.drone.jsonnet Normal file
View File

@ -0,0 +1,440 @@
# 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',
'uname -a',
'echo $DRONE_STAGE_MACHINE',
'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 16.04 GCC 4.8 32/64",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-4.8', CXXSTD: '11', ADDRMD: '32,64' },
"g++-4.8-multilib",
),
linux_pipeline(
"Linux 16.04 GCC 4.9 32/64",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-4.9', CXXSTD: '11', ADDRMD: '32,64' },
"g++-4.9-multilib",
),
linux_pipeline(
"Linux 16.04 GCC 5* 32/64",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14', ADDRMD: '32,64' },
),
linux_pipeline(
"Linux 18.04 GCC 6 32/64",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-6', CXXSTD: '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: '11,14,17', ADDRMD: '32,64' },
),
linux_pipeline(
"Linux 18.04 GCC 8 32/64",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-8', CXXSTD: '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: '11,14,17,2a', ADDRMD: '32,64' },
),
linux_pipeline(
"Linux 20.04 GCC 9* ARM64",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' },
arch="arm64",
),
linux_pipeline(
"Linux 20.04 GCC 9* S390x",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' },
arch="s390x",
),
linux_pipeline(
"Linux 20.04 GCC 10 32/64",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '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: '11,14,17,2a', ADDRMD: '32,64' },
),
linux_pipeline(
"Linux 22.04 GCC 12 32/64",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '11,14,17,20,2b', ADDRMD: '32,64' },
"g++-12-multilib",
),
linux_pipeline(
"Linux 24.04 GCC 13 32/64",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '32,64' },
"g++-13-multilib",
),
linux_pipeline(
"Linux 24.04 GCC 14 32 ASAN",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' } + asan,
"g++-14-multilib",
),
linux_pipeline(
"Linux 24.04 GCC 14 64 ASAN",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b', ADDRMD: '64' } + asan,
"g++-14-multilib",
),
linux_pipeline(
"Linux 24.04 GCC 14 32 UBSAN",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' } + ubsan,
"g++-14-multilib",
),
linux_pipeline(
"Linux 24.04 GCC 14 64 UBSAN",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b', ADDRMD: '64' } + ubsan,
"g++-14-multilib",
),
linux_pipeline(
"Linux 16.04 Clang 3.5",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.5', CXXSTD: '11' },
"clang-3.5",
),
linux_pipeline(
"Linux 16.04 Clang 3.6",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.6', CXXSTD: '11,14' },
"clang-3.6",
),
linux_pipeline(
"Linux 16.04 Clang 3.7",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.7', CXXSTD: '11,14' },
"clang-3.7",
),
linux_pipeline(
"Linux 16.04 Clang 3.8",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.8', CXXSTD: '11,14' },
"clang-3.8",
),
linux_pipeline(
"Linux 18.04 Clang 3.9",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.9', CXXSTD: '11,14' },
"clang-3.9",
),
linux_pipeline(
"Linux 18.04 Clang 4.0",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-4.0', CXXSTD: '11,14' },
"clang-4.0",
),
linux_pipeline(
"Linux 18.04 Clang 5.0",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-5.0', CXXSTD: '11,14' },
"clang-5.0",
),
linux_pipeline(
"Linux 18.04 Clang 6.0",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-6.0', CXXSTD: '11,14,17' },
"clang-6.0",
),
linux_pipeline(
"Linux 20.04 Clang 7",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-7', CXXSTD: '11,14,17' },
"clang-7",
),
linux_pipeline(
"Linux 20.04 Clang 8",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-8', CXXSTD: '11,14,17' },
"clang-8",
),
linux_pipeline(
"Linux 20.04 Clang 9",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-9', CXXSTD: '11,14,17,2a' },
"clang-9",
),
linux_pipeline(
"Linux 20.04 Clang 10",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-10', CXXSTD: '11,14,17,2a' },
"clang-10",
),
linux_pipeline(
"Linux 20.04 Clang 11",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-11', CXXSTD: '11,14,17,2a' },
"clang-11",
),
linux_pipeline(
"Linux 20.04 Clang 12",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-12', CXXSTD: '11,14,17,2a' },
"clang-12",
),
linux_pipeline(
"Linux 22.04 Clang 13",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-13', CXXSTD: '11,14,17,20,2b' },
"clang-13",
),
linux_pipeline(
"Linux 22.04 Clang 14",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '11,14,17,20,2b' },
"clang-14",
),
linux_pipeline(
"Linux 22.04 Clang 15",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '11,14,17,20,2b' },
"clang-15",
),
linux_pipeline(
"Linux 24.04 Clang 16",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-16', CXXSTD: '11,14,17,20,2b' },
"clang-16",
),
linux_pipeline(
"Linux 24.04 Clang 17 UBSAN",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '11,14,17,20,2b' } + ubsan,
"clang-17",
),
linux_pipeline(
"Linux 24.04 Clang 17 ASAN",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '11,14,17,20,2b' } + asan,
"clang-17",
),
linux_pipeline(
"Linux 24.04 Clang 18 UBSAN",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + ubsan,
"clang-18",
),
linux_pipeline(
"Linux 24.04 Clang 18 ASAN",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + asan,
"clang-18",
),
linux_pipeline(
"Linux 24.10 Clang 19",
"cppalliance/droneubuntu2410:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-19', CXXSTD: '11,14,17,20,2b' } + asan,
"clang-19",
),
macos_pipeline(
"MacOS 10.15 Xcode 12.2 UBSAN",
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,1z' } + ubsan,
),
macos_pipeline(
"MacOS 10.15 Xcode 12.2 ASAN",
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,1z' } + asan,
),
macos_pipeline(
"MacOS 12.4 Xcode 13.4.1 UBSAN",
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '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: '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', B2_DONT_EMBED_MANIFEST: '1' },
),
windows_pipeline(
"Windows VS2017 msvc-14.1",
"cppalliance/dronevs2017",
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest' },
),
windows_pipeline(
"Windows VS2017 msvc-14.1 permissive-",
"cppalliance/dronevs2017",
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17', 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 permissive-",
"cppalliance/dronevs2019",
{ TOOLSET: 'msvc-14.2', CXXSTD: '14,17', CXXFLAGS: '/permissive-' },
),
windows_pipeline(
"Windows VS2022 msvc-14.3",
"cppalliance/dronevs2022:1",
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17,20,latest' },
),
windows_pipeline(
"Windows VS2022 msvc-14.3 permissive-",
"cppalliance/dronevs2022:1",
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17', CXXFLAGS: '/permissive-' },
),
]

24
.drone/drone.bat Normal file
View 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
View 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}

View File

@ -17,105 +17,197 @@ 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
cxxstd: "11"
container: ubuntu:16.04
os: ubuntu-latest
install: g++-4.8
- toolset: gcc-4.9
cxxstd: "03,11"
os: ubuntu-16.04
cxxstd: "11"
container: ubuntu:16.04
os: ubuntu-latest
install: g++-4.9
- toolset: gcc-5
cxxstd: "03,11,14,1z"
os: ubuntu-16.04
cxxstd: "11,14,1z"
container: ubuntu:18.04
os: ubuntu-latest
install: g++-5
- toolset: gcc-6
cxxstd: "03,11,14,1z"
os: ubuntu-16.04
cxxstd: "11,14,1z"
container: ubuntu:18.04
os: ubuntu-latest
install: g++-6
- toolset: gcc-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
cxxstd: "11,14,17"
container: ubuntu:18.04
os: ubuntu-latest
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-18.04
cxxstd: "11,14,17,2a"
os: ubuntu-20.04
install: g++-8
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-18.04
cxxstd: "11,14,17,2a"
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
cxxstd: "11,14,17,2a"
os: ubuntu-22.04
install: g++-10
- toolset: gcc-11
cxxstd: "11,14,17,2a"
os: ubuntu-22.04
install: g++-11
- toolset: gcc-12
cxxstd: "11,14,17,20,2b"
os: ubuntu-22.04
install: g++-12
- toolset: gcc-13
cxxstd: "11,14,17,20,2b"
container: ubuntu:24.04
os: ubuntu-latest
install: g++-13
- toolset: gcc-14
cxxstd: "11,14,17,20,2b"
container: ubuntu:24.04
os: ubuntu-latest
install: g++-14
- toolset: clang
compiler: clang++-3.9
cxxstd: "03,11,14"
os: ubuntu-16.04
cxxstd: "11,14"
container: ubuntu:18.04
os: ubuntu-latest
install: clang-3.9
- toolset: clang
compiler: clang++-4.0
cxxstd: "03,11,14"
os: ubuntu-16.04
cxxstd: "11,14"
container: ubuntu:18.04
os: ubuntu-latest
install: clang-4.0
- toolset: clang
compiler: clang++-5.0
cxxstd: "03,11,14,1z"
os: ubuntu-16.04
cxxstd: "11,14"
container: ubuntu:18.04
os: ubuntu-latest
install: clang-5.0
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
os: ubuntu-18.04
cxxstd: "11,14,17"
os: ubuntu-20.04
install: clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
cxxstd: "11,14,17"
os: ubuntu-20.04
install: clang-7
- toolset: clang
compiler: clang++-8
cxxstd: "03,11,14,17,2a"
cxxstd: "11,14,17"
os: ubuntu-20.04
install: clang-8
- toolset: clang
compiler: clang++-9
cxxstd: "03,11,14,17,2a"
cxxstd: "11,14,17,2a"
os: ubuntu-20.04
install: clang-9
- toolset: clang
compiler: clang++-10
cxxstd: "03,11,14,17,2a"
cxxstd: "11,14,17,2a"
os: ubuntu-20.04
install: clang-10
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-10.15
compiler: clang++-11
cxxstd: "11,14,17,2a"
os: ubuntu-20.04
install: clang-11
- toolset: clang
compiler: clang++-12
cxxstd: "11,14,17,2a"
os: ubuntu-20.04
install: clang-12
- toolset: clang
compiler: clang++-13
cxxstd: "11,14,17,20,2b"
container: ubuntu:22.04
os: ubuntu-latest
install: clang-13
- toolset: clang
compiler: clang++-14
cxxstd: "11,14,17,20,2b"
container: ubuntu:22.04
os: ubuntu-latest
install: clang-14
- toolset: clang
compiler: clang++-15
cxxstd: "11,14,17,20,2b"
container: ubuntu:22.04
os: ubuntu-latest
install: clang-15
- toolset: clang
compiler: clang++-16
cxxstd: "11,14,17,20,2b"
container: ubuntu:24.04
os: ubuntu-latest
install: clang-16
- toolset: clang
compiler: clang++-17
cxxstd: "11,14,17,20,2b"
container: ubuntu:24.04
os: ubuntu-latest
install: clang-17
- toolset: clang
compiler: clang++-18
cxxstd: "11,14,17,20,2b"
container: ubuntu:24.04
os: ubuntu-latest
install: clang-18
- toolset: clang
compiler: clang++-19
cxxstd: "11,14,17,20,2b"
container: ubuntu:24.10
os: ubuntu-latest
install: clang-19
- toolset: clang
cxxstd: "11,14,17,20,2b"
os: macos-13
- toolset: clang
cxxstd: "11,14,17,20,2b"
os: macos-14
- toolset: clang
cxxstd: "11,14,17,20,2b"
os: macos-15
runs-on: ${{matrix.os}}
container:
image: ${{matrix.container}}
volumes:
- /node20217:/node20217:rw,rshared
- ${{ startsWith(matrix.container, 'ubuntu:1') && '/node20217:/__e/node20:ro,rshared' || ' ' }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- name: Setup container environment
if: matrix.container
run: |
apt-get update
apt-get -y install sudo python3 git g++ curl xz-utils
- name: Install nodejs20glibc2.17
if: ${{ startsWith( matrix.container, 'ubuntu:1' ) }}
run: |
curl -LO https://archives.boost.io/misc/node/node-v20.9.0-linux-x64-glibc-217.tar.xz
tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217
ldd /__e/node20/bin/node
- uses: actions/checkout@v4
- 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 +227,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 $LIBRARY
./bootstrap.sh
./b2 -d0 headers
@ -154,23 +246,31 @@ 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"
cxxstd: "11,14,17,2a"
addrmd: 64
os: windows-2019
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Boost
shell: cmd
@ -198,4 +298,349 @@ 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 -j2 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: ubuntu-24.04
- os: macos-13
- os: macos-14
- os: macos-15
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- 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: ubuntu-24.04
- os: macos-13
- os: macos-14
- os: macos-15
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- 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: ubuntu-24.04
- os: macos-13
- os: macos-14
- os: macos-15
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- 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@v4
- 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@v4
- 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@v4
- 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

View File

@ -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

View File

@ -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)

View File

@ -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).

View File

@ -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 -j2 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

22
build.jam Normal file
View File

@ -0,0 +1,22 @@
# Copyright 2023-2024 René Ferdinand Rivera Morell
# Copyright 2024 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
require-b2 5.2 ;
constant boost_dependencies :
/boost/assert//boost_assert
/boost/config//boost_config
/boost/mp11//boost_mp11
;
project /boost/variant2 ;
explicit
[ alias boost_variant2 : : : : <include>include <library>$(boost_dependencies) ]
[ alias all : boost_variant2 test ]
;
call-if : boost-library variant2
;

View File

@ -13,6 +13,8 @@ Peter Dimov
:toclevels: 4
:idprefix:
:docinfo: private-footer
:source-highlighter: rouge
:source-language: c++
:leveloffset: +1

View File

@ -1,16 +1,40 @@
////
Copyright 2019, 2020 Peter Dimov
Copyright 2019-2025 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.88.0
* Use the smallest appropriate unsigned type for the index.
## 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`

View File

@ -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.

View File

@ -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].

View File

@ -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>`.

178
extra/boost_variant2.natvis Normal file
View File

@ -0,0 +1,178 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="boost::variant2::detail::variant_base_impl&lt;*,1,*&gt;">
<Intrinsic Name="index" Expression="(int)ix_ - 1"/>
<DisplayString Condition="index() == 0" Optional="true">{{ index=0, value={*($T2*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 1" Optional="true">{{ index=1, value={*($T3*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 2" Optional="true">{{ index=2, value={*($T4*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 3" Optional="true">{{ index=3, value={*($T5*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 4" Optional="true">{{ index=4, value={*($T6*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 5" Optional="true">{{ index=5, value={*($T7*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 6" Optional="true">{{ index=6, value={*($T8*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 7" Optional="true">{{ index=7, value={*($T9*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 8" Optional="true">{{ index=8, value={*($T10*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 9" Optional="true">{{ index=9, value={*($T11*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 10" Optional="true">{{ index=10, value={*($T12*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 11" Optional="true">{{ index=11, value={*($T13*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 12" Optional="true">{{ index=12, value={*($T14*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 13" Optional="true">{{ index=13, value={*($T15*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 14" Optional="true">{{ index=14, value={*($T16*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 15" Optional="true">{{ index=15, value={*($T17*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 16" Optional="true">{{ index=16, value={*($T18*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 17" Optional="true">{{ index=17, value={*($T19*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 18" Optional="true">{{ index=18, value={*($T20*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 19" Optional="true">{{ index=19, value={*($T21*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 20" Optional="true">{{ index=10, value={*($T22*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 21" Optional="true">{{ index=21, value={*($T23*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 22" Optional="true">{{ index=22, value={*($T24*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 23" Optional="true">{{ index=23, value={*($T25*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 24" Optional="true">{{ index=24, value={*($T26*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 25" Optional="true">{{ index=25, value={*($T27*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 26" Optional="true">{{ index=26, value={*($T28*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 27" Optional="true">{{ index=27, value={*($T29*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 28" Optional="true">{{ index=28, value={*($T30*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 29" Optional="true">{{ index=29, value={*($T31*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 30" Optional="true">{{ index=30, value={*($T32*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 31" Optional="true">{{ index=31, value={*($T33*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 32" Optional="true">{{ index=32, value={*($T34*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 33" Optional="true">{{ index=33, value={*($T35*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 34" Optional="true">{{ index=34, value={*($T36*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 35" Optional="true">{{ index=35, value={*($T37*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 36" Optional="true">{{ index=36, value={*($T38*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 37" Optional="true">{{ index=37, value={*($T39*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 38" Optional="true">{{ index=38, value={*($T40*)&amp;st_} }}</DisplayString>
<DisplayString Condition="index() == 39" Optional="true">{{ index=39, value={*($T41*)&amp;st_} }}</DisplayString>
<Expand>
<Item Name="index">index()</Item>
<Item Name="[value]" Condition="index() == 0" Optional="true">*($T2*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 1" Optional="true">*($T3*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 2" Optional="true">*($T4*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 3" Optional="true">*($T5*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 4" Optional="true">*($T6*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 5" Optional="true">*($T7*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 6" Optional="true">*($T8*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 7" Optional="true">*($T9*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 8" Optional="true">*($T10*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 9" Optional="true">*($T11*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 10" Optional="true">*($T12*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 11" Optional="true">*($T13*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 12" Optional="true">*($T14*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 13" Optional="true">*($T15*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 14" Optional="true">*($T16*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 15" Optional="true">*($T17*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 16" Optional="true">*($T18*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 17" Optional="true">*($T19*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 18" Optional="true">*($T20*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 19" Optional="true">*($T21*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 20" Optional="true">*($T22*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 21" Optional="true">*($T23*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 22" Optional="true">*($T24*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 23" Optional="true">*($T25*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 24" Optional="true">*($T26*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 25" Optional="true">*($T27*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 26" Optional="true">*($T28*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 27" Optional="true">*($T29*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 28" Optional="true">*($T30*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 29" Optional="true">*($T31*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 30" Optional="true">*($T32*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 31" Optional="true">*($T33*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 32" Optional="true">*($T34*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 33" Optional="true">*($T35*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 34" Optional="true">*($T36*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 35" Optional="true">*($T37*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 36" Optional="true">*($T38*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 37" Optional="true">*($T39*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 38" Optional="true">*($T40*)&amp;st_</Item>
<Item Name="[value]" Condition="index() == 39" Optional="true">*($T41*)&amp;st_</Item>
</Expand>
</Type>
<Type Name="boost::variant2::detail::variant_base_impl&lt;*,0,*&gt;">
<Intrinsic Name="index" Expression="(int)((ix_-2)/2)"/>
<DisplayString Condition="index() == 0" Optional="true">{{ index=0, value={*($T2*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 1" Optional="true">{{ index=1, value={*($T3*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 2" Optional="true">{{ index=2, value={*($T4*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 3" Optional="true">{{ index=3, value={*($T5*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 4" Optional="true">{{ index=4, value={*($T6*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 5" Optional="true">{{ index=5, value={*($T7*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 6" Optional="true">{{ index=6, value={*($T8*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 7" Optional="true">{{ index=7, value={*($T9*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 8" Optional="true">{{ index=8, value={*($T10*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 9" Optional="true">{{ index=9, value={*($T11*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 10" Optional="true">{{ index=10, value={*($T12*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 11" Optional="true">{{ index=11, value={*($T13*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 12" Optional="true">{{ index=12, value={*($T14*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 13" Optional="true">{{ index=13, value={*($T15*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 14" Optional="true">{{ index=14, value={*($T16*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 15" Optional="true">{{ index=15, value={*($T17*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 16" Optional="true">{{ index=16, value={*($T18*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 17" Optional="true">{{ index=17, value={*($T19*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 18" Optional="true">{{ index=18, value={*($T20*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 19" Optional="true">{{ index=19, value={*($T21*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 20" Optional="true">{{ index=20, value={*($T22*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 21" Optional="true">{{ index=21, value={*($T23*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 22" Optional="true">{{ index=22, value={*($T24*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 23" Optional="true">{{ index=23, value={*($T25*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 24" Optional="true">{{ index=24, value={*($T26*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 25" Optional="true">{{ index=25, value={*($T27*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 26" Optional="true">{{ index=26, value={*($T28*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 27" Optional="true">{{ index=27, value={*($T29*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 28" Optional="true">{{ index=28, value={*($T30*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 29" Optional="true">{{ index=29, value={*($T31*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 30" Optional="true">{{ index=30, value={*($T32*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 31" Optional="true">{{ index=31, value={*($T33*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 32" Optional="true">{{ index=32, value={*($T34*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 33" Optional="true">{{ index=33, value={*($T35*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 34" Optional="true">{{ index=34, value={*($T36*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 35" Optional="true">{{ index=35, value={*($T37*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 36" Optional="true">{{ index=36, value={*($T38*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 37" Optional="true">{{ index=37, value={*($T39*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 38" Optional="true">{{ index=38, value={*($T40*)&amp;st_[ix_%2]} }}</DisplayString>
<DisplayString Condition="index() == 39" Optional="true">{{ index=39, value={*($T41*)&amp;st_[ix_%2]} }}</DisplayString>
<Expand>
<Item Name="index">index()</Item>
<Item Name="[value]" Condition="index() == 0" Optional="true">*($T2*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 1" Optional="true">*($T3*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 2" Optional="true">*($T4*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 3" Optional="true">*($T5*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 4" Optional="true">*($T6*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 5" Optional="true">*($T7*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 6" Optional="true">*($T8*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 7" Optional="true">*($T9*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 8" Optional="true">*($T10*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 9" Optional="true">*($T11*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 10" Optional="true">*($T12*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 11" Optional="true">*($T13*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 12" Optional="true">*($T14*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 13" Optional="true">*($T15*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 14" Optional="true">*($T16*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 15" Optional="true">*($T17*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 16" Optional="true">*($T18*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 17" Optional="true">*($T19*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 18" Optional="true">*($T20*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 19" Optional="true">*($T21*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 20" Optional="true">*($T22*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 21" Optional="true">*($T23*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 22" Optional="true">*($T24*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 23" Optional="true">*($T25*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 24" Optional="true">*($T26*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 25" Optional="true">*($T27*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 26" Optional="true">*($T28*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 27" Optional="true">*($T29*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 28" Optional="true">*($T30*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 29" Optional="true">*($T31*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 30" Optional="true">*($T32*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 31" Optional="true">*($T33*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 32" Optional="true">*($T34*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 33" Optional="true">*($T35*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 34" Optional="true">*($T36*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 35" Optional="true">*($T37*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 36" Optional="true">*($T38*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 37" Optional="true">*($T39*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 38" Optional="true">*($T40*)&amp;st_[ix_%2]</Item>
<Item Name="[value]" Condition="index() == 39" Optional="true">*($T41*)&amp;st_[ix_%2]</Item>
</Expand>
</Type>
</AutoVisualizer>

View 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

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,8 @@
# http://www.boost.org/LICENSE_1_0.txt
import testing ;
import ../../config/checks/config : requires ;
import-search /boost/config/checks ;
import config : requires ;
project
: default-build
@ -16,11 +17,14 @@ project
: requirements
[ requires cxx11_variadic_templates cxx11_template_aliases cxx11_decltype cxx11_constexpr ]
<library>/boost/variant2//boost_variant2
<library>/boost/core//boost_core
<library>/boost/container_hash//boost_container_hash
<toolset>msvc:<warnings-as-errors>on
<toolset>gcc:<warnings-as-errors>on
<toolset>clang:<warnings-as-errors>on
;
run quick.cpp ;
@ -56,10 +60,10 @@ run variant_in_place_type_construct.cpp ;
compile variant_in_place_type_construct_cx.cpp : <toolset>msvc-14.0:<build>no ;
run variant_copy_assign.cpp ;
compile variant_copy_assign_cx.cpp : [ requires cxx14_constexpr ] ;
compile variant_copy_assign_cx.cpp : [ requires cxx14_constexpr ] <toolset>gcc-5:<build>no <toolset>gcc-6:<build>no ;
run variant_move_assign.cpp ;
compile variant_move_assign_cx.cpp : [ requires cxx14_constexpr ] ;
compile variant_move_assign_cx.cpp : [ requires cxx14_constexpr ] <toolset>gcc-5:<build>no <toolset>gcc-6:<build>no ;
run variant_value_assign.cpp ;
compile variant_value_assign_cx.cpp : [ requires cxx14_constexpr ] ;
@ -119,3 +123,37 @@ 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//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 ;
run variant_derived_construct2.cpp ;
compile variant_visit_cx.cpp : [ requires cxx14_constexpr ] ;
compile variant_visit_cx_2.cpp : [ requires cxx14_constexpr ] ;
compile variant_visit_r_cx.cpp : [ requires cxx14_constexpr ] ;
local index-type-reqs =
<variant>release
<toolset>msvc,<address-model>32:<build>no
<toolset>clang,<target-os>linux:<cxxflags>-ftemplate-depth=1024 # for Clang 3.x
;
local list-sizes = 126 127 128 129 254 255 256 257 ;
for local list-size in $(list-sizes)
{
run variant_index_type.cpp : : : $(index-type-reqs) <define>LIST_SIZE=$(list-size) : variant_index_type_$(list-size) ;
}

View File

@ -14,4 +14,4 @@ target_link_libraries(quick Boost::variant2)
enable_testing()
add_test(quick quick)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

View File

@ -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)
@ -16,4 +18,4 @@ target_link_libraries(quick Boost::variant2)
enable_testing()
add_test(quick quick)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

View 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();
}

View File

@ -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;

View 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;
}

View File

@ -0,0 +1,60 @@
// Copyright 2024 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>
struct expr: boost::variant2::variant<bool, int, double>
{
using variant::variant;
};
int main()
{
using boost::variant2::get;
{
expr v{ true };
BOOST_TEST_EQ( v.index(), 0 );
BOOST_TEST_EQ( get<0>(v), true );
}
{
expr v{ 2 };
BOOST_TEST_EQ( v.index(), 1 );
BOOST_TEST_EQ( get<1>(v), 2 );
}
{
expr v{ 3.0 };
BOOST_TEST_EQ( v.index(), 2 );
BOOST_TEST_EQ( get<2>(v), 3.0 );
}
{
expr v( true );
BOOST_TEST_EQ( v.index(), 0 );
BOOST_TEST_EQ( get<0>(v), true );
}
{
expr v( 2 );
BOOST_TEST_EQ( v.index(), 1 );
BOOST_TEST_EQ( get<1>(v), 2 );
}
{
expr v( 3.0 );
BOOST_TEST_EQ( v.index(), 2 );
BOOST_TEST_EQ( get<2>(v), 3.0 );
}
return boost::report_errors();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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

View File

@ -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 );

View File

@ -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) );
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,86 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(_MSC_VER)
# pragma warning( disable: 4503 ) // decorated name length exceeded
#endif
#include <boost/variant2/variant.hpp>
#include <boost/mp11.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::mp11;
template<std::size_t I> struct X
{
};
template<class N> using Xf = X< N::value >;
template<std::size_t I> struct Y
{
Y() = default;
Y( Y&& ) {}
};
template<class N> using Yf = Y< N::value >;
template<std::size_t I> struct Z
{
~Z() {}
};
template<class N> using Zf = Z< N::value >;
template<std::size_t I> struct W
{
~W() {}
W() = default;
W( W&& ) {}
};
template<class N> using Wf = W< N::value >;
template<class L, template<class...> class F> void test()
{
using V = mp_rename< mp_transform<F, L>, boost::variant2::variant >;
constexpr std::size_t N = mp_size<L>::value;
using last_type = F<mp_size_t<N-1>>;
{
V v( last_type{} );
BOOST_TEST_EQ( v.index(), N-1 );
}
{
V v;
BOOST_TEST_EQ( v.index(), 0 );
v.template emplace<last_type>();
BOOST_TEST_EQ( v.index(), N-1 );
}
}
int main()
{
constexpr std::size_t N = LIST_SIZE;
using L = mp_iota_c<N>;
static_assert( !boost::variant2::variant< X<0>, X<1> >::uses_double_storage(), "" );
test<L, Xf>();
static_assert( boost::variant2::variant< Y<0>, Y<1> >::uses_double_storage(), "" );
test<L, Yf>();
static_assert( !boost::variant2::variant< Z<0>, Z<1> >::uses_double_storage(), "" );
test<L, Zf>();
static_assert( boost::variant2::variant< W<0>, W<1> >::uses_double_storage(), "" );
test<L, Wf>();
return boost::report_errors();
}

View File

@ -0,0 +1,47 @@
// Copyright 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/config.hpp>
#if defined(BOOST_GCC) && BOOST_GCC < 50000
# define BOOST_ALLOW_DEPRECATED
#endif
#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();
}

View File

@ -0,0 +1,48 @@
// Copyright 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/config.hpp>
#if defined(BOOST_GCC) && BOOST_GCC < 50000
# define BOOST_ALLOW_DEPRECATED
#endif
#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();
}

View File

@ -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();
}

View File

@ -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

View 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();
}

View 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() );

View File

@ -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 );
}
{

View 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();
}

51
test/variant_visit_cx.cpp Normal file
View File

@ -0,0 +1,51 @@
// Copyright 2017, 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/variant2/variant.hpp>
using namespace boost::variant2;
#if !defined(BOOST_MP11_HAS_CXX14_CONSTEXPR)
#include <boost/config/pragma_message.hpp>
BOOST_PRAGMA_MESSAGE("Skipping constexpr visit test because BOOST_MP11_HAS_CXX14_CONSTEXPR is not defined")
int main() {}
#else
struct X
{
constexpr operator int() const { return 2; }
};
struct F
{
constexpr int operator()( int x ) const
{
return x;
}
};
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
int main()
{
{
constexpr variant<int> v( 1 );
STATIC_ASSERT( visit( F(), v ) == 1 );
}
{
constexpr variant<char, int> v( 'a' );
STATIC_ASSERT( visit( F(), v ) == 'a' );
}
{
constexpr variant<char, int, X> v( X{} );
STATIC_ASSERT( visit( F(), v ) == 2 );
}
}
#endif

View File

@ -0,0 +1,53 @@
// Copyright 2017, 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/variant2/variant.hpp>
#include <boost/config/pragma_message.hpp>
#if !( defined(__cpp_constexpr) && __cpp_constexpr >= 201603L )
BOOST_PRAGMA_MESSAGE("Skipping constexpr visit test because __cpp_constexpr < 201603L")
int main() {}
#elif !defined(BOOST_MP11_HAS_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Skipping constexpr visit test because BOOST_MP11_HAS_CXX14_CONSTEXPR is not defined")
int main() {}
#else
using namespace boost::variant2;
struct F
{
constexpr int operator()( int x1, int x2 ) const
{
return x1 + x2;
}
constexpr int operator()( int x1, int x2, int x3 ) const
{
return x1 + x2 + x3;
}
};
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
int main()
{
{
constexpr variant<char, int> v1( 1 );
constexpr variant<char, int> v2( '2' );
STATIC_ASSERT( visit( F(), v1, v2 ) == 1 + '2' );
}
{
constexpr variant<char, int> v1( 1 );
constexpr variant<char, int> v2( 2 );
constexpr variant<char, int> v3( '3' );
STATIC_ASSERT( visit( F(), v1, v2, v3 ) == 1 + 2 + '3' );
}
}
#endif

View File

@ -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 ) ) {};

View File

@ -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 );
}
{

View File

@ -0,0 +1,52 @@
// Copyright 2017, 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/variant2/variant.hpp>
using namespace boost::variant2;
#if !defined(BOOST_MP11_HAS_CXX14_CONSTEXPR)
#include <boost/config/pragma_message.hpp>
BOOST_PRAGMA_MESSAGE("Skipping constexpr visit test because BOOST_MP11_HAS_CXX14_CONSTEXPR is not defined")
int main() {}
#else
struct X
{
int v;
constexpr operator int() const { return v; }
};
struct F
{
template<class T> constexpr T operator()( T x ) const
{
return x;
}
};
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
int main()
{
{
constexpr variant<int> v( 1 );
STATIC_ASSERT( visit<int>( F(), v ) == 1 );
}
{
constexpr variant<char, int> v( 'a' );
STATIC_ASSERT( visit<int>( F(), v ) == 'a' );
}
{
constexpr variant<char, int, X> v( X{2} );
STATIC_ASSERT( visit<int>( F(), v ) == 2 );
}
}
#endif