re PR libstdc++/78441 ([variant] variant_alternative doesn't allow cv qualifiers)
PR libstdc++/78441 * include/std/variant: Propagate cv qualifications to types returned by variant_alternative. * testsuite/20_util/variant/compile.cc: Tests. From-SVN: r242892
This commit is contained in:
parent
216c1ee838
commit
3203ed5f01
3 changed files with 28 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
|||
2016-11-26 Tim Shen <timshen@google.com>
|
||||
|
||||
PR libstdc++/78441
|
||||
* include/std/variant: Propagate cv qualifications to types returned
|
||||
by variant_alternative.
|
||||
* testsuite/20_util/variant/compile.cc: Tests.
|
||||
|
||||
2016-11-23 Felix Morgner <felix.morgner@gmail.com>
|
||||
Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
|
|
|
@ -85,6 +85,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
using variant_alternative_t =
|
||||
typename variant_alternative<_Np, _Variant>::type;
|
||||
|
||||
template<size_t _Np, typename _Variant>
|
||||
struct variant_alternative<_Np, const _Variant>
|
||||
{ using type = add_const_t<variant_alternative_t<_Np, _Variant>>; };
|
||||
|
||||
template<size_t _Np, typename _Variant>
|
||||
struct variant_alternative<_Np, volatile _Variant>
|
||||
{ using type = add_volatile_t<variant_alternative_t<_Np, _Variant>>; };
|
||||
|
||||
template<size_t _Np, typename _Variant>
|
||||
struct variant_alternative<_Np, const volatile _Variant>
|
||||
{ using type = add_cv_t<variant_alternative_t<_Np, _Variant>>; };
|
||||
|
||||
constexpr size_t variant_npos = -1;
|
||||
|
||||
_GLIBCXX_END_NAMESPACE_VERSION
|
||||
|
|
|
@ -330,3 +330,12 @@ void test_adl()
|
|||
variant<X> v8{allocator_arg, a, in_place_type<X>, il, x};
|
||||
variant<X> v9{allocator_arg, a, in_place_type<X>, 1};
|
||||
}
|
||||
|
||||
void test_variant_alternative() {
|
||||
static_assert(is_same_v<variant_alternative_t<0, variant<int, string>>, int>, "");
|
||||
static_assert(is_same_v<variant_alternative_t<1, variant<int, string>>, string>, "");
|
||||
|
||||
static_assert(is_same_v<variant_alternative_t<0, const variant<int>>, const int>, "");
|
||||
static_assert(is_same_v<variant_alternative_t<0, volatile variant<int>>, volatile int>, "");
|
||||
static_assert(is_same_v<variant_alternative_t<0, const volatile variant<int>>, const volatile int>, "");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue