1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
13 // template <size_t I, class T> struct variant_alternative; // undefined
14 // template <size_t I, class T> struct variant_alternative<I, const T>;
15 // template <size_t I, class T> struct variant_alternative<I, volatile T>;
16 // template <size_t I, class T> struct variant_alternative<I, const volatile T>;
17 // template <size_t I, class T>
18 // using variant_alternative_t = typename variant_alternative<I, T>::type;
20 // template <size_t I, class... Types>
21 // struct variant_alternative<I, variant<Types...>>;
24 #include <type_traits>
27 #include "test_macros.h"
28 #include "variant_test_helpers.h"
30 template <class V
, std::size_t I
, class E
> void test() {
32 std::is_same_v
<typename
std::variant_alternative
<I
, V
>::type
, E
>, "");
34 std::is_same_v
<typename
std::variant_alternative
<I
, const V
>::type
,
38 std::is_same_v
<typename
std::variant_alternative
<I
, volatile V
>::type
,
43 typename
std::variant_alternative
<I
, const volatile V
>::type
,
46 static_assert(std::is_same_v
<std::variant_alternative_t
<I
, V
>, E
>, "");
47 static_assert(std::is_same_v
<std::variant_alternative_t
<I
, const V
>, const E
>,
50 std::is_same_v
<std::variant_alternative_t
<I
, volatile V
>, volatile E
>,
52 static_assert(std::is_same_v
<std::variant_alternative_t
<I
, const volatile V
>,
57 int main(int, char**) {
59 using V
= std::variant
<int, void *, const void *, long double>;
62 test
<V
, 2, const void *>();
63 test
<V
, 3, long double>();
65 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
67 using V
= std::variant
<int, int &, const int &, int &&, long double>;
70 test
<V
, 2, const int &>();
72 test
<V
, 4, long double>();