1 | //===----------------------------------------------------------------------===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11, c++14 |
10 | |
11 | // <variant> |
12 | |
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; |
19 | // |
20 | // template <size_t I, class... Types> |
21 | // struct variant_alternative<I, variant<Types...>>; |
22 | |
23 | #include <memory> |
24 | #include <type_traits> |
25 | #include <variant> |
26 | |
27 | #include "test_macros.h" |
28 | #include "variant_test_helpers.h" |
29 | |
30 | template <class V, std::size_t I, class E> void test() { |
31 | static_assert( |
32 | std::is_same_v<typename std::variant_alternative<I, V>::type, E>, "" ); |
33 | static_assert( |
34 | std::is_same_v<typename std::variant_alternative<I, const V>::type, |
35 | const E>, |
36 | "" ); |
37 | static_assert( |
38 | std::is_same_v<typename std::variant_alternative<I, volatile V>::type, |
39 | volatile E>, |
40 | "" ); |
41 | static_assert( |
42 | std::is_same_v< |
43 | typename std::variant_alternative<I, const volatile V>::type, |
44 | const volatile E>, |
45 | "" ); |
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>, |
48 | "" ); |
49 | static_assert( |
50 | std::is_same_v<std::variant_alternative_t<I, volatile V>, volatile E>, |
51 | "" ); |
52 | static_assert(std::is_same_v<std::variant_alternative_t<I, const volatile V>, |
53 | const volatile E>, |
54 | "" ); |
55 | } |
56 | |
57 | int main(int, char**) { |
58 | { |
59 | using V = std::variant<int, void *, const void *, long double>; |
60 | test<V, 0, int>(); |
61 | test<V, 1, void *>(); |
62 | test<V, 2, const void *>(); |
63 | test<V, 3, long double>(); |
64 | } |
65 | |
66 | return 0; |
67 | } |
68 | |