mirror of
https://github.com/boostorg/variant2.git
synced 2026-01-13 18:56:59 +01:00
Compare commits
25 Commits
feature/in
...
feature/is
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
155ed414ab | ||
|
|
e6b336ec68 | ||
|
|
799a69eccc | ||
|
|
74f6f0cd96 | ||
|
|
fc786d39b3 | ||
|
|
382cf33824 | ||
|
|
4632862a4b | ||
|
|
48ed0a243f | ||
|
|
936a1a95b5 | ||
|
|
fcdaadb0f5 | ||
|
|
540354878c | ||
|
|
2a5aa1c7ad | ||
|
|
f267609ad6 | ||
|
|
edf1c7925b | ||
|
|
b9d0499a8f | ||
|
|
a63b03286e | ||
|
|
5661f2ba15 | ||
|
|
9d913eb1a0 | ||
|
|
43377dcada | ||
|
|
2af2d02fce | ||
|
|
b2109dee2a | ||
|
|
df001efb54 | ||
|
|
e708866c65 | ||
|
|
28d23c14f6 | ||
|
|
8caa1a3484 |
@@ -34,7 +34,6 @@ local linux_pipeline(name, image, environment, packages = "", sources = [], arch
|
||||
'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 []) +
|
||||
@@ -213,6 +212,13 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
"g++-14-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 25.04 GCC 15 32/64",
|
||||
"cppalliance/droneubuntu2504:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-15', CXXSTD: '11,14,17,20,23,2c', ADDRMD: '32,64' },
|
||||
"g++-15-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 Clang 3.5",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
@@ -340,40 +346,47 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 17 UBSAN",
|
||||
"Linux 24.04 Clang 17",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-17",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 17 ASAN",
|
||||
"Linux 24.04 Clang 18",
|
||||
"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,
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-18",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 18 ASAN",
|
||||
"Linux 24.04 Clang 19",
|
||||
"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,
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-19', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-19",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 20 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-20', CXXSTD: '11,14,17,20,23,2c' } + ubsan,
|
||||
"clang-20",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 20 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-20', CXXSTD: '11,14,17,20,23,2c' } + asan,
|
||||
"clang-20",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 25.10 Clang 21",
|
||||
"cppalliance/droneubuntu2510:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-21', CXXSTD: '11,14,17,20,23,2c' },
|
||||
"clang-21",
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 UBSAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,1z' } + ubsan,
|
||||
@@ -437,4 +450,16 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
"cppalliance/dronevs2022:1",
|
||||
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17', CXXFLAGS: '/permissive-' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2026 msvc-14.5",
|
||||
"cppalliance/dronevs2026:1",
|
||||
{ TOOLSET: 'msvc-14.5', CXXSTD: '14,17,20,latest' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2026 msvc-14.5 permissive-",
|
||||
"cppalliance/dronevs2026:1",
|
||||
{ TOOLSET: 'msvc-14.5', CXXSTD: '14,17', CXXFLAGS: '/permissive-' },
|
||||
),
|
||||
]
|
||||
|
||||
89
.github/workflows/ci.yml
vendored
89
.github/workflows/ci.yml
vendored
@@ -43,22 +43,27 @@ jobs:
|
||||
os: ubuntu-latest
|
||||
- toolset: gcc-8
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: g++-8
|
||||
- toolset: gcc-9
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
- toolset: gcc-10
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-22.04
|
||||
container: ubuntu:22.04
|
||||
os: ubuntu-latest
|
||||
install: g++-10
|
||||
- toolset: gcc-11
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-22.04
|
||||
container: ubuntu:22.04
|
||||
os: ubuntu-latest
|
||||
install: g++-11
|
||||
- toolset: gcc-12
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
container: ubuntu:22.04
|
||||
os: ubuntu-latest
|
||||
install: g++-12
|
||||
- toolset: gcc-13
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
@@ -70,6 +75,11 @@ jobs:
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: g++-14
|
||||
- toolset: gcc-15
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
container: ubuntu:25.04
|
||||
os: ubuntu-latest
|
||||
install: g++-15
|
||||
- toolset: clang
|
||||
compiler: clang++-3.9
|
||||
cxxstd: "11,14"
|
||||
@@ -91,37 +101,44 @@ jobs:
|
||||
- toolset: clang
|
||||
compiler: clang++-6.0
|
||||
cxxstd: "11,14,17"
|
||||
os: ubuntu-20.04
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-6.0
|
||||
- toolset: clang
|
||||
compiler: clang++-7
|
||||
cxxstd: "11,14,17"
|
||||
os: ubuntu-20.04
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-7
|
||||
- toolset: clang
|
||||
compiler: clang++-8
|
||||
cxxstd: "11,14,17"
|
||||
os: ubuntu-20.04
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-8
|
||||
- toolset: clang
|
||||
compiler: clang++-9
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-9
|
||||
- toolset: clang
|
||||
compiler: clang++-10
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-10
|
||||
- toolset: clang
|
||||
compiler: clang++-11
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-11
|
||||
- toolset: clang
|
||||
compiler: clang++-12
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
container: ubuntu:20.04
|
||||
os: ubuntu-latest
|
||||
install: clang-12
|
||||
- toolset: clang
|
||||
compiler: clang++-13
|
||||
@@ -162,18 +179,30 @@ jobs:
|
||||
- toolset: clang
|
||||
compiler: clang++-19
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
container: ubuntu:24.10
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-19
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: macos-13
|
||||
compiler: clang++-20
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-20
|
||||
- toolset: clang
|
||||
compiler: clang++-21
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
container: ubuntu:25.10
|
||||
os: ubuntu-latest
|
||||
install: clang-21
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: macos-14
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
os: macos-15
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
os: macos-26
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -246,14 +275,6 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- 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
|
||||
@@ -265,7 +286,7 @@ jobs:
|
||||
- toolset: gcc
|
||||
cxxstd: "11,14,17,2a"
|
||||
addrmd: 64
|
||||
os: windows-2019
|
||||
os: windows-2022
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -305,12 +326,11 @@ jobs:
|
||||
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
|
||||
- os: macos-26
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -354,12 +374,11 @@ jobs:
|
||||
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
|
||||
- os: macos-26
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -413,12 +432,11 @@ jobs:
|
||||
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
|
||||
- os: macos-26
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -470,8 +488,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
- os: windows-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -519,8 +536,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
- os: windows-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -586,8 +602,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
- os: windows-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ target_link_libraries(boost_variant2
|
||||
Boost::mp11
|
||||
)
|
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.18 AND CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.19 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")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
////
|
||||
Copyright 2019-2022 Peter Dimov
|
||||
Copyright 2019-2025 Peter Dimov
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
https://www.boost.org/LICENSE_1_0.txt
|
||||
////
|
||||
@@ -8,6 +8,15 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
# Revision History
|
||||
:idprefix: changelog_
|
||||
|
||||
## Changes in 1.90.0
|
||||
|
||||
* More functions have been marked as `constexpr`, including `~variant`.
|
||||
This didn't matter before {cpp}20, but does now.
|
||||
|
||||
## Changes in 1.88.0
|
||||
|
||||
* Use the smallest appropriate unsigned type for the index.
|
||||
|
||||
## Changes in 1.83.0
|
||||
|
||||
* Added `uses_double_storage()`.
|
||||
|
||||
@@ -30,6 +30,15 @@
|
||||
|
||||
//
|
||||
|
||||
// constexpr destructors
|
||||
#if defined(__cpp_constexpr_dynamic_alloc) && __cpp_constexpr_dynamic_alloc >= 201907L
|
||||
# define BOOST_VARIANT2_CXX20_CONSTEXPR constexpr
|
||||
#else
|
||||
# define BOOST_VARIANT2_CXX20_CONSTEXPR
|
||||
#endif
|
||||
|
||||
//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
@@ -84,7 +93,7 @@ struct monostate
|
||||
{
|
||||
};
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1950)
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1960)
|
||||
|
||||
constexpr bool operator<(monostate, monostate) noexcept { return false; }
|
||||
constexpr bool operator>(monostate, monostate) noexcept { return false; }
|
||||
@@ -549,24 +558,34 @@ template<class T1, class... T> union variant_storage_impl<mp11::mp_false, T1, T.
|
||||
T1 first_;
|
||||
variant_storage<T...> rest_;
|
||||
|
||||
#if defined(BOOST_GCC) && (__GNUC__ >= 12)
|
||||
// false positive, see https://github.com/boostorg/variant2/issues/55
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
|
||||
template<class... A> constexpr variant_storage_impl( mp11::mp_size_t<0>, A&&... a ): first_( std::forward<A>(a)... )
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(BOOST_GCC) && (__GNUC__ >= 12)
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
template<std::size_t I, class... A> constexpr variant_storage_impl( mp11::mp_size_t<I>, A&&... a ): rest_( mp11::mp_size_t<I-1>(), std::forward<A>(a)... )
|
||||
{
|
||||
}
|
||||
|
||||
~variant_storage_impl()
|
||||
BOOST_VARIANT2_CXX20_CONSTEXPR ~variant_storage_impl()
|
||||
{
|
||||
}
|
||||
|
||||
template<class... A> void emplace( mp11::mp_size_t<0>, A&&... a )
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<0>, A&&... a )
|
||||
{
|
||||
::new( &first_ ) T1( std::forward<A>(a)... );
|
||||
}
|
||||
|
||||
template<std::size_t I, class... A> void emplace( mp11::mp_size_t<I>, A&&... a )
|
||||
template<std::size_t I, class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<I>, A&&... a )
|
||||
{
|
||||
rest_.emplace( mp11::mp_size_t<I-1>(), std::forward<A>(a)... );
|
||||
}
|
||||
@@ -606,22 +625,22 @@ template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, c
|
||||
|
||||
template<std::size_t I, class... A> constexpr variant_storage_impl( mp11::mp_size_t<I>, A&&... a ): rest_( mp11::mp_size_t<I-10>(), std::forward<A>(a)... ) {}
|
||||
|
||||
~variant_storage_impl()
|
||||
BOOST_VARIANT2_CXX20_CONSTEXPR ~variant_storage_impl()
|
||||
{
|
||||
}
|
||||
|
||||
template<class... A> void emplace( mp11::mp_size_t<0>, A&&... a ) { ::new( &t0_ ) T0( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace( mp11::mp_size_t<1>, A&&... a ) { ::new( &t1_ ) T1( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace( mp11::mp_size_t<2>, A&&... a ) { ::new( &t2_ ) T2( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace( mp11::mp_size_t<3>, A&&... a ) { ::new( &t3_ ) T3( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace( mp11::mp_size_t<4>, A&&... a ) { ::new( &t4_ ) T4( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace( mp11::mp_size_t<5>, A&&... a ) { ::new( &t5_ ) T5( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace( mp11::mp_size_t<6>, A&&... a ) { ::new( &t6_ ) T6( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace( mp11::mp_size_t<7>, A&&... a ) { ::new( &t7_ ) T7( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace( mp11::mp_size_t<8>, A&&... a ) { ::new( &t8_ ) T8( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace( mp11::mp_size_t<9>, A&&... a ) { ::new( &t9_ ) T9( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<0>, A&&... a ) { ::new( &t0_ ) T0( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<1>, A&&... a ) { ::new( &t1_ ) T1( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<2>, A&&... a ) { ::new( &t2_ ) T2( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<3>, A&&... a ) { ::new( &t3_ ) T3( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<4>, A&&... a ) { ::new( &t4_ ) T4( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<5>, A&&... a ) { ::new( &t5_ ) T5( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<6>, A&&... a ) { ::new( &t6_ ) T6( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<7>, A&&... a ) { ::new( &t7_ ) T7( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<8>, A&&... a ) { ::new( &t8_ ) T8( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<9>, A&&... a ) { ::new( &t9_ ) T9( std::forward<A>(a)... ); }
|
||||
|
||||
template<std::size_t I, class... A> void emplace( mp11::mp_size_t<I>, A&&... a )
|
||||
template<std::size_t I, class... A> BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t<I>, A&&... a )
|
||||
{
|
||||
rest_.emplace( mp11::mp_size_t<I-10>(), std::forward<A>(a)... );
|
||||
}
|
||||
@@ -674,7 +693,7 @@ template<class T1, class... T> union variant_storage_impl<mp11::mp_true, T1, T..
|
||||
{
|
||||
}
|
||||
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<0>, A&&... a )
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<0>, A&&... a )
|
||||
{
|
||||
::new( &first_ ) T1( std::forward<A>(a)... );
|
||||
}
|
||||
@@ -695,6 +714,7 @@ template<class T1, class... T> union variant_storage_impl<mp11::mp_true, T1, T..
|
||||
# pragma GCC diagnostic ignored "-Wuninitialized"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
*this = variant_storage_impl( mp11::mp_size_t<I>(), std::forward<A>(a)... );
|
||||
|
||||
#if defined(BOOST_GCC) && (__GNUC__ >= 7)
|
||||
@@ -742,16 +762,16 @@ template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, c
|
||||
|
||||
template<std::size_t I, class... A> constexpr variant_storage_impl( mp11::mp_size_t<I>, A&&... a ): rest_( mp11::mp_size_t<I-10>(), std::forward<A>(a)... ) {}
|
||||
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<0>, A&&... a ) { ::new( &t0_ ) T0( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<1>, A&&... a ) { ::new( &t1_ ) T1( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<2>, A&&... a ) { ::new( &t2_ ) T2( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<3>, A&&... a ) { ::new( &t3_ ) T3( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<4>, A&&... a ) { ::new( &t4_ ) T4( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<5>, A&&... a ) { ::new( &t5_ ) T5( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<6>, A&&... a ) { ::new( &t6_ ) T6( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<7>, A&&... a ) { ::new( &t7_ ) T7( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<8>, A&&... a ) { ::new( &t8_ ) T8( std::forward<A>(a)... ); }
|
||||
template<class... A> void emplace_impl( mp11::mp_false, mp11::mp_size_t<9>, A&&... a ) { ::new( &t9_ ) T9( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<0>, A&&... a ) { ::new( &t0_ ) T0( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<1>, A&&... a ) { ::new( &t1_ ) T1( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<2>, A&&... a ) { ::new( &t2_ ) T2( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<3>, A&&... a ) { ::new( &t3_ ) T3( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<4>, A&&... a ) { ::new( &t4_ ) T4( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<5>, A&&... a ) { ::new( &t5_ ) T5( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<6>, A&&... a ) { ::new( &t6_ ) T6( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<7>, A&&... a ) { ::new( &t7_ ) T7( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<8>, A&&... a ) { ::new( &t8_ ) T8( std::forward<A>(a)... ); }
|
||||
template<class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<9>, A&&... a ) { ::new( &t9_ ) T9( std::forward<A>(a)... ); }
|
||||
|
||||
template<std::size_t I, class... A> BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t<I>, A&&... a )
|
||||
{
|
||||
@@ -890,7 +910,7 @@ template<class... T> struct variant_base_impl<true, true, T...>
|
||||
}
|
||||
|
||||
// requires: ix_ == 0
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
template<class I, class... A> BOOST_CXX14_CONSTEXPR void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &st_ ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
|
||||
@@ -974,7 +994,7 @@ template<class... T> struct variant_base_impl<true, false, T...>
|
||||
}
|
||||
|
||||
// requires: ix_ == 0
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
template<class I, class... A> BOOST_CXX14_CONSTEXPR void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &st_[ 0 ] ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
|
||||
@@ -1042,7 +1062,7 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
}
|
||||
|
||||
// requires: ix_ == 0
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
template<class I, class... A> BOOST_CXX14_CONSTEXPR void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &st_ ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
|
||||
@@ -1059,14 +1079,25 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
{
|
||||
variant_base_impl * this_;
|
||||
|
||||
template<class I> void operator()( I ) const noexcept
|
||||
template<class I> BOOST_CXX14_CONSTEXPR void operator()( I ) const noexcept
|
||||
{
|
||||
using U = mp11::mp_at<mp11::mp_list<none, T...>, I>;
|
||||
|
||||
#if defined(BOOST_GCC) && (__GNUC__ >= 12)
|
||||
// false positive, see https://github.com/boostorg/variant2/issues/55
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
|
||||
this_->st_.get( I() ).~U();
|
||||
|
||||
#if defined(BOOST_GCC) && (__GNUC__ >= 12)
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
void _destroy() noexcept
|
||||
BOOST_CXX14_CONSTEXPR void _destroy() noexcept
|
||||
{
|
||||
if( ix_ > 0 )
|
||||
{
|
||||
@@ -1074,7 +1105,7 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
}
|
||||
}
|
||||
|
||||
~variant_base_impl() noexcept
|
||||
BOOST_VARIANT2_CXX20_CONSTEXPR ~variant_base_impl() noexcept
|
||||
{
|
||||
_destroy();
|
||||
}
|
||||
@@ -1102,7 +1133,7 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
return st_.get( mp11::mp_size_t<I+1>() );
|
||||
}
|
||||
|
||||
template<std::size_t I, class... A> void emplace( A&&... a )
|
||||
template<std::size_t I, class... A> BOOST_CXX14_CONSTEXPR void emplace( A&&... a )
|
||||
{
|
||||
std::size_t const J = I+1;
|
||||
|
||||
@@ -1110,8 +1141,18 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
|
||||
static_assert( std::is_nothrow_move_constructible<U>::value, "Logic error: U must be nothrow move constructible" );
|
||||
|
||||
#if defined(BOOST_GCC) && (__GNUC__ >= 12)
|
||||
// false positive, see https://github.com/boostorg/variant2/issues/55
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
|
||||
U tmp( std::forward<A>(a)... );
|
||||
|
||||
#if defined(BOOST_GCC) && (__GNUC__ >= 12)
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
_destroy();
|
||||
|
||||
st_.emplace( mp11::mp_size_t<J>(), std::move(tmp) );
|
||||
@@ -1182,7 +1223,7 @@ template<class... T> struct variant_base_impl<false, false, T...>
|
||||
#endif
|
||||
|
||||
// requires: ix_ == 0
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
template<class I, class... A> BOOST_CXX14_CONSTEXPR void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &storage( 0 ) ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
|
||||
@@ -1200,19 +1241,19 @@ template<class... T> struct variant_base_impl<false, false, T...>
|
||||
variant_base_impl * this_;
|
||||
unsigned i2_;
|
||||
|
||||
template<class I> void operator()( I ) const noexcept
|
||||
template<class I> BOOST_CXX14_CONSTEXPR void operator()( I ) const noexcept
|
||||
{
|
||||
using U = mp11::mp_at<mp11::mp_list<none, T...>, I>;
|
||||
this_->storage( i2_ ).get( I() ).~U();
|
||||
}
|
||||
};
|
||||
|
||||
void _destroy() noexcept
|
||||
BOOST_CXX14_CONSTEXPR void _destroy() noexcept
|
||||
{
|
||||
mp11::mp_with_index<1 + sizeof...(T)>( ix_ / 2, _destroy_L1{ this, static_cast<unsigned>( ix_ & 1 ) } );
|
||||
}
|
||||
|
||||
~variant_base_impl() noexcept
|
||||
BOOST_VARIANT2_CXX20_CONSTEXPR ~variant_base_impl() noexcept
|
||||
{
|
||||
_destroy();
|
||||
}
|
||||
@@ -1242,7 +1283,7 @@ template<class... T> struct variant_base_impl<false, false, T...>
|
||||
return storage( ix_ & 1 ).get( mp11::mp_size_t<I+1>() );
|
||||
}
|
||||
|
||||
template<std::size_t I, class... A> void emplace( A&&... a )
|
||||
template<std::size_t I, class... A> BOOST_CXX14_CONSTEXPR void emplace( A&&... a )
|
||||
{
|
||||
std::size_t const J = I+1;
|
||||
|
||||
@@ -1403,7 +1444,7 @@ private:
|
||||
variant_base * this_;
|
||||
variant_base const & r;
|
||||
|
||||
template<class I> void operator()( I i ) const
|
||||
template<class I> BOOST_CXX14_CONSTEXPR void operator()( I i ) const
|
||||
{
|
||||
this_->_replace( i, r._get_impl( i ) );
|
||||
}
|
||||
@@ -1411,7 +1452,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
variant_cc_base_impl( variant_cc_base_impl const& r )
|
||||
BOOST_CXX14_CONSTEXPR variant_cc_base_impl( variant_cc_base_impl const& r )
|
||||
noexcept( mp11::mp_all<std::is_nothrow_copy_constructible<T>...>::value )
|
||||
: variant_base()
|
||||
{
|
||||
@@ -1483,7 +1524,7 @@ private:
|
||||
variant_base * this_;
|
||||
variant_base const & r;
|
||||
|
||||
template<class I> void operator()( I i ) const
|
||||
template<class I> BOOST_CXX14_CONSTEXPR void operator()( I i ) const
|
||||
{
|
||||
this_->template emplace<I::value>( r._get_impl( i ) );
|
||||
}
|
||||
@@ -1557,7 +1598,7 @@ private:
|
||||
variant_base * this_;
|
||||
variant_base & r;
|
||||
|
||||
template<class I> void operator()( I i ) const
|
||||
template<class I> BOOST_CXX14_CONSTEXPR void operator()( I i ) const
|
||||
{
|
||||
this_->_replace( i, std::move( r._get_impl( i ) ) );
|
||||
}
|
||||
@@ -1565,7 +1606,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
variant_mc_base_impl( variant_mc_base_impl && r )
|
||||
BOOST_CXX14_CONSTEXPR variant_mc_base_impl( variant_mc_base_impl && r )
|
||||
noexcept( mp11::mp_all<std::is_nothrow_move_constructible<T>...>::value )
|
||||
{
|
||||
mp11::mp_with_index<sizeof...(T)>( r.index(), L2{ this, r } );
|
||||
@@ -1636,7 +1677,7 @@ private:
|
||||
variant_base * this_;
|
||||
variant_base & r;
|
||||
|
||||
template<class I> void operator()( I i ) const
|
||||
template<class I> BOOST_CXX14_CONSTEXPR void operator()( I i ) const
|
||||
{
|
||||
this_->template emplace<I::value>( std::move( r._get_impl( i ) ) );
|
||||
}
|
||||
@@ -1644,7 +1685,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
variant_ma_base_impl& operator=( variant_ma_base_impl && r )
|
||||
BOOST_CXX14_CONSTEXPR variant_ma_base_impl& operator=( variant_ma_base_impl && r )
|
||||
noexcept( mp11::mp_all<std::is_nothrow_move_constructible<T>...>::value )
|
||||
{
|
||||
mp11::mp_with_index<sizeof...(T)>( r.index(), L4{ this, r } );
|
||||
@@ -1680,7 +1721,7 @@ public:
|
||||
class Ud = typename std::decay<U>::type,
|
||||
class E1 = typename std::enable_if< !std::is_same<Ud, variant>::value && !std::is_base_of<variant, Ud>::value && !detail::is_in_place_index<Ud>::value && !detail::is_in_place_type<Ud>::value >::type,
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1950)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1960)
|
||||
|
||||
class V = mp11::mp_apply_q< mp11::mp_bind_front<detail::resolve_overload_type, U&&>, variant >,
|
||||
|
||||
@@ -1790,7 +1831,7 @@ private:
|
||||
variant * this_;
|
||||
variant & r;
|
||||
|
||||
template<class I> void operator()( I i ) const
|
||||
template<class I> BOOST_CXX14_CONSTEXPR void operator()( I i ) const
|
||||
{
|
||||
using std::swap;
|
||||
swap( this_->_get_impl( i ), r._get_impl( i ) );
|
||||
@@ -1799,7 +1840,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
void swap( variant& r ) noexcept( mp11::mp_all<std::is_nothrow_move_constructible<T>..., detail::is_nothrow_swappable<T>...>::value )
|
||||
BOOST_CXX14_CONSTEXPR void swap( variant& r ) noexcept( mp11::mp_all<std::is_nothrow_move_constructible<T>..., detail::is_nothrow_swappable<T>...>::value )
|
||||
{
|
||||
if( index() == r.index() )
|
||||
{
|
||||
@@ -1826,7 +1867,7 @@ private:
|
||||
variant_base * this_;
|
||||
variant<U...> const & r;
|
||||
|
||||
template<class I> void operator()( I i ) const
|
||||
template<class I> BOOST_CXX14_CONSTEXPR void operator()( I i ) const
|
||||
{
|
||||
using J = mp11::mp_find<mp11::mp_list<T...>, mp11::mp_at<mp11::mp_list<U...>, I>>;
|
||||
this_->_replace( J{}, r._get_impl( i ) );
|
||||
@@ -1837,7 +1878,7 @@ public:
|
||||
|
||||
template<class... U,
|
||||
class E2 = mp11::mp_if<mp11::mp_all<std::is_copy_constructible<U>..., mp11::mp_contains<mp11::mp_list<T...>, U>...>, void> >
|
||||
variant( variant<U...> const& r )
|
||||
BOOST_CXX14_CONSTEXPR variant( variant<U...> const& r )
|
||||
noexcept( mp11::mp_all<std::is_nothrow_copy_constructible<U>...>::value )
|
||||
{
|
||||
mp11::mp_with_index<sizeof...(U)>( r.index(), L6<U...>{ this, r } );
|
||||
@@ -1850,7 +1891,7 @@ private:
|
||||
variant_base * this_;
|
||||
variant<U...> & r;
|
||||
|
||||
template<class I> void operator()( I i ) const
|
||||
template<class I> BOOST_CXX14_CONSTEXPR void operator()( I i ) const
|
||||
{
|
||||
using J = mp11::mp_find<mp11::mp_list<T...>, mp11::mp_at<mp11::mp_list<U...>, I>>;
|
||||
this_->_replace( J{}, std::move( r._get_impl( i ) ) );
|
||||
@@ -1861,7 +1902,7 @@ public:
|
||||
|
||||
template<class... U,
|
||||
class E2 = mp11::mp_if<mp11::mp_all<std::is_move_constructible<U>..., mp11::mp_contains<mp11::mp_list<T...>, U>...>, void> >
|
||||
variant( variant<U...> && r )
|
||||
BOOST_CXX14_CONSTEXPR variant( variant<U...> && r )
|
||||
noexcept( mp11::mp_all<std::is_nothrow_move_constructible<U>...>::value )
|
||||
{
|
||||
mp11::mp_with_index<sizeof...(U)>( r.index(), L7<U...>{ this, r } );
|
||||
@@ -1887,7 +1928,7 @@ private:
|
||||
{
|
||||
variant * this_;
|
||||
|
||||
template<class I> variant<U...> operator()( I i ) const
|
||||
template<class I> BOOST_CXX14_CONSTEXPR variant<U...> operator()( I i ) const
|
||||
{
|
||||
using J = mp11::mp_find<mp11::mp_list<U...>, mp11::mp_at<mp11::mp_list<T...>, I>>;
|
||||
return this_->_subset_impl<U...>( J{}, this_->_get_impl( i ) );
|
||||
@@ -1909,7 +1950,7 @@ private:
|
||||
{
|
||||
variant const * this_;
|
||||
|
||||
template<class I> variant<U...> operator()( I i ) const
|
||||
template<class I> BOOST_CXX14_CONSTEXPR variant<U...> operator()( I i ) const
|
||||
{
|
||||
using J = mp11::mp_find<mp11::mp_list<U...>, mp11::mp_at<mp11::mp_list<T...>, I>>;
|
||||
return this_->_subset_impl<U...>( J{}, this_->_get_impl( i ) );
|
||||
@@ -1931,7 +1972,7 @@ private:
|
||||
{
|
||||
variant * this_;
|
||||
|
||||
template<class I> variant<U...> operator()( I i ) const
|
||||
template<class I> BOOST_CXX14_CONSTEXPR variant<U...> operator()( I i ) const
|
||||
{
|
||||
using J = mp11::mp_find<mp11::mp_list<U...>, mp11::mp_at<mp11::mp_list<T...>, I>>;
|
||||
return this_->_subset_impl<U...>( J{}, std::move( this_->_get_impl( i ) ) );
|
||||
@@ -1957,7 +1998,7 @@ private:
|
||||
{
|
||||
variant const * this_;
|
||||
|
||||
template<class I> variant<U...> operator()( I i ) const
|
||||
template<class I> BOOST_CXX14_CONSTEXPR variant<U...> operator()( I i ) const
|
||||
{
|
||||
using J = mp11::mp_find<mp11::mp_list<U...>, mp11::mp_at<mp11::mp_list<T...>, I>>;
|
||||
return this_->_subset_impl<U...>( J{}, std::move( this_->_get_impl( i ) ) );
|
||||
@@ -2293,7 +2334,7 @@ template<class R = detail::deduced, class F, class V1, class V2, class... V> con
|
||||
// specialized algorithms
|
||||
template<class... T,
|
||||
class E = typename std::enable_if<mp11::mp_all<std::is_move_constructible<T>..., detail::is_swappable<T>...>::value>::type>
|
||||
void swap( variant<T...> & v, variant<T...> & w )
|
||||
BOOST_CXX14_CONSTEXPR void swap( variant<T...> & v, variant<T...> & w )
|
||||
noexcept( noexcept(v.swap(w)) )
|
||||
{
|
||||
v.swap( w );
|
||||
|
||||
@@ -6,6 +6,6 @@ include(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
|
||||
|
||||
if(HAVE_BOOST_TEST)
|
||||
|
||||
boost_test_jamfile(FILE Jamfile LINK_LIBRARIES Boost::variant2 Boost::core Boost::container_hash)
|
||||
boost_test_jamfile(FILE Jamfile LINK_LIBRARIES Boost::variant2 Boost::core Boost::container_hash Boost::system)
|
||||
|
||||
endif()
|
||||
|
||||
26
test/Jamfile
26
test/Jamfile
@@ -131,7 +131,13 @@ 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" ;
|
||||
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"
|
||||
"<toolset>gcc-4.9:<build>no"
|
||||
;
|
||||
|
||||
run variant_json_value_from.cpp : : : $(JSON) ;
|
||||
run variant_json_value_to.cpp : : : $(JSON) ;
|
||||
@@ -157,3 +163,21 @@ 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) ;
|
||||
}
|
||||
|
||||
compile variant_default_construct_cx_2.cpp ;
|
||||
compile variant_default_construct_cx_3.cpp ;
|
||||
compile variant_default_construct_cx_4.cpp ;
|
||||
compile variant_default_construct_cx_5.cpp ;
|
||||
|
||||
compile variant_value_construct_cx_2.cpp ;
|
||||
compile variant_value_construct_cx_3.cpp ;
|
||||
compile variant_value_construct_cx_4.cpp ;
|
||||
|
||||
# GCC 12+ false positive -Wmaybe-uninitialized with non-trivially-copyable types
|
||||
run variant_issue_55.cpp
|
||||
: : :
|
||||
<library>/boost/system//boost_system
|
||||
|
||||
# clang-cl 32 bit fails with an assertion in mp_with_index, likely due to a codegen bug
|
||||
"<toolset>clang-win,<address-model>32:<build>no"
|
||||
;
|
||||
|
||||
@@ -45,7 +45,7 @@ void test()
|
||||
variant<Y1, Y2> v1( in_place_type_t<Y1>{} );
|
||||
variant<Y1, Y2> v2( in_place_type_t<Y2>{} );
|
||||
|
||||
BOOST_TEST_THROWS( v1 = v2, std::runtime_error )
|
||||
BOOST_TEST_THROWS( v1 = v2, std::runtime_error );
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
32
test/variant_default_construct_cx_2.cpp
Normal file
32
test/variant_default_construct_cx_2.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2025 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/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(__cpp_constexpr_dynamic_alloc) || __cpp_constexpr_dynamic_alloc < 201907L
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr destructor test because __cpp_constexpr_dynamic_alloc < 201907L")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr ~X() {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
constexpr variant<int, X> v;
|
||||
|
||||
STATIC_ASSERT( v.index() == 0 );
|
||||
STATIC_ASSERT( get<0>(v) == 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
37
test/variant_default_construct_cx_3.cpp
Normal file
37
test/variant_default_construct_cx_3.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2025 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/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(__cpp_constexpr_dynamic_alloc) || __cpp_constexpr_dynamic_alloc < 201907L
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr destructor test because __cpp_constexpr_dynamic_alloc < 201907L")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION < 180000
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr destructor test because BOOST_CLANG_VERSION < 180000")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
struct X
|
||||
{
|
||||
~X() {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
constexpr variant<int, X> v;
|
||||
|
||||
STATIC_ASSERT( v.index() == 0 );
|
||||
STATIC_ASSERT( get<0>(v) == 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
33
test/variant_default_construct_cx_4.cpp
Normal file
33
test/variant_default_construct_cx_4.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2025 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/config/pragma_message.hpp>
|
||||
#include <string>
|
||||
|
||||
#if !defined(__cpp_constexpr_dynamic_alloc) || __cpp_constexpr_dynamic_alloc < 201907L
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr destructor test because __cpp_constexpr_dynamic_alloc < 201907L")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION < 180000
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr destructor test because BOOST_CLANG_VERSION < 180000")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
int main()
|
||||
{
|
||||
constexpr variant<int, std::string> v;
|
||||
|
||||
STATIC_ASSERT( v.index() == 0 );
|
||||
STATIC_ASSERT( get<0>(v) == 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
49
test/variant_default_construct_cx_5.cpp
Normal file
49
test/variant_default_construct_cx_5.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2025 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/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(__cpp_constexpr_dynamic_alloc) || __cpp_constexpr_dynamic_alloc < 201907L
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr destructor test because __cpp_constexpr_dynamic_alloc < 201907L")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC < 1960
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr destructor test because BOOST_MSVC < 1960")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION < 180000
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr destructor test because BOOST_CLANG_VERSION < 180000")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
constexpr ~Y() {}
|
||||
};
|
||||
|
||||
struct Z
|
||||
{
|
||||
~Z() {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
constexpr variant<X, Y, Z> v;
|
||||
STATIC_ASSERT( v.index() == 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
194
test/variant_issue_55.cpp
Normal file
194
test/variant_issue_55.cpp
Normal file
@@ -0,0 +1,194 @@
|
||||
// Copyright 2025 Peter Dimov
|
||||
// Copyright 2025 Vinnie Falco
|
||||
//
|
||||
// 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
|
||||
|
||||
// GCC 12+ -Wmaybe-uninitialized false positive tests
|
||||
// https://github.com/boostorg/variant2/issues/55
|
||||
//
|
||||
// GCC 12+'s improved dataflow analysis sees code paths for all alternatives
|
||||
// in mp_with_index and warns that members may be uninitialized, even though
|
||||
// the variant's discriminator guarantees only initialized alternatives are
|
||||
// accessed.
|
||||
|
||||
#include <boost/system/result.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
// Check for C++17 std::optional support
|
||||
#if BOOST_CXX_VERSION >= 201703L
|
||||
# include <optional>
|
||||
# define BOOST_VARIANT2_TEST_HAS_OPTIONAL 1
|
||||
#endif
|
||||
|
||||
// Check for C++20 coroutine support
|
||||
#if defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L
|
||||
# include <coroutine>
|
||||
# define BOOST_VARIANT2_TEST_HAS_CORO 1
|
||||
#endif
|
||||
|
||||
using result_void = boost::system::result<void, std::exception_ptr>;
|
||||
using result_string = boost::system::result<std::string, std::exception_ptr>;
|
||||
|
||||
void testGccUninitialized()
|
||||
{
|
||||
// Test 1: Simple copy construction
|
||||
{
|
||||
result_void r1;
|
||||
result_void r2(r1);
|
||||
(void)r2;
|
||||
}
|
||||
|
||||
// Test 2: Copy assignment
|
||||
{
|
||||
result_void r1;
|
||||
result_void r2;
|
||||
r2 = r1;
|
||||
(void)r2;
|
||||
}
|
||||
|
||||
#ifdef BOOST_VARIANT2_TEST_HAS_OPTIONAL
|
||||
// Test 3: std::optional assignment (matches spawn pattern)
|
||||
{
|
||||
std::optional<result_void> opt;
|
||||
opt = result_void{};
|
||||
(void)opt;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Test 4: Pass to function via copy
|
||||
{
|
||||
auto fn = [](result_void r) { (void)r; };
|
||||
fn(result_void{});
|
||||
}
|
||||
|
||||
#ifdef BOOST_VARIANT2_TEST_HAS_OPTIONAL
|
||||
// Test 5: Lambda capture + optional (closest to spawn)
|
||||
{
|
||||
auto fn = [](result_void r) {
|
||||
std::optional<result_void> opt;
|
||||
opt = r;
|
||||
return opt.has_value();
|
||||
};
|
||||
(void)fn(result_void{});
|
||||
}
|
||||
#endif
|
||||
|
||||
// Test 6: Non-void result with string (triggers string warning)
|
||||
{
|
||||
result_string r1;
|
||||
result_string r2(r1);
|
||||
(void)r2;
|
||||
}
|
||||
|
||||
// Test 7: Assign exception to result holding value
|
||||
{
|
||||
result_string r1{"hello"};
|
||||
r1 = std::make_exception_ptr(std::runtime_error("test"));
|
||||
(void)r1;
|
||||
}
|
||||
|
||||
#ifdef BOOST_VARIANT2_TEST_HAS_OPTIONAL
|
||||
// Test 8: Optional with string result
|
||||
{
|
||||
std::optional<result_string> opt;
|
||||
opt = result_string{};
|
||||
(void)opt;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_VARIANT2_TEST_HAS_CORO
|
||||
// Minimal fire-and-forget coroutine for testing
|
||||
struct fire_and_forget
|
||||
{
|
||||
struct promise_type
|
||||
{
|
||||
fire_and_forget get_return_object() { return {}; }
|
||||
std::suspend_never initial_suspend() noexcept { return {}; }
|
||||
std::suspend_never final_suspend() noexcept { return {}; }
|
||||
void return_void() {}
|
||||
void unhandled_exception() { std::terminate(); }
|
||||
};
|
||||
};
|
||||
|
||||
// Test 9: Coroutine returning result (mimics spawn)
|
||||
{
|
||||
auto coro = []() -> fire_and_forget {
|
||||
result_void r{};
|
||||
(void)r;
|
||||
co_return;
|
||||
};
|
||||
coro();
|
||||
}
|
||||
|
||||
// Test 10: Coroutine with handler call (closest to actual spawn)
|
||||
{
|
||||
std::optional<result_void> received;
|
||||
auto handler = [&](result_void r) {
|
||||
received = r;
|
||||
};
|
||||
auto coro = [&]() -> fire_and_forget {
|
||||
handler(result_void{});
|
||||
co_return;
|
||||
};
|
||||
coro();
|
||||
(void)received;
|
||||
}
|
||||
|
||||
// Test 11: Coroutine with try/catch like spawn
|
||||
{
|
||||
std::optional<result_void> received;
|
||||
auto handler = [&](result_void r) {
|
||||
received = r;
|
||||
};
|
||||
auto coro = [&]() -> fire_and_forget {
|
||||
try
|
||||
{
|
||||
handler(result_void{});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
handler(result_void{std::current_exception()});
|
||||
}
|
||||
co_return;
|
||||
};
|
||||
coro();
|
||||
(void)received;
|
||||
}
|
||||
|
||||
// Test 12: Coroutine with string result
|
||||
{
|
||||
std::optional<result_string> received;
|
||||
auto handler = [&](result_string r) {
|
||||
received = r;
|
||||
};
|
||||
auto coro = [&]() -> fire_and_forget {
|
||||
try
|
||||
{
|
||||
handler(result_string{"test"});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
handler(result_string{std::current_exception()});
|
||||
}
|
||||
co_return;
|
||||
};
|
||||
coro();
|
||||
(void)received;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::core::lwt_init();
|
||||
|
||||
testGccUninitialized();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -45,7 +45,7 @@ void test()
|
||||
variant<Y1, Y2> v1( in_place_type_t<Y1>{} );
|
||||
variant<Y1, Y2> v2( in_place_type_t<Y2>{} );
|
||||
|
||||
BOOST_TEST_THROWS( v1 = std::move( v2 ), std::runtime_error )
|
||||
BOOST_TEST_THROWS( v1 = std::move( v2 ), std::runtime_error );
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
32
test/variant_value_construct_cx_2.cpp
Normal file
32
test/variant_value_construct_cx_2.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2025 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/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(__cpp_constexpr_dynamic_alloc) || __cpp_constexpr_dynamic_alloc < 201907L
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because __cpp_constexpr_dynamic_alloc < 201907L")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr ~X() {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
constexpr variant<X, int> v( 5 );
|
||||
|
||||
STATIC_ASSERT( v.index() == 1 );
|
||||
STATIC_ASSERT( get<1>(v) == 5 );
|
||||
}
|
||||
|
||||
#endif
|
||||
37
test/variant_value_construct_cx_3.cpp
Normal file
37
test/variant_value_construct_cx_3.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2025 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/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(__cpp_constexpr_dynamic_alloc) || __cpp_constexpr_dynamic_alloc < 201907L
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because __cpp_constexpr_dynamic_alloc < 201907L")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION < 180000
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_CLANG_VERSION < 180000")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
struct X
|
||||
{
|
||||
~X() {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
constexpr variant<X, int> v( 5 );
|
||||
|
||||
STATIC_ASSERT( v.index() == 1 );
|
||||
STATIC_ASSERT( get<1>(v) == 5 );
|
||||
}
|
||||
|
||||
#endif
|
||||
56
test/variant_value_construct_cx_4.cpp
Normal file
56
test/variant_value_construct_cx_4.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright 2025 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/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(__cpp_constexpr_dynamic_alloc) || __cpp_constexpr_dynamic_alloc < 201907L
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because __cpp_constexpr_dynamic_alloc < 201907L")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC < 1960
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_MSVC < 1960")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION < 180000
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_CLANG_VERSION < 180000")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
constexpr ~Y() {}
|
||||
};
|
||||
|
||||
struct Z
|
||||
{
|
||||
~Z() {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
constexpr variant<X, Y, Z> v( X{} );
|
||||
STATIC_ASSERT( v.index() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<X, Y, Z> v( Y{} );
|
||||
STATIC_ASSERT( v.index() == 1 );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user