aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorTim Shen <timshen@google.com>2016-11-27 00:32:04 +0000
committerTim Shen <timshen@gcc.gnu.org>2016-11-27 00:32:04 +0000
commit3203ed5f0182e7dbf1c74e6598e718641a3d4013 (patch)
tree0db3aa4bf197b8f1448c76a2cd58777ba299b74b /libstdc++-v3
parent216c1ee8384255ff0a345608d0f97e74b2da312c (diff)
downloadgcc-3203ed5f0182e7dbf1c74e6598e718641a3d4013.zip
gcc-3203ed5f0182e7dbf1c74e6598e718641a3d4013.tar.gz
gcc-3203ed5f0182e7dbf1c74e6598e718641a3d4013.tar.bz2
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
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog7
-rw-r--r--libstdc++-v3/include/std/variant12
-rw-r--r--libstdc++-v3/testsuite/20_util/variant/compile.cc9
3 files changed, 28 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index d663f70..4a26191 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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>
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 7d93575..34ad3fd 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -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
diff --git a/libstdc++-v3/testsuite/20_util/variant/compile.cc b/libstdc++-v3/testsuite/20_util/variant/compile.cc
index 2470bcc..e3330be 100644
--- a/libstdc++-v3/testsuite/20_util/variant/compile.cc
+++ b/libstdc++-v3/testsuite/20_util/variant/compile.cc
@@ -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>, "");
+}