+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>
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
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>, "");
+}