mirror of
https://github.com/boostorg/variant2.git
synced 2025-06-25 12:01:36 +02:00
Compare commits
41 Commits
boost-1.86
...
develop
Author | SHA1 | Date | |
---|---|---|---|
8caa1a3484 | |||
6669e07071 | |||
df84f1f146 | |||
2630b3e572 | |||
010c78598e | |||
d77d61c8ec | |||
8f6918554e | |||
183aea23a9 | |||
7c64abd41c | |||
7b8e8c33bb | |||
2f5dbc19b5 | |||
639bd0232b | |||
94749d088d | |||
e2fc107ac7 | |||
306a602d19 | |||
509ce1dc77 | |||
47e544959f | |||
8333e9af93 | |||
19b75fffe4 | |||
bdc1098c80 | |||
9061e427c2 | |||
1202390861 | |||
79061e470f | |||
a4b167b723 | |||
c7c5eb2510 | |||
acf24454d8 | |||
f78343e18d | |||
ea4394914c | |||
f5cd36af3d | |||
0e325dcf8d | |||
e3cf721a23 | |||
d4f0e57b36 | |||
f874a2cb1b | |||
fc088e7273 | |||
4f207d7363 | |||
429a82a52e | |||
bb13b5be08 | |||
1324e32b33 | |||
02303d662e | |||
09f3802347 | |||
5c34125b14 |
@ -32,6 +32,8 @@ local linux_pipeline(name, image, environment, packages = "", sources = [], arch
|
||||
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 []) +
|
||||
@ -99,7 +101,7 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
linux_pipeline(
|
||||
"Linux 16.04 GCC 4.8 32/64",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11', ADDRMD: '32,64' },
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-4.8', CXXSTD: '11', ADDRMD: '32,64' },
|
||||
"g++-4.8-multilib",
|
||||
),
|
||||
|
||||
@ -177,44 +179,37 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 23.04 GCC 13 32 ASAN",
|
||||
"cppalliance/droneubuntu2304:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' } + asan,
|
||||
"g++-13-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 23.04 GCC 13 64 ASAN",
|
||||
"cppalliance/droneubuntu2304:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '64' } + asan,
|
||||
"g++-13-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 23.04 GCC 13 32 UBSAN",
|
||||
"cppalliance/droneubuntu2304:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' } + ubsan,
|
||||
"g++-13-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 23.04 GCC 13 64 UBSAN",
|
||||
"cppalliance/droneubuntu2304:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '64' } + ubsan,
|
||||
"g++-13-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 GCC 14 32",
|
||||
"Linux 24.04 GCC 13 32/64",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' },
|
||||
{ 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",
|
||||
"Linux 24.04 GCC 14 64 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b', ADDRMD: '64' },
|
||||
{ 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",
|
||||
),
|
||||
|
||||
@ -263,7 +258,7 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
linux_pipeline(
|
||||
"Linux 18.04 Clang 5.0",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-5.0', CXXSTD: '11,14,1z' },
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-5.0', CXXSTD: '11,14' },
|
||||
"clang-5.0",
|
||||
),
|
||||
|
||||
@ -338,22 +333,22 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 23.04 Clang 16",
|
||||
"cppalliance/droneubuntu2304:1",
|
||||
"Linux 24.04 Clang 16",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-16', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-16",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 23.10 Clang 17 UBSAN",
|
||||
"cppalliance/droneubuntu2310:1",
|
||||
"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 23.10 Clang 17 ASAN",
|
||||
"cppalliance/droneubuntu2310:1",
|
||||
"Linux 24.04 Clang 17 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
"clang-17",
|
||||
),
|
||||
@ -372,6 +367,13 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
"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,
|
||||
|
56
.github/workflows/ci.yml
vendored
56
.github/workflows/ci.yml
vendored
@ -62,7 +62,7 @@ jobs:
|
||||
install: g++-12
|
||||
- toolset: gcc-13
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
container: ubuntu:23.04
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: g++-13
|
||||
- toolset: gcc-14
|
||||
@ -84,7 +84,7 @@ jobs:
|
||||
install: clang-4.0
|
||||
- toolset: clang
|
||||
compiler: clang++-5.0
|
||||
cxxstd: "11,14,1z"
|
||||
cxxstd: "11,14"
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: clang-5.0
|
||||
@ -144,13 +144,13 @@ jobs:
|
||||
- toolset: clang
|
||||
compiler: clang++-16
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
container: ubuntu:23.04
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-16
|
||||
- toolset: clang
|
||||
compiler: clang++-17
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
container: ubuntu:23.10
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-17
|
||||
- toolset: clang
|
||||
@ -160,33 +160,48 @@ jobs:
|
||||
os: ubuntu-latest
|
||||
install: clang-18
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: macos-11
|
||||
- toolset: clang
|
||||
compiler: clang++-19
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: macos-12
|
||||
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: ${{matrix.container}}
|
||||
|
||||
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@v3
|
||||
|
||||
- name: Setup container environment
|
||||
if: matrix.container
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get -y install sudo python3 git g++
|
||||
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
|
||||
@ -283,7 +298,7 @@ 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 embed-manifest-via=linker
|
||||
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:
|
||||
@ -292,9 +307,10 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: ubuntu-24.04
|
||||
- os: macos-13
|
||||
- os: macos-14
|
||||
- os: macos-15
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@ -340,9 +356,10 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: ubuntu-24.04
|
||||
- os: macos-13
|
||||
- os: macos-14
|
||||
- os: macos-15
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@ -398,9 +415,10 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: ubuntu-24.04
|
||||
- os: macos-13
|
||||
- os: macos-14
|
||||
- os: macos-15
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
|
@ -59,7 +59,7 @@ test_script:
|
||||
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
|
||||
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
|
||||
- if not "%CXXFLAGS%" == "" set CXXFLAGS=cxxflags=%CXXFLAGS%
|
||||
- if "%CMAKE%%CMAKE_SUBDIR%%CMAKE_INSTALL%" == "" b2 -j3 libs/variant2/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% %CXXFLAGS% variant=debug,release embed-manifest-via=linker
|
||||
- if "%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 ..
|
||||
|
22
build.jam
Normal file
22
build.jam
Normal 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
|
||||
;
|
@ -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,10 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
# 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()`.
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <iosfwd>
|
||||
#include <cstdint>
|
||||
#include <cerrno>
|
||||
#include <limits>
|
||||
|
||||
//
|
||||
|
||||
@ -83,7 +84,7 @@ struct monostate
|
||||
{
|
||||
};
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1940)
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1950)
|
||||
|
||||
constexpr bool operator<(monostate, monostate) noexcept { return false; }
|
||||
constexpr bool operator>(monostate, monostate) noexcept { return false; }
|
||||
@ -845,6 +846,26 @@ template<class U, class... T> using resolve_overload_type = typename decltype( o
|
||||
|
||||
template<class U, class... T> using resolve_overload_index = mp11::mp_find<mp11::mp_list<T...>, resolve_overload_type<U, T...>>;
|
||||
|
||||
// index_type
|
||||
|
||||
template<std::size_t N> using get_smallest_unsigned_type = mp11::mp_cond<
|
||||
|
||||
mp11::mp_bool< N <= (std::numeric_limits<unsigned char>::max)() >, unsigned char,
|
||||
mp11::mp_bool< N <= (std::numeric_limits<unsigned short>::max)() >, unsigned short,
|
||||
mp11::mp_true, unsigned
|
||||
|
||||
>;
|
||||
|
||||
#if BOOST_WORKAROUND( BOOST_CLANG_VERSION, < 30800 )
|
||||
|
||||
template<bool Double, class... T> using get_index_type = unsigned short;
|
||||
|
||||
#else
|
||||
|
||||
template<bool Double, class... T> using get_index_type = get_smallest_unsigned_type< (Double + 1) * sizeof...(T) >;
|
||||
|
||||
#endif
|
||||
|
||||
// variant_base
|
||||
|
||||
template<bool is_trivially_destructible, bool is_single_buffered, class... T> struct variant_base_impl;
|
||||
@ -855,8 +876,10 @@ struct none {};
|
||||
// trivially destructible, single buffered
|
||||
template<class... T> struct variant_base_impl<true, true, T...>
|
||||
{
|
||||
using index_type = get_index_type<false, T...>;
|
||||
|
||||
variant_storage<none, T...> st_;
|
||||
unsigned ix_;
|
||||
index_type ix_;
|
||||
|
||||
constexpr variant_base_impl(): st_( mp11::mp_size_t<0>() ), ix_( 0 )
|
||||
{
|
||||
@ -870,6 +893,8 @@ template<class... T> struct variant_base_impl<true, true, T...>
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &st_ ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
|
||||
static_assert( I::value + 1 <= (std::numeric_limits<index_type>::max)(), "" );
|
||||
ix_ = I::value + 1;
|
||||
}
|
||||
|
||||
@ -880,7 +905,7 @@ template<class... T> struct variant_base_impl<true, true, T...>
|
||||
|
||||
template<std::size_t I> BOOST_CXX14_CONSTEXPR mp11::mp_at_c<variant<T...>, I>& _get_impl( mp11::mp_size_t<I> ) noexcept
|
||||
{
|
||||
size_t const J = I+1;
|
||||
std::size_t const J = I+1;
|
||||
|
||||
BOOST_ASSERT( ix_ == J );
|
||||
|
||||
@ -889,7 +914,7 @@ template<class... T> struct variant_base_impl<true, true, T...>
|
||||
|
||||
template<std::size_t I> constexpr mp11::mp_at_c<variant<T...>, I> const& _get_impl( mp11::mp_size_t<I> ) const noexcept
|
||||
{
|
||||
// size_t const J = I+1;
|
||||
// std::size_t const J = I+1;
|
||||
|
||||
BOOST_VARIANT2_CX14_ASSERT( ix_ == I+1 )
|
||||
|
||||
@ -901,6 +926,8 @@ template<class... T> struct variant_base_impl<true, true, T...>
|
||||
static_assert( std::is_nothrow_constructible<U, A&&...>::value, "Logic error: U must be nothrow constructible from A&&..." );
|
||||
|
||||
st_.emplace( mp11::mp_size_t<J>(), std::forward<A>(a)... );
|
||||
|
||||
static_assert( J <= (std::numeric_limits<index_type>::max)(), "" );
|
||||
ix_ = J;
|
||||
}
|
||||
|
||||
@ -911,6 +938,8 @@ template<class... T> struct variant_base_impl<true, true, T...>
|
||||
U tmp( std::forward<A>(a)... );
|
||||
|
||||
st_.emplace( mp11::mp_size_t<J>(), std::move(tmp) );
|
||||
|
||||
static_assert( J <= (std::numeric_limits<index_type>::max)(), "" );
|
||||
ix_ = J;
|
||||
}
|
||||
|
||||
@ -931,8 +960,10 @@ template<class... T> struct variant_base_impl<true, true, T...>
|
||||
// trivially destructible, double buffered
|
||||
template<class... T> struct variant_base_impl<true, false, T...>
|
||||
{
|
||||
using index_type = get_index_type<true, T...>;
|
||||
|
||||
variant_storage<none, T...> st_[ 2 ];
|
||||
unsigned ix_;
|
||||
index_type ix_;
|
||||
|
||||
constexpr variant_base_impl(): st_{ { mp11::mp_size_t<0>() }, { mp11::mp_size_t<0>() } }, ix_( 0 )
|
||||
{
|
||||
@ -946,6 +977,8 @@ template<class... T> struct variant_base_impl<true, false, T...>
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &st_[ 0 ] ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
|
||||
static_assert( ( I::value + 1 ) * 2 <= (std::numeric_limits<index_type>::max)(), "" );
|
||||
ix_ = ( I::value + 1 ) * 2;
|
||||
}
|
||||
|
||||
@ -958,7 +991,7 @@ template<class... T> struct variant_base_impl<true, false, T...>
|
||||
{
|
||||
BOOST_ASSERT( index() == I );
|
||||
|
||||
size_t const J = I+1;
|
||||
std::size_t const J = I+1;
|
||||
|
||||
constexpr mp11::mp_size_t<J> j{};
|
||||
return st_[ ix_ & 1 ].get( j );
|
||||
@ -968,7 +1001,7 @@ template<class... T> struct variant_base_impl<true, false, T...>
|
||||
{
|
||||
BOOST_VARIANT2_CX14_ASSERT( index() == I )
|
||||
|
||||
// size_t const J = I+1;
|
||||
// std::size_t const J = I+1;
|
||||
// constexpr mp_size_t<J> j{};
|
||||
|
||||
return st_[ ix_ & 1 ].get( mp11::mp_size_t<I+1>() );
|
||||
@ -976,13 +1009,14 @@ template<class... T> struct variant_base_impl<true, false, T...>
|
||||
|
||||
template<std::size_t I, class... A> BOOST_CXX14_CONSTEXPR void emplace( A&&... a )
|
||||
{
|
||||
size_t const J = I+1;
|
||||
std::size_t const J = I+1;
|
||||
|
||||
unsigned i2 = 1 - ( ix_ & 1 );
|
||||
|
||||
st_[ i2 ].emplace( mp11::mp_size_t<J>(), std::forward<A>(a)... );
|
||||
|
||||
ix_ = J * 2 + i2;
|
||||
static_assert( J * 2 + 1 <= (std::numeric_limits<index_type>::max)(), "" );
|
||||
ix_ = static_cast<index_type>( J * 2 + i2 );
|
||||
}
|
||||
|
||||
static constexpr bool uses_double_storage() noexcept
|
||||
@ -994,8 +1028,10 @@ template<class... T> struct variant_base_impl<true, false, T...>
|
||||
// not trivially destructible, single buffered
|
||||
template<class... T> struct variant_base_impl<false, true, T...>
|
||||
{
|
||||
using index_type = get_index_type<false, T...>;
|
||||
|
||||
variant_storage<none, T...> st_;
|
||||
unsigned ix_;
|
||||
index_type ix_;
|
||||
|
||||
constexpr variant_base_impl(): st_( mp11::mp_size_t<0>() ), ix_( 0 )
|
||||
{
|
||||
@ -1009,6 +1045,8 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &st_ ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
|
||||
static_assert( I::value + 1 <= (std::numeric_limits<index_type>::max)(), "" );
|
||||
ix_ = I::value + 1;
|
||||
}
|
||||
|
||||
@ -1048,7 +1086,7 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
|
||||
template<std::size_t I> BOOST_CXX14_CONSTEXPR mp11::mp_at_c<variant<T...>, I>& _get_impl( mp11::mp_size_t<I> ) noexcept
|
||||
{
|
||||
size_t const J = I+1;
|
||||
std::size_t const J = I+1;
|
||||
|
||||
BOOST_ASSERT( ix_ == J );
|
||||
|
||||
@ -1057,7 +1095,7 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
|
||||
template<std::size_t I> constexpr mp11::mp_at_c<variant<T...>, I> const& _get_impl( mp11::mp_size_t<I> ) const noexcept
|
||||
{
|
||||
// size_t const J = I+1;
|
||||
// std::size_t const J = I+1;
|
||||
|
||||
BOOST_VARIANT2_CX14_ASSERT( ix_ == I+1 )
|
||||
|
||||
@ -1066,7 +1104,7 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
|
||||
template<std::size_t I, class... A> void emplace( A&&... a )
|
||||
{
|
||||
size_t const J = I+1;
|
||||
std::size_t const J = I+1;
|
||||
|
||||
using U = mp11::mp_at_c<variant<T...>, I>;
|
||||
|
||||
@ -1077,6 +1115,8 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
_destroy();
|
||||
|
||||
st_.emplace( mp11::mp_size_t<J>(), std::move(tmp) );
|
||||
|
||||
static_assert( J <= (std::numeric_limits<index_type>::max)(), "" );
|
||||
ix_ = J;
|
||||
}
|
||||
|
||||
@ -1089,12 +1129,14 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
// not trivially destructible, double buffered
|
||||
template<class... T> struct variant_base_impl<false, false, T...>
|
||||
{
|
||||
using index_type = get_index_type<true, T...>;
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ < 11 && !defined(__clang__) && !defined(__INTEL_COMPILER)
|
||||
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63707 :-(
|
||||
|
||||
variant_storage<none, T...> st1_, st2_;
|
||||
unsigned ix_;
|
||||
index_type ix_;
|
||||
|
||||
constexpr variant_base_impl(): st1_( mp11::mp_size_t<0>() ), st2_( mp11::mp_size_t<0>() ), ix_( 0 )
|
||||
{
|
||||
@ -1117,7 +1159,7 @@ template<class... T> struct variant_base_impl<false, false, T...>
|
||||
#else
|
||||
|
||||
variant_storage<none, T...> st_[ 2 ];
|
||||
unsigned ix_;
|
||||
index_type ix_;
|
||||
|
||||
constexpr variant_base_impl(): st_{ { mp11::mp_size_t<0>() }, { mp11::mp_size_t<0>() } }, ix_( 0 )
|
||||
{
|
||||
@ -1143,6 +1185,8 @@ template<class... T> struct variant_base_impl<false, false, T...>
|
||||
template<class I, class... A> void _replace( I, A&&... a )
|
||||
{
|
||||
::new( &storage( 0 ) ) variant_storage<none, T...>( mp11::mp_size_t<I::value + 1>(), std::forward<A>(a)... );
|
||||
|
||||
static_assert( ( I::value + 1 ) * 2 <= (std::numeric_limits<index_type>::max)(), "" );
|
||||
ix_ = ( I::value + 1 ) * 2;
|
||||
}
|
||||
|
||||
@ -1165,7 +1209,7 @@ template<class... T> struct variant_base_impl<false, false, T...>
|
||||
|
||||
void _destroy() noexcept
|
||||
{
|
||||
mp11::mp_with_index<1 + sizeof...(T)>( ix_ / 2, _destroy_L1{ this, ix_ & 1 } );
|
||||
mp11::mp_with_index<1 + sizeof...(T)>( ix_ / 2, _destroy_L1{ this, static_cast<unsigned>( ix_ & 1 ) } );
|
||||
}
|
||||
|
||||
~variant_base_impl() noexcept
|
||||
@ -1182,7 +1226,7 @@ template<class... T> struct variant_base_impl<false, false, T...>
|
||||
{
|
||||
BOOST_ASSERT( index() == I );
|
||||
|
||||
size_t const J = I+1;
|
||||
std::size_t const J = I+1;
|
||||
|
||||
constexpr mp11::mp_size_t<J> j{};
|
||||
return storage( ix_ & 1 ).get( j );
|
||||
@ -1192,7 +1236,7 @@ template<class... T> struct variant_base_impl<false, false, T...>
|
||||
{
|
||||
BOOST_VARIANT2_CX14_ASSERT( index() == I )
|
||||
|
||||
// size_t const J = I+1;
|
||||
// std::size_t const J = I+1;
|
||||
// constexpr mp_size_t<J> j{};
|
||||
|
||||
return storage( ix_ & 1 ).get( mp11::mp_size_t<I+1>() );
|
||||
@ -1200,14 +1244,15 @@ template<class... T> struct variant_base_impl<false, false, T...>
|
||||
|
||||
template<std::size_t I, class... A> void emplace( A&&... a )
|
||||
{
|
||||
size_t const J = I+1;
|
||||
std::size_t const J = I+1;
|
||||
|
||||
unsigned i2 = 1 - ( ix_ & 1 );
|
||||
|
||||
storage( i2 ).emplace( mp11::mp_size_t<J>(), std::forward<A>(a)... );
|
||||
_destroy();
|
||||
|
||||
ix_ = J * 2 + i2;
|
||||
static_assert( J * 2 + 1 <= (std::numeric_limits<index_type>::max)(), "" );
|
||||
ix_ = static_cast<index_type>( J * 2 + i2 );
|
||||
}
|
||||
|
||||
static constexpr bool uses_double_storage() noexcept
|
||||
@ -2125,7 +2170,7 @@ template<class R, class F, class V1> struct visit_L1
|
||||
F&& f;
|
||||
V1&& v1;
|
||||
|
||||
template<class I> auto operator()( I ) const -> Vret<R, F, V1>
|
||||
template<class I> constexpr auto operator()( I ) const -> Vret<R, F, V1>
|
||||
{
|
||||
return std::forward<F>(f)( unsafe_get<I::value>( std::forward<V1>(v1) ) );
|
||||
}
|
||||
|
32
test/Jamfile
32
test/Jamfile
@ -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,9 +17,14 @@ project
|
||||
|
||||
: requirements
|
||||
|
||||
<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 ;
|
||||
@ -54,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 ] ;
|
||||
@ -125,7 +131,7 @@ run variant_visit_by_index.cpp ;
|
||||
run variant_ostream_insert.cpp ;
|
||||
run is_output_streamable.cpp ;
|
||||
|
||||
local JSON = <library>/boost//json/<warnings>off "<toolset>msvc-14.0:<build>no" "<toolset>msvc-14.2:<cxxflags>-wd5104" "<undefined-sanitizer>norecover:<link>static" ;
|
||||
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) ;
|
||||
@ -133,3 +139,21 @@ 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) ;
|
||||
}
|
||||
|
@ -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>)
|
||||
|
@ -18,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>)
|
||||
|
86
test/variant_index_type.cpp
Normal file
86
test/variant_index_type.cpp
Normal 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();
|
||||
}
|
@ -2,6 +2,12 @@
|
||||
// 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>
|
||||
|
@ -2,6 +2,12 @@
|
||||
// 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>
|
||||
|
51
test/variant_visit_cx.cpp
Normal file
51
test/variant_visit_cx.cpp
Normal 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
|
53
test/variant_visit_cx_2.cpp
Normal file
53
test/variant_visit_cx_2.cpp
Normal 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
|
52
test/variant_visit_r_cx.cpp
Normal file
52
test/variant_visit_r_cx.cpp
Normal 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
|
Reference in New Issue
Block a user