mirror of
https://github.com/boostorg/variant2.git
synced 2026-04-13 13:16:01 +02:00
Compare commits
17 Commits
boost-1.90
...
feature/is
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b137164c0d | ||
|
|
6e8f4e955d | ||
|
|
3b731db14d | ||
|
|
25a8596890 | ||
|
|
8237d94f93 | ||
|
|
155ed414ab | ||
|
|
e6b336ec68 | ||
|
|
799a69eccc | ||
|
|
74f6f0cd96 | ||
|
|
fc786d39b3 | ||
|
|
382cf33824 | ||
|
|
4632862a4b | ||
|
|
48ed0a243f | ||
|
|
936a1a95b5 | ||
|
|
fcdaadb0f5 | ||
|
|
540354878c | ||
|
|
2a5aa1c7ad |
@@ -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-' },
|
||||
),
|
||||
]
|
||||
|
||||
20
.github/workflows/ci.yml
vendored
20
.github/workflows/ci.yml
vendored
@@ -185,18 +185,24 @@ jobs:
|
||||
- toolset: clang
|
||||
compiler: clang++-20
|
||||
cxxstd: "11,14,17,20,23,2c"
|
||||
container: ubuntu:25.04
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-20
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: macos-13
|
||||
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}}
|
||||
|
||||
@@ -322,9 +328,9 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-22.04
|
||||
- os: ubuntu-24.04
|
||||
- os: macos-13
|
||||
- os: macos-14
|
||||
- os: macos-15
|
||||
- os: macos-26
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -370,9 +376,9 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-22.04
|
||||
- os: ubuntu-24.04
|
||||
- os: macos-13
|
||||
- os: macos-14
|
||||
- os: macos-15
|
||||
- os: macos-26
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -428,9 +434,9 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-22.04
|
||||
- os: ubuntu-24.04
|
||||
- os: macos-13
|
||||
- os: macos-14
|
||||
- os: macos-15
|
||||
- os: macos-26
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
# Revision History
|
||||
:idprefix: changelog_
|
||||
|
||||
## Changes in 1.91.0
|
||||
|
||||
* `holds_alternative<T>` and `get<T>` have been relaxed to no longer require `T` to occur exactly once in the list of alternatives. It now must occur at least once.
|
||||
|
||||
## Changes in 1.90.0
|
||||
|
||||
* More functions have been marked as `constexpr`, including `~variant`.
|
||||
|
||||
@@ -719,10 +719,8 @@ template<class U, class... T>
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Requires: :: The type `U` occurs exactly once in `T...`. Otherwise, the
|
||||
program is ill-formed.
|
||||
Returns: :: `true` if `index()` is equal to the zero-based index of `U`
|
||||
in `T...`.
|
||||
Requires: :: The type `U` must be present in `T...`. Otherwise, the program is ill-formed.
|
||||
Returns: :: `true` if `v` holds a value of type `U`, otherwise `false`.
|
||||
|
||||
### get
|
||||
|
||||
@@ -773,10 +771,8 @@ template<class U, class... T>
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Requires: :: The type `U` occurs exactly once in `T...`. Otherwise, the
|
||||
program is ill-formed.
|
||||
Effects: :: If `v` holds a value of type `U`, returns a reference to that value.
|
||||
Otherwise, throws `bad_variant_access`.
|
||||
Requires: :: The type `U` must be present in `T...`. Otherwise, the program is ill-formed.
|
||||
Effects: :: If `v` holds a value of type `U`, returns a reference to that value. Otherwise, throws `bad_variant_access`.
|
||||
|
||||
### get_if
|
||||
|
||||
@@ -793,10 +789,8 @@ template<size_t I, class... T>
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects: :: A pointer to the value stored in the variant, if
|
||||
`v != nullptr && v\->index() == I`. Otherwise, `nullptr`.
|
||||
Remarks: :: These functions do not participate in overload resolution
|
||||
unless `I` < `sizeof...(T)`.
|
||||
Returns: :: A pointer to the value stored in `*v`, if `v != nullptr && v\->index() == I`. Otherwise, `nullptr`.
|
||||
Remarks: :: These functions do not participate in overload resolution unless `I` < `sizeof...(T)`.
|
||||
|
||||
```
|
||||
template<class U, class... T>
|
||||
@@ -811,10 +805,8 @@ template<class U, class... T>
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Requires: :: The type `U` occurs exactly once in `T...`. Otherwise, the
|
||||
program is ill-formed.
|
||||
Effects: :: Equivalent to: `return get_if<I>(v);` with `I` being
|
||||
the zero-based index of `U` in `T...`.
|
||||
Requires: :: The type `U` must be present in `T...`. Otherwise, the program is ill-formed.
|
||||
Returns: :: If `v != nullptr` and `*v` holds a value of type `U`, a pointer to that value. Otherwise, `nullptr`.
|
||||
|
||||
### unsafe_get (extension)
|
||||
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
#ifndef BOOST_VARIANT2_VARIANT_HPP_INCLUDED
|
||||
#define BOOST_VARIANT2_VARIANT_HPP_INCLUDED
|
||||
|
||||
// Copyright 2017-2019 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017-2026 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
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910
|
||||
# pragma warning( push )
|
||||
@@ -93,7 +90,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; }
|
||||
@@ -324,12 +321,41 @@ constexpr std::size_t variant_npos = ~static_cast<std::size_t>( 0 );
|
||||
|
||||
// holds_alternative
|
||||
|
||||
#if !defined(BOOST_MP11_HAS_CXX14_CONSTEXPR)
|
||||
|
||||
template<class U, class... T> constexpr bool holds_alternative( variant<T...> const& v ) noexcept
|
||||
{
|
||||
static_assert( mp11::mp_count<variant<T...>, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" );
|
||||
return v.index() == mp11::mp_find<variant<T...>, U>::value;
|
||||
static_assert( mp11::mp_contains<variant<T...>, U>::value, "The type must be present in the list of variant alternatives" );
|
||||
|
||||
using A = bool[];
|
||||
return A{ std::is_same<U, T>::value... }[ v.index() ];
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class U, class V> struct holds_alternative_L
|
||||
{
|
||||
template<class I> constexpr bool operator()( I ) const noexcept
|
||||
{
|
||||
return std::is_same< U, mp11::mp_at<V, I> >::value;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class U, class... T> constexpr bool holds_alternative( variant<T...> const& v ) noexcept
|
||||
{
|
||||
using V = variant<T...>;
|
||||
static_assert( mp11::mp_contains<V, U>::value, "The type must be present in the list of variant alternatives" );
|
||||
|
||||
return mp11::mp_with_index<sizeof...(T)>( v.index(), detail::holds_alternative_L<U, V>() );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// get (index)
|
||||
|
||||
template<std::size_t I, class... T> constexpr variant_alternative_t<I, variant<T...>>& get(variant<T...>& v)
|
||||
@@ -422,61 +448,106 @@ template<std::size_t I, class... T> constexpr variant_alternative_t<I, variant<T
|
||||
|
||||
// get (type)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class U, class V> struct get_if_impl_L1
|
||||
{
|
||||
V& v_;
|
||||
|
||||
template<class I> constexpr U* fn( I, mp11::mp_true ) const noexcept
|
||||
{
|
||||
return &v_._get_impl( I() );
|
||||
}
|
||||
|
||||
template<class I> constexpr U* fn( I, mp11::mp_false ) const noexcept
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<class I> constexpr U* operator()( I ) const noexcept
|
||||
{
|
||||
return this->fn( I(), std::is_same<U, mp11::mp_at<V, I>>() );
|
||||
}
|
||||
};
|
||||
|
||||
template<class U, class... T> constexpr U* get_if_impl( variant<T...>& v ) noexcept
|
||||
{
|
||||
return mp11::mp_with_index<sizeof...(T)>( v.index(), get_if_impl_L1< U, variant<T...> >{ v } );
|
||||
}
|
||||
|
||||
template<class U, class V> struct get_if_impl_L2
|
||||
{
|
||||
V const& v_;
|
||||
|
||||
template<class I> constexpr U const* fn( I, mp11::mp_true ) const noexcept
|
||||
{
|
||||
return &v_._get_impl( I() );
|
||||
}
|
||||
|
||||
template<class I> constexpr U const* fn( I, mp11::mp_false ) const noexcept
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<class I> constexpr U const* operator()( I ) const noexcept
|
||||
{
|
||||
return this->fn( I(), std::is_same<U, mp11::mp_at<V, I>>() );
|
||||
}
|
||||
};
|
||||
|
||||
template<class U, class... T> constexpr U const* get_if_impl( variant<T...> const& v ) noexcept
|
||||
{
|
||||
return mp11::mp_with_index<sizeof...(T)>( v.index(), get_if_impl_L2< U, variant<T...> >{ v } );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class U, class... T> constexpr U& get(variant<T...>& v)
|
||||
{
|
||||
static_assert( mp11::mp_count<variant<T...>, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" );
|
||||
|
||||
using I = mp11::mp_find<variant<T...>, U>;
|
||||
|
||||
return ( v.index() != I::value? detail::throw_bad_variant_access(): (void)0 ), v._get_impl( I() );
|
||||
static_assert( mp11::mp_contains<variant<T...>, U>::value, "The type must be present in the list of variant alternatives" );
|
||||
return ( !holds_alternative<U>( v )? detail::throw_bad_variant_access(): (void)0 ), *detail::get_if_impl<U>( v );
|
||||
}
|
||||
|
||||
template<class U, class... T> constexpr U&& get(variant<T...>&& v)
|
||||
{
|
||||
static_assert( mp11::mp_count<variant<T...>, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" );
|
||||
|
||||
using I = mp11::mp_find<variant<T...>, U>;
|
||||
static_assert( mp11::mp_contains<variant<T...>, U>::value, "The type must be present in the list of variant alternatives" );
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1930)
|
||||
|
||||
return ( v.index() != I::value? detail::throw_bad_variant_access(): (void)0 ), std::move( v._get_impl( I() ) );
|
||||
return ( !holds_alternative<U>( v )? detail::throw_bad_variant_access(): (void)0 ), std::move( *detail::get_if_impl<U>( v ) );
|
||||
|
||||
#else
|
||||
|
||||
if( v.index() != I::value ) detail::throw_bad_variant_access();
|
||||
return std::move( v._get_impl( I() ) );
|
||||
if( !holds_alternative<U>( v ) ) detail::throw_bad_variant_access();
|
||||
return std::move( *detail::get_if_impl<U>( v ) );
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class U, class... T> constexpr U const& get(variant<T...> const& v)
|
||||
{
|
||||
static_assert( mp11::mp_count<variant<T...>, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" );
|
||||
|
||||
using I = mp11::mp_find<variant<T...>, U>;
|
||||
|
||||
return ( v.index() != I::value? detail::throw_bad_variant_access(): (void)0 ), v._get_impl( I() );
|
||||
static_assert( mp11::mp_contains<variant<T...>, U>::value, "The type must be present in the list of variant alternatives" );
|
||||
return ( !holds_alternative<U>( v )? detail::throw_bad_variant_access(): (void)0 ), *detail::get_if_impl<U>( v );
|
||||
}
|
||||
|
||||
template<class U, class... T> constexpr U const&& get(variant<T...> const&& v)
|
||||
{
|
||||
static_assert( mp11::mp_count<variant<T...>, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" );
|
||||
|
||||
using I = mp11::mp_find<variant<T...>, U>;
|
||||
static_assert( mp11::mp_contains<variant<T...>, U>::value, "The type must be present in the list of variant alternatives" );
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1930)
|
||||
|
||||
return ( v.index() != I::value? detail::throw_bad_variant_access(): (void)0 ), std::move( v._get_impl( I() ) );
|
||||
return ( !holds_alternative<U>( v )? detail::throw_bad_variant_access(): (void)0 ), std::move( *detail::get_if_impl<U>( v ) );
|
||||
|
||||
#else
|
||||
|
||||
if( v.index() != I::value ) detail::throw_bad_variant_access();
|
||||
return std::move( v._get_impl( I() ) );
|
||||
if( !holds_alternative<U>( v ) ) detail::throw_bad_variant_access();
|
||||
return std::move( *detail::get_if_impl<U>( v ) );
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
// get_if
|
||||
// get_if (index)
|
||||
|
||||
template<std::size_t I, class... T> constexpr typename std::add_pointer<variant_alternative_t<I, variant<T...>>>::type get_if(variant<T...>* v) noexcept
|
||||
{
|
||||
@@ -490,22 +561,18 @@ template<std::size_t I, class... T> constexpr typename std::add_pointer<const va
|
||||
return v && v->index() == I? &v->_get_impl( mp11::mp_size_t<I>() ): 0;
|
||||
}
|
||||
|
||||
// get_if (type)
|
||||
|
||||
template<class U, class... T> constexpr typename std::add_pointer<U>::type get_if(variant<T...>* v) noexcept
|
||||
{
|
||||
static_assert( mp11::mp_count<variant<T...>, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" );
|
||||
|
||||
using I = mp11::mp_find<variant<T...>, U>;
|
||||
|
||||
return v && v->index() == I::value? &v->_get_impl( I() ): 0;
|
||||
static_assert( mp11::mp_contains<variant<T...>, U>::value, "The type must be present in the list of variant alternatives" );
|
||||
return v && holds_alternative<U>( *v )? detail::get_if_impl<U>( *v ): 0;
|
||||
}
|
||||
|
||||
template<class U, class... T> constexpr typename std::add_pointer<U const>::type get_if(variant<T...> const * v) noexcept
|
||||
template<class U, class... T> constexpr typename std::add_pointer<U const>::type get_if(variant<T...> const* v) noexcept
|
||||
{
|
||||
static_assert( mp11::mp_count<variant<T...>, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" );
|
||||
|
||||
using I = mp11::mp_find<variant<T...>, U>;
|
||||
|
||||
return v && v->index() == I::value? &v->_get_impl( I() ): 0;
|
||||
static_assert( mp11::mp_contains<variant<T...>, U>::value, "The type must be present in the list of variant alternatives" );
|
||||
return v && holds_alternative<U>( *v )? detail::get_if_impl<U>( *v ): 0;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -558,10 +625,20 @@ 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)... )
|
||||
{
|
||||
}
|
||||
@@ -704,6 +781,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)
|
||||
@@ -1071,7 +1149,18 @@ template<class... T> struct variant_base_impl<false, true, T...>
|
||||
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
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1119,8 +1208,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) );
|
||||
@@ -1689,7 +1788,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 >,
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
76
test/Jamfile
76
test/Jamfile
@@ -1,14 +1,8 @@
|
||||
# Boost.Variant2 Library Test Jamfile
|
||||
#
|
||||
# Copyright 2015-2019 Peter Dimov
|
||||
#
|
||||
# Copyright 2015-2026 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
|
||||
|
||||
import testing ;
|
||||
import-search /boost/config/checks ;
|
||||
import config : requires ;
|
||||
|
||||
project
|
||||
: default-build
|
||||
@@ -33,54 +27,54 @@ run variant_size.cpp ;
|
||||
run variant_alternative.cpp ;
|
||||
|
||||
run variant_holds_alternative.cpp ;
|
||||
compile variant_holds_alternative_cx.cpp : <toolset>msvc-14.0:<build>no ;
|
||||
compile variant_holds_alternative_cx.cpp ;
|
||||
|
||||
run variant_get_by_index.cpp ;
|
||||
compile variant_get_by_index_cx.cpp : <toolset>msvc-14.0:<build>no ;
|
||||
compile variant_get_by_index_cx.cpp ;
|
||||
|
||||
run variant_get_by_type.cpp ;
|
||||
compile variant_get_by_type_cx.cpp : <toolset>msvc-14.0:<build>no ;
|
||||
compile variant_get_by_type_cx.cpp ;
|
||||
|
||||
run variant_default_construct.cpp ;
|
||||
compile variant_default_construct_cx.cpp : <toolset>msvc-14.0:<build>no ;
|
||||
compile variant_default_construct_cx.cpp ;
|
||||
|
||||
run variant_copy_construct.cpp ;
|
||||
compile variant_copy_construct_cx.cpp : <toolset>msvc-14.0:<build>no ;
|
||||
compile variant_copy_construct_cx.cpp ;
|
||||
|
||||
run variant_move_construct.cpp ;
|
||||
compile variant_move_construct_cx.cpp : [ requires cxx14_constexpr ] ;
|
||||
compile variant_move_construct_cx.cpp ;
|
||||
|
||||
run variant_value_construct.cpp ;
|
||||
compile variant_value_construct_cx.cpp : <toolset>msvc-14.0:<build>no ;
|
||||
compile variant_value_construct_cx.cpp ;
|
||||
|
||||
run variant_in_place_index_construct.cpp ;
|
||||
compile variant_in_place_index_construct_cx.cpp : <toolset>msvc-14.0:<build>no ;
|
||||
compile variant_in_place_index_construct_cx.cpp ;
|
||||
|
||||
run variant_in_place_type_construct.cpp ;
|
||||
compile variant_in_place_type_construct_cx.cpp : <toolset>msvc-14.0:<build>no ;
|
||||
compile variant_in_place_type_construct_cx.cpp ;
|
||||
|
||||
run variant_copy_assign.cpp ;
|
||||
compile variant_copy_assign_cx.cpp : [ requires cxx14_constexpr ] <toolset>gcc-5:<build>no <toolset>gcc-6:<build>no ;
|
||||
compile variant_copy_assign_cx.cpp ;
|
||||
|
||||
run variant_move_assign.cpp ;
|
||||
compile variant_move_assign_cx.cpp : [ requires cxx14_constexpr ] <toolset>gcc-5:<build>no <toolset>gcc-6:<build>no ;
|
||||
compile variant_move_assign_cx.cpp ;
|
||||
|
||||
run variant_value_assign.cpp ;
|
||||
compile variant_value_assign_cx.cpp : [ requires cxx14_constexpr ] ;
|
||||
compile variant_value_assign_cx.cpp ;
|
||||
|
||||
run variant_emplace_index.cpp ;
|
||||
compile variant_emplace_index_cx.cpp : [ requires cxx14_constexpr ] ;
|
||||
compile variant_emplace_index_cx.cpp ;
|
||||
|
||||
run variant_emplace_type.cpp ;
|
||||
compile variant_emplace_type_cx.cpp : [ requires cxx14_constexpr ] ;
|
||||
compile variant_emplace_type_cx.cpp ;
|
||||
|
||||
run variant_swap.cpp ;
|
||||
|
||||
run variant_eq_ne.cpp ;
|
||||
compile variant_eq_ne_cx.cpp : [ requires cxx14_constexpr ] ;
|
||||
compile variant_eq_ne_cx.cpp ;
|
||||
|
||||
run variant_lt_gt.cpp ;
|
||||
compile variant_lt_gt_cx.cpp : [ requires cxx14_constexpr ] ;
|
||||
compile variant_lt_gt_cx.cpp ;
|
||||
|
||||
run variant_destroy.cpp ;
|
||||
run variant_visit.cpp ;
|
||||
@@ -103,10 +97,10 @@ local NX =
|
||||
;
|
||||
|
||||
run variant_get_by_index.cpp throw_exception.cpp : : : $(NX) : variant_get_by_index_nx ;
|
||||
compile variant_get_by_index_cx.cpp : $(NX) <toolset>msvc-14.0:<build>no : variant_get_by_index_cx_nx ;
|
||||
compile variant_get_by_index_cx.cpp : $(NX) : variant_get_by_index_cx_nx ;
|
||||
|
||||
run variant_get_by_type.cpp throw_exception.cpp : : : $(NX) : variant_get_by_type_nx ;
|
||||
compile variant_get_by_type_cx.cpp : $(NX) <toolset>msvc-14.0:<build>no : variant_get_by_type_cx_nx ;
|
||||
compile variant_get_by_type_cx.cpp : $(NX) : variant_get_by_type_cx_nx ;
|
||||
|
||||
run variant_subset.cpp throw_exception.cpp : : : $(NX) : variant_subset_nx ;
|
||||
|
||||
@@ -117,7 +111,12 @@ run variant_special.cpp ;
|
||||
|
||||
run variant_visit_derived.cpp ;
|
||||
|
||||
run variant_many_types.cpp ;
|
||||
# These two tests require /bigobj under GCC/Windows and CMake/VS2022 (for some reason)
|
||||
|
||||
run variant_many_types.cpp : : :
|
||||
<toolset>gcc,<target-os>windows:<variant>release
|
||||
<toolset>gcc,<target-os>cygwin:<variant>release
|
||||
;
|
||||
|
||||
run variant_visit_r.cpp : : :
|
||||
<toolset>gcc,<target-os>windows:<variant>release
|
||||
@@ -131,7 +130,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) ;
|
||||
@@ -140,9 +145,9 @@ 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 ] ;
|
||||
compile variant_visit_cx.cpp ;
|
||||
compile variant_visit_cx_2.cpp ;
|
||||
compile variant_visit_r_cx.cpp ;
|
||||
|
||||
local index-type-reqs =
|
||||
|
||||
@@ -166,3 +171,12 @@ 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"
|
||||
;
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_GCC) && BOOST_GCC < 70000
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_GCC < 70000" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -33,26 +43,26 @@ enum E
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
template<class V, class T, class A> constexpr T test( A const& a )
|
||||
template<class V, std::size_t I, class A> constexpr variant_alternative_t<I, V> test( A const& a )
|
||||
{
|
||||
V v;
|
||||
|
||||
v = a;
|
||||
|
||||
return get<T>(v);
|
||||
return get<I>(v);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
constexpr variant<int> v( 1 );
|
||||
constexpr auto w = test<variant<int>, int>( v );
|
||||
constexpr auto w = test<variant<int>, 0>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<X> v( 1 );
|
||||
constexpr auto w = test<variant<X>, X>( v );
|
||||
constexpr auto w = test<variant<X>, 0>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -61,7 +71,7 @@ int main()
|
||||
|
||||
{
|
||||
constexpr variant<Y> v( 1 );
|
||||
constexpr auto w = test<variant<Y>, Y>( v );
|
||||
constexpr auto w = test<variant<Y>, 0>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -69,31 +79,31 @@ int main()
|
||||
|
||||
{
|
||||
constexpr variant<int, float> v( 1 );
|
||||
constexpr auto w = test<variant<int, float>, int>( v );
|
||||
constexpr auto w = test<variant<int, float>, 0>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, float> v( 3.0f );
|
||||
constexpr auto w = test<variant<int, float>, float>( v );
|
||||
constexpr auto w = test<variant<int, float>, 1>( v );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float> v( 3.0f );
|
||||
constexpr auto w = test<variant<int, int, float>, float>( v );
|
||||
constexpr auto w = test<variant<int, int, float>, 2>( v );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<E, E, X> v( 1 );
|
||||
constexpr auto w = test<variant<E, E, X>, X>( v );
|
||||
constexpr auto w = test<variant<E, E, X>, 2>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float, float, X> v( X(1) );
|
||||
constexpr auto w = test<variant<int, int, float, float, X>, X>( v );
|
||||
constexpr auto w = test<variant<int, int, float, float, X>, 4>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -102,15 +112,17 @@ int main()
|
||||
|
||||
{
|
||||
constexpr variant<E, E, Y> v( 1 );
|
||||
constexpr auto w = test<variant<E, E, Y>, Y>( v );
|
||||
constexpr auto w = test<variant<E, E, Y>, 2>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float, float, Y> v( Y(1) );
|
||||
constexpr auto w = test<variant<int, int, float, float, Y>, Y>( v );
|
||||
constexpr auto w = test<variant<int, int, float, float, Y>, 4>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC < 1910" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -33,22 +38,22 @@ enum E
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
template<class T, class V> constexpr T test( V const v )
|
||||
template<std::size_t I, class V> constexpr variant_alternative_t<I, V> test( V const v )
|
||||
{
|
||||
return get<T>( v );
|
||||
return get<I>( v );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
constexpr variant<int> v( 1 );
|
||||
constexpr auto w = test<int>( v );
|
||||
constexpr auto w = test<0>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<X> v( 1 );
|
||||
constexpr auto w = test<X>( v );
|
||||
constexpr auto w = test<0>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -57,7 +62,7 @@ int main()
|
||||
|
||||
{
|
||||
constexpr variant<Y> v( 1 );
|
||||
constexpr auto w = test<Y>( v );
|
||||
constexpr auto w = test<0>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -65,31 +70,31 @@ int main()
|
||||
|
||||
{
|
||||
constexpr variant<int, float> v( 1 );
|
||||
constexpr auto w = test<int>( v );
|
||||
constexpr auto w = test<0>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, float> v( 3.0f );
|
||||
constexpr auto w = test<float>( v );
|
||||
constexpr auto w = test<1>( v );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float> v( 3.0f );
|
||||
constexpr auto w = test<float>( v );
|
||||
constexpr auto w = test<2>( v );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<E, E, X> v( 1 );
|
||||
constexpr auto w = test<X>( v );
|
||||
constexpr auto w = test<2>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float, float, X> v( X(1) );
|
||||
constexpr auto w = test<X>( v );
|
||||
constexpr auto w = test<4>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -98,15 +103,17 @@ int main()
|
||||
|
||||
{
|
||||
constexpr variant<E, E, Y> v( 1 );
|
||||
constexpr auto w = test<Y>( v );
|
||||
constexpr auto w = test<2>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float, float, Y> v( Y(1) );
|
||||
constexpr auto w = test<Y>( v );
|
||||
constexpr auto w = test<4>( v );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC < 1910" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -49,3 +54,5 @@ int main()
|
||||
STATIC_ASSERT( get<0>(v) == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr destructor test because __cpp_constexpr_dynamic_alloc < 201907L")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC < 1950
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC < 1960
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr destructor test because BOOST_MSVC < 1950")
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr destructor test because BOOST_MSVC < 1960")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION < 180000
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -134,3 +139,5 @@ int main()
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -28,24 +33,24 @@ struct Y
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
template<class V, class T, class A> constexpr A test( A const& a )
|
||||
template<class V, std::size_t I, class A, class T = variant_alternative_t<I, V>> constexpr T test( A const& a )
|
||||
{
|
||||
V v;
|
||||
|
||||
v.template emplace<T>( a );
|
||||
|
||||
return get<T>(v);
|
||||
return get<I>(v);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
constexpr auto w = test<variant<int>, int>( 1 );
|
||||
constexpr auto w = test<variant<int>, 0>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<X>, X>( 1 );
|
||||
constexpr auto w = test<variant<X>, 0>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -53,29 +58,29 @@ int main()
|
||||
#else
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<Y>, Y>( 1 );
|
||||
constexpr auto w = test<variant<Y>, 0>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, float>, int>( 1 );
|
||||
constexpr auto w = test<variant<int, float>, 0>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, float>, float>( 3.0f );
|
||||
constexpr auto w = test<variant<int, float>, 1>( 3.0f );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, int, float>, float>( 3.0f );
|
||||
constexpr auto w = test<variant<int, int, float>, 2>( 3.0f );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, int, float, float, X>, X>( 1 );
|
||||
constexpr auto w = test<variant<int, int, float, float, X>, 4>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -83,9 +88,11 @@ int main()
|
||||
#else
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, int, float, float, Y>, Y>( 1 );
|
||||
constexpr auto w = test<variant<int, int, float, float, Y>, 4>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
|
||||
// Copyright 2017, 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
using namespace boost::variant2;
|
||||
|
||||
#if !defined(BOOST_MP11_HAS_CXX14_CONSTEXPR)
|
||||
|
||||
#include <boost/mp11.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr op==, op!= test because BOOST_MP11_HAS_CXX14_CONSTEXPR is not defined")
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
int main() {}
|
||||
|
||||
#elif !defined(BOOST_MP11_HAS_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr op==, op!= test because BOOST_MP11_HAS_CXX14_CONSTEXPR is not defined")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC < 1910" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -94,3 +98,5 @@ int main()
|
||||
STATIC_ASSERT_IF( get_if<2>(&v) == &get<2>(v) );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#if defined( __clang__ ) && defined( __has_warning )
|
||||
# if __has_warning( "-Wdeprecated-volatile" )
|
||||
@@ -217,6 +213,9 @@ int main()
|
||||
BOOST_TEST_EQ( get<int>(v), 0 );
|
||||
BOOST_TEST_EQ( get_if<int>(&v), &get<int>(v) );
|
||||
|
||||
BOOST_TEST_THROWS( get<float>(v), bad_variant_access );
|
||||
BOOST_TEST_EQ( get_if<float>(&v), nullptr );
|
||||
|
||||
BOOST_TEST_EQ( get<int>(std::move(v)), 0 );
|
||||
}
|
||||
|
||||
@@ -226,6 +225,9 @@ int main()
|
||||
BOOST_TEST_EQ( get<int>(v), 0 );
|
||||
BOOST_TEST_EQ( get_if<int>(&v), &get<int>(v) );
|
||||
|
||||
BOOST_TEST_THROWS( get<float>(v), bad_variant_access );
|
||||
BOOST_TEST_EQ( get_if<float>(&v), nullptr );
|
||||
|
||||
BOOST_TEST_EQ( get<int>(std::move(v)), 0 );
|
||||
}
|
||||
|
||||
@@ -235,6 +237,9 @@ int main()
|
||||
BOOST_TEST_EQ( get<int>(v), 1 );
|
||||
BOOST_TEST_EQ( get_if<int>(&v), &get<int>(v) );
|
||||
|
||||
BOOST_TEST_THROWS( get<float>(v), bad_variant_access );
|
||||
BOOST_TEST_EQ( get_if<float>(&v), nullptr );
|
||||
|
||||
BOOST_TEST_EQ( get<int>(std::move(v)), 1 );
|
||||
}
|
||||
|
||||
@@ -244,12 +249,18 @@ int main()
|
||||
BOOST_TEST_EQ( get<int>(v), 1 );
|
||||
BOOST_TEST_EQ( get_if<int>(&v), &get<int>(v) );
|
||||
|
||||
BOOST_TEST_THROWS( get<float>(v), bad_variant_access );
|
||||
BOOST_TEST_EQ( get_if<float>(&v), nullptr );
|
||||
|
||||
BOOST_TEST_EQ( get<int>(std::move(v)), 1 );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float> v( 3.14f );
|
||||
|
||||
BOOST_TEST_THROWS( get<int>(v), bad_variant_access );
|
||||
BOOST_TEST_EQ( get_if<int>(&v), nullptr );
|
||||
|
||||
BOOST_TEST_EQ( get<float>(v), 3.14f );
|
||||
BOOST_TEST_EQ( get_if<float>(&v), &get<float>(v) );
|
||||
|
||||
@@ -259,6 +270,9 @@ int main()
|
||||
{
|
||||
variant<int, int, float> const v( 3.14f );
|
||||
|
||||
BOOST_TEST_THROWS( get<int>(v), bad_variant_access );
|
||||
BOOST_TEST_EQ( get_if<int>(&v), nullptr );
|
||||
|
||||
BOOST_TEST_EQ( get<float>(v), 3.14f );
|
||||
BOOST_TEST_EQ( get_if<float>(&v), &get<float>(v) );
|
||||
|
||||
@@ -301,11 +315,13 @@ int main()
|
||||
|
||||
{
|
||||
variant<int, int, float> * p = 0;
|
||||
BOOST_TEST_EQ( get_if<int>(p), nullptr );
|
||||
BOOST_TEST_EQ( get_if<float>(p), nullptr );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float> const * p = 0;
|
||||
BOOST_TEST_EQ( get_if<int>(p), nullptr );
|
||||
BOOST_TEST_EQ( get_if<float>(p), nullptr );
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/mp11.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(BOOST_MP11_HAS_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_MP11_HAS_CXX14_CONSTEXPR is not defined")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -70,6 +75,7 @@ int main()
|
||||
STATIC_ASSERT( get<int>(v) == 0 );
|
||||
|
||||
STATIC_ASSERT_IF( get_if<int>(&v) == &get<int>(v) );
|
||||
STATIC_ASSERT_IF( get_if<float>(&v) == nullptr );
|
||||
}
|
||||
|
||||
{
|
||||
@@ -78,6 +84,7 @@ int main()
|
||||
STATIC_ASSERT( get<int>(v) == 1 );
|
||||
|
||||
STATIC_ASSERT_IF( get_if<int>(&v) == &get<int>(v) );
|
||||
STATIC_ASSERT_IF( get_if<float>(&v) == nullptr );
|
||||
}
|
||||
|
||||
{
|
||||
@@ -85,6 +92,9 @@ int main()
|
||||
|
||||
STATIC_ASSERT( get<float>(v) == (float)3.14f );
|
||||
|
||||
STATIC_ASSERT_IF( get_if<int>(&v) == nullptr );
|
||||
STATIC_ASSERT_IF( get_if<float>(&v) == &get<float>(v) );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
@@ -34,13 +30,27 @@ int main()
|
||||
{
|
||||
variant<int, float, float> v;
|
||||
BOOST_TEST( holds_alternative<int>( v ) );
|
||||
BOOST_TEST( !holds_alternative<float>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float> v( 3.14f );
|
||||
BOOST_TEST( !holds_alternative<int>( v ) );
|
||||
BOOST_TEST( holds_alternative<float>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float> v( in_place_index_t<0>{} );
|
||||
BOOST_TEST( holds_alternative<int>( v ) );
|
||||
BOOST_TEST( !holds_alternative<float>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float> v( in_place_index_t<1>{} );
|
||||
BOOST_TEST( holds_alternative<int>( v ) );
|
||||
BOOST_TEST( !holds_alternative<float>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float, std::string> v;
|
||||
BOOST_TEST( holds_alternative<int>( v ) );
|
||||
@@ -64,15 +74,31 @@ int main()
|
||||
|
||||
{
|
||||
variant<int, int, float, std::string> v( 3.14f );
|
||||
BOOST_TEST( !holds_alternative<int>( v ) );
|
||||
BOOST_TEST( holds_alternative<float>( v ) );
|
||||
BOOST_TEST( !holds_alternative<std::string>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float, std::string> v( "text" );
|
||||
BOOST_TEST( !holds_alternative<int>( v ) );
|
||||
BOOST_TEST( !holds_alternative<float>( v ) );
|
||||
BOOST_TEST( holds_alternative<std::string>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float, std::string> v( in_place_index_t<0>{} );
|
||||
BOOST_TEST( holds_alternative<int>( v ) );
|
||||
BOOST_TEST( !holds_alternative<float>( v ) );
|
||||
BOOST_TEST( !holds_alternative<std::string>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float, std::string> v( in_place_index_t<1>{} );
|
||||
BOOST_TEST( holds_alternative<int>( v ) );
|
||||
BOOST_TEST( !holds_alternative<float>( v ) );
|
||||
BOOST_TEST( !holds_alternative<std::string>( v ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC < 1910" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -34,10 +39,20 @@ int main()
|
||||
{
|
||||
constexpr variant<int, float, float> v;
|
||||
STATIC_ASSERT( holds_alternative<int>( v ) );
|
||||
STATIC_ASSERT( !holds_alternative<float>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float> v( 3.14f );
|
||||
STATIC_ASSERT( !holds_alternative<int>( v ) );
|
||||
STATIC_ASSERT( holds_alternative<float>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float> v;
|
||||
STATIC_ASSERT( holds_alternative<int>( v ) );
|
||||
STATIC_ASSERT( !holds_alternative<float>( v ) );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC < 1910" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -119,3 +123,5 @@ int main()
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC < 1910" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -118,3 +122,5 @@ int main()
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
@@ -1,24 +1,26 @@
|
||||
|
||||
// Copyright 2017, 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
using namespace boost::variant2;
|
||||
|
||||
#if !defined(BOOST_MP11_HAS_CXX14_CONSTEXPR)
|
||||
|
||||
#include <boost/mp11.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr op<, op<= test because BOOST_MP11_HAS_CXX14_CONSTEXPR is not defined")
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
int main() {}
|
||||
|
||||
#elif !defined(BOOST_MP11_HAS_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr op<, op<= test because BOOST_MP11_HAS_CXX14_CONSTEXPR is not defined")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <utility>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_GCC) && BOOST_GCC < 70000
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_GCC < 70000" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
struct X
|
||||
@@ -34,24 +44,24 @@ enum E
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
template<class V, class T, class A> constexpr T test( A&& a )
|
||||
template<class V, std::size_t I, class A> constexpr variant_alternative_t<I, V> test( A&& a )
|
||||
{
|
||||
V v;
|
||||
|
||||
v = std::forward<A>(a);
|
||||
|
||||
return get<T>(v);
|
||||
return get<I>(v);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
constexpr auto w = test<variant<int>, int>( variant<int>( 1 ) );
|
||||
constexpr auto w = test<variant<int>, 0>( variant<int>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<X>, X>( variant<X>( 1 ) );
|
||||
constexpr auto w = test<variant<X>, 0>( variant<X>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -59,34 +69,34 @@ int main()
|
||||
#else
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<Y>, Y>( variant<Y>( 1 ) );
|
||||
constexpr auto w = test<variant<Y>, 0>( variant<Y>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, float>, int>( variant<int, float>( 1 ) );
|
||||
constexpr auto w = test<variant<int, float>, 0>( variant<int, float>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, float>, float>( variant<int, float>( 3.0f ) );
|
||||
constexpr auto w = test<variant<int, float>, 1>( variant<int, float>( 3.0f ) );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, int, float>, float>( variant<int, int, float>( 3.0f ) );
|
||||
constexpr auto w = test<variant<int, int, float>, 2>( variant<int, int, float>( 3.0f ) );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<E, E, X>, X>( variant<E, E, X>( 1 ) );
|
||||
constexpr auto w = test<variant<E, E, X>, 2>( variant<E, E, X>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, int, float, float, X>, X>( variant<int, int, float, float, X>( X(1) ) );
|
||||
constexpr auto w = test<variant<int, int, float, float, X>, 4>( variant<int, int, float, float, X>( X(1) ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -94,14 +104,16 @@ int main()
|
||||
#else
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<E, E, Y>, Y>( variant<E, E, Y>( 1 ) );
|
||||
constexpr auto w = test<variant<E, E, Y>, 2>( variant<E, E, Y>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, int, float, float, Y>, Y>( variant<int, int, float, float, Y>( Y(1) ) );
|
||||
constexpr auto w = test<variant<int, int, float, float, Y>, 4>( variant<int, int, float, float, Y>( Y(1) ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <utility>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
struct X
|
||||
@@ -34,21 +39,21 @@ enum E
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
template<class T, class V> constexpr T test( V&& v )
|
||||
template<std::size_t I, class V> constexpr variant_alternative_t<I, V> test( V&& v )
|
||||
{
|
||||
V v2( std::forward<V>(v) );
|
||||
return get<T>( v2 );
|
||||
return get<I>( v2 );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
constexpr auto w = test<int>( variant<int>( 1 ) );
|
||||
constexpr auto w = test<0>( variant<int>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<X>( variant<X>( 1 ) );
|
||||
constexpr auto w = test<0>( variant<X>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -56,34 +61,34 @@ int main()
|
||||
#else
|
||||
|
||||
{
|
||||
constexpr auto w = test<Y>( variant<Y>( 1 ) );
|
||||
constexpr auto w = test<0>( variant<Y>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
constexpr auto w = test<int>( variant<int, float>( 1 ) );
|
||||
constexpr auto w = test<0>( variant<int, float>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<float>( variant<int, float>( 3.0f ) );
|
||||
constexpr auto w = test<1>( variant<int, float>( 3.0f ) );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<float>( variant<int, int, float>( 3.0f ) );
|
||||
constexpr auto w = test<2>( variant<int, int, float>( 3.0f ) );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<X>( variant<E, E, X>( 1 ) );
|
||||
constexpr auto w = test<2>( variant<E, E, X>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<X>( variant<int, int, float, float, X>( X(1) ) );
|
||||
constexpr auto w = test<4>( variant<int, int, float, float, X>( X(1) ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -91,14 +96,16 @@ int main()
|
||||
#else
|
||||
|
||||
{
|
||||
constexpr auto w = test<Y>( variant<E, E, Y>( 1 ) );
|
||||
constexpr auto w = test<2>( variant<E, E, Y>( 1 ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<Y>( variant<int, int, float, float, Y>( Y(1) ) );
|
||||
constexpr auto w = test<4>( variant<int, int, float, float, Y>( Y(1) ) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -33,24 +38,24 @@ enum E
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
template<class V, class T, class A> constexpr A test( A const& a )
|
||||
template<class V, std::size_t I, class A> constexpr variant_alternative_t<I, V> test( A const& a )
|
||||
{
|
||||
V v;
|
||||
|
||||
v = a;
|
||||
|
||||
return get<T>(v);
|
||||
return get<I>(v);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
constexpr auto w = test<variant<int>, int>( 1 );
|
||||
constexpr auto w = test<variant<int>, 0>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<X>, X>( 1 );
|
||||
constexpr auto w = test<variant<X>, 0>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -58,34 +63,34 @@ int main()
|
||||
#else
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<Y>, Y>( 1 );
|
||||
constexpr auto w = test<variant<Y>, 0>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, float>, int>( 1 );
|
||||
constexpr auto w = test<variant<int, float>, 0>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, float>, float>( 3.0f );
|
||||
constexpr auto w = test<variant<int, float>, 1>( 3.0f );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, int, float>, float>( 3.0f );
|
||||
constexpr auto w = test<variant<int, int, float>, 2>( 3.0f );
|
||||
STATIC_ASSERT( w == 3.0f );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<E, E, X>, X>( 1 );
|
||||
constexpr auto w = test<variant<E, E, X>, 2>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, int, float, float, X>, X>( X(1) );
|
||||
constexpr auto w = test<variant<int, int, float, float, X>, 4>( X(1) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
@@ -93,14 +98,16 @@ int main()
|
||||
#else
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<E, E, Y>, Y>( 1 );
|
||||
constexpr auto w = test<variant<E, E, Y>, 2>( 1 );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr auto w = test<variant<int, int, float, float, Y>, Y>( Y(1) );
|
||||
constexpr auto w = test<variant<int, int, float, float, Y>, 4>( Y(1) );
|
||||
STATIC_ASSERT( w == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Copyright 2017, 2026 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
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC < 1910" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
@@ -107,3 +112,5 @@ int main()
|
||||
STATIC_ASSERT( holds_alternative<X>(v) );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because __cpp_constexpr_dynamic_alloc < 201907L")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC < 1950
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC < 1960
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_MSVC < 1950")
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_MSVC < 1960")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION < 180000
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
// Copyright 2017, 2024 Peter Dimov
|
||||
// Copyright 2017, 2024, 2026 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/mp11.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr visit test because BOOST_MP11_HAS_CXX14_CONSTEXPR is not defined")
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
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 X
|
||||
{
|
||||
constexpr operator int() const { return 2; }
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
// Copyright 2017, 2024 Peter Dimov
|
||||
// Copyright 2017, 2024, 2026 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/mp11.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr visit test because BOOST_MP11_HAS_CXX14_CONSTEXPR is not defined")
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
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 X
|
||||
{
|
||||
int v;
|
||||
|
||||
Reference in New Issue
Block a user