Home | History | Annotate | Download | only in variant.helpers
      1 // -*- C++ -*-
      2 //===----------------------------------------------------------------------===//
      3 //
      4 //                     The LLVM Compiler Infrastructure
      5 //
      6 // This file is dual licensed under the MIT and the University of Illinois Open
      7 // Source Licenses. See LICENSE.TXT for details.
      8 //
      9 //===----------------------------------------------------------------------===//
     10 
     11 // UNSUPPORTED: c++98, c++03, c++11, c++14
     12 
     13 // <variant>
     14 
     15 // template <size_t I, class T> struct variant_alternative; // undefined
     16 // template <size_t I, class T> struct variant_alternative<I, const T>;
     17 // template <size_t I, class T> struct variant_alternative<I, volatile T>;
     18 // template <size_t I, class T> struct variant_alternative<I, const volatile T>;
     19 // template <size_t I, class T>
     20 //   using variant_alternative_t = typename variant_alternative<I, T>::type;
     21 //
     22 // template <size_t I, class... Types>
     23 //    struct variant_alternative<I, variant<Types...>>;
     24 
     25 #include <memory>
     26 #include <type_traits>
     27 #include <variant>
     28 
     29 #include "test_macros.h"
     30 #include "variant_test_helpers.hpp"
     31 
     32 template <class V, size_t I, class E> void test() {
     33   static_assert(
     34       std::is_same_v<typename std::variant_alternative<I, V>::type, E>, "");
     35   static_assert(
     36       std::is_same_v<typename std::variant_alternative<I, const V>::type,
     37                      const E>,
     38       "");
     39   static_assert(
     40       std::is_same_v<typename std::variant_alternative<I, volatile V>::type,
     41                      volatile E>,
     42       "");
     43   static_assert(
     44       std::is_same_v<
     45           typename std::variant_alternative<I, const volatile V>::type,
     46           const volatile E>,
     47       "");
     48   static_assert(std::is_same_v<std::variant_alternative_t<I, V>, E>, "");
     49   static_assert(std::is_same_v<std::variant_alternative_t<I, const V>, const E>,
     50                 "");
     51   static_assert(
     52       std::is_same_v<std::variant_alternative_t<I, volatile V>, volatile E>,
     53       "");
     54   static_assert(std::is_same_v<std::variant_alternative_t<I, const volatile V>,
     55                                const volatile E>,
     56                 "");
     57 }
     58 
     59 int main() {
     60   {
     61     using V = std::variant<int, void *, const void *, long double>;
     62     test<V, 0, int>();
     63     test<V, 1, void *>();
     64     test<V, 2, const void *>();
     65     test<V, 3, long double>();
     66   }
     67 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
     68   {
     69     using V = std::variant<int, int &, const int &, int &&, long double>;
     70     test<V, 0, int>();
     71     test<V, 1, int &>();
     72     test<V, 2, const int &>();
     73     test<V, 3, int &&>();
     74     test<V, 4, long double>();
     75   }
     76 #endif
     77 }
     78