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 <class ...Types> class variant;
16
17 // constexpr size_t index() const noexcept;
18
19 #include <cassert>
20 #include <string>
21 #include <type_traits>
22 #include <variant>
23
24 #include "archetypes.hpp"
25 #include "test_macros.h"
26 #include "variant_test_helpers.hpp"
27
28
main()29 int main() {
30 {
31 using V = std::variant<int, long>;
32 constexpr V v;
33 static_assert(v.index() == 0, "");
34 }
35 {
36 using V = std::variant<int, long>;
37 V v;
38 assert(v.index() == 0);
39 }
40 {
41 using V = std::variant<int, long>;
42 constexpr V v(std::in_place_index<1>);
43 static_assert(v.index() == 1, "");
44 }
45 {
46 using V = std::variant<int, std::string>;
47 V v("abc");
48 assert(v.index() == 1);
49 v = 42;
50 assert(v.index() == 0);
51 }
52 #ifndef TEST_HAS_NO_EXCEPTIONS
53 {
54 using V = std::variant<int, MakeEmptyT>;
55 V v;
56 assert(v.index() == 0);
57 makeEmpty(v);
58 assert(v.index() == std::variant_npos);
59 }
60 #endif
61 }
62