1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03, c++11, c++14 11 12 // <variant> 13 14 // template <size_t I, class T> struct variant_alternative; // undefined 15 // template <size_t I, class T> struct variant_alternative<I, const T>; 16 // template <size_t I, class T> struct variant_alternative<I, volatile T>; 17 // template <size_t I, class T> struct variant_alternative<I, const volatile T>; 18 // template <size_t I, class T> 19 // using variant_alternative_t = typename variant_alternative<I, T>::type; 20 // 21 // template <size_t I, class... Types> 22 // struct variant_alternative<I, variant<Types...>>; 23 24 #include <memory> 25 #include <type_traits> 26 #include <variant> 27 28 #include "test_macros.h" 29 #include "variant_test_helpers.h" 30 31 template <class V, size_t I, class E> void test() { 32 static_assert( 33 std::is_same_v<typename std::variant_alternative<I, V>::type, E>, ""); 34 static_assert( 35 std::is_same_v<typename std::variant_alternative<I, const V>::type, 36 const E>, 37 ""); 38 static_assert( 39 std::is_same_v<typename std::variant_alternative<I, volatile V>::type, 40 volatile E>, 41 ""); 42 static_assert( 43 std::is_same_v< 44 typename std::variant_alternative<I, const volatile V>::type, 45 const volatile E>, 46 ""); 47 static_assert(std::is_same_v<std::variant_alternative_t<I, V>, E>, ""); 48 static_assert(std::is_same_v<std::variant_alternative_t<I, const V>, const E>, 49 ""); 50 static_assert( 51 std::is_same_v<std::variant_alternative_t<I, volatile V>, volatile E>, 52 ""); 53 static_assert(std::is_same_v<std::variant_alternative_t<I, const volatile V>, 54 const volatile E>, 55 ""); 56 } 57 58 int main(int, char**) { 59 { 60 using V = std::variant<int, void *, const void *, long double>; 61 test<V, 0, int>(); 62 test<V, 1, void *>(); 63 test<V, 2, const void *>(); 64 test<V, 3, long double>(); 65 } 66 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) 67 { 68 using V = std::variant<int, int &, const int &, int &&, long double>; 69 test<V, 0, int>(); 70 test<V, 1, int &>(); 71 test<V, 2, const int &>(); 72 test<V, 3, int &&>(); 73 test<V, 4, long double>(); 74 } 75 #endif 76 77 return 0; 78 } 79