xref: /llvm-project/libcxx/test/std/utilities/variant/variant.get/holds_alternative.pass.cpp (revision d4b59a05fc7507cf69993109443dc5af47ae4fa8)
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 <class T, class... Types>
14 // constexpr bool holds_alternative(const variant<Types...>& v) noexcept;
15 
16 #include "test_macros.h"
17 #include <variant>
18 
main(int,char **)19 int main(int, char**) {
20   {
21     using V = std::variant<int>;
22     constexpr V v;
23     static_assert(std::holds_alternative<int>(v), "");
24   }
25   {
26     using V = std::variant<int, long>;
27     constexpr V v;
28     static_assert(std::holds_alternative<int>(v), "");
29     static_assert(!std::holds_alternative<long>(v), "");
30   }
31   { // noexcept test
32     using V = std::variant<int>;
33     const V v;
34     ASSERT_NOEXCEPT(std::holds_alternative<int>(v));
35   }
36 
37   return 0;
38 }
39