Debian Codegraph @

libcxx/test/libcxx-03/utilities/meta/meta_base.pass.cpp

raw
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
10 #include "test_macros.h"
11
12 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wprivate-header")
13 #include <__cxx03/__type_traits/conjunction.h>
14 #include <__cxx03/__type_traits/disjunction.h>
15 #include <__cxx03/__type_traits/is_valid_expansion.h>
16 #include <__cxx03/__type_traits/negation.h>
17 #include <cassert>
18 #include <type_traits>
19 #include <utility>
20
21 struct Bomb;
22 template <int N, class T = Bomb >
23 struct BOOM {
24 using Explode = typename T::BOOMBOOM;
25 };
26
27 using True = std::true_type;
28 using False = std::false_type;
29
30 void test_if() {
31 ASSERT_SAME_TYPE(std::_If<true, int, long>, int);
32 ASSERT_SAME_TYPE(std::_If<false, int, long>, long);
33 }
34
35 void test_and() {
36 static_assert(std::_And<True>::value, "");
37 static_assert(!std::_And<False>::value, "");
38 static_assert(std::_And<True, True>::value, "");
39 static_assert(!std::_And<False, BOOM<1> >::value, "");
40 static_assert(!std::_And<True, True, True, False, BOOM<2> >::value, "");
41 }
42
43 void test_or() {
44 static_assert(std::_Or<True>::value, "");
45 static_assert(!std::_Or<False>::value, "");
46 static_assert(std::_Or<False, True>::value, "");
47 static_assert(std::_Or<True, std::_Not<BOOM<3> > >::value, "");
48 static_assert(!std::_Or<False, False>::value, "");
49 static_assert(std::_Or<True, BOOM<1> >::value, "");
50 static_assert(std::_Or<False, False, False, False, True, BOOM<2> >::value, "");
51 }
52
53 void test_combined() {
54 static_assert(std::_And<True, std::_Or<False, True, BOOM<4> > >::value, "");
55 static_assert(std::_And<True, std::_Or<False, True, BOOM<4> > >::value, "");
56 static_assert(std::_Not<std::_And<True, False, BOOM<5> > >::value, "");
57 }
58
59 struct MemberTest {
60 static int foo;
61 using type = long;
62
63 void func(int);
64 };
65 struct Empty {};
66 struct MemberTest2 {
67 using foo = int;
68 };
69 template <class T>
70 using HasFooData = decltype(T::foo);
71 template <class T>
72 using HasFooType = typename T::foo;
73
74 template <class T, class U>
75 using FuncCallable = decltype(std::declval<T>().func(std::declval<U>()));
76 template <class T>
77 using BadCheck = typename T::DOES_NOT_EXIST;
78
79 void test_is_valid_trait() {
80 static_assert(std::_IsValidExpansion<HasFooData, MemberTest>::value, "");
81 static_assert(!std::_IsValidExpansion<HasFooType, MemberTest>::value, "");
82 static_assert(!std::_IsValidExpansion<HasFooData, MemberTest2>::value, "");
83 static_assert(std::_IsValidExpansion<HasFooType, MemberTest2>::value, "");
84 static_assert(std::_IsValidExpansion<FuncCallable, MemberTest, int>::value, "");
85 static_assert(!std::_IsValidExpansion<FuncCallable, MemberTest, void*>::value, "");
86 }
87
88 int main(int, char**) {
89 return 0;
90 }