91 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9 10#include "test_macros.h"11 12TEST_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 21struct Bomb;22template <int N, class T = Bomb >23struct BOOM {24 using Explode = typename T::BOOMBOOM;25};26 27using True = std::true_type;28using False = std::false_type;29 30void test_if() {31 ASSERT_SAME_TYPE(std::_If<true, int, long>, int);32 ASSERT_SAME_TYPE(std::_If<false, int, long>, long);33}34 35void 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 43void 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 53void 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 59struct MemberTest {60 static int foo;61 using type = long;62 63 void func(int);64};65struct Empty {};66struct MemberTest2 {67 using foo = int;68};69template <class T>70using HasFooData = decltype(T::foo);71template <class T>72using HasFooType = typename T::foo;73 74template <class T, class U>75using FuncCallable = decltype(std::declval<T>().func(std::declval<U>()));76template <class T>77using BadCheck = typename T::DOES_NOT_EXIST;78 79void 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 88int main(int, char**) {89 return 0;90}91