1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
12 // template<class... B> struct disjunction; // C++17
13 // template<class... B>
14 // constexpr bool disjunction_v = disjunction<B...>::value; // C++17
16 #include <type_traits>
19 #include "test_macros.h"
21 struct True
{ static constexpr bool value
= true; };
22 struct False
{ static constexpr bool value
= false; };
24 struct MySpecialTrueType
{ static constexpr auto value
= -1; static constexpr auto MySpecial
= 37; };
25 struct MySpecialFalseType
{ static constexpr auto value
= false; static constexpr auto MySpecial
= 23; };
26 struct MyOtherSpecialFalseType
{ static constexpr auto value
= false; static constexpr auto MySpecial
= 46; };
28 struct ExplicitlyConvertibleToBool
{ explicit constexpr operator bool() const { return false; } };
29 struct ValueExplicitlyConvertible
{ static constexpr ExplicitlyConvertibleToBool value
{}; };
31 static_assert(!std::disjunction
<>::value
);
32 static_assert( std::disjunction
<std::true_type
>::value
);
33 static_assert(!std::disjunction
<std::false_type
>::value
);
35 static_assert(!std::disjunction_v
<>);
36 static_assert( std::disjunction_v
<std::true_type
>);
37 static_assert(!std::disjunction_v
<std::false_type
>);
39 static_assert( std::disjunction
<std::true_type
, std::true_type
>::value
);
40 static_assert( std::disjunction
<std::true_type
, std::false_type
>::value
);
41 static_assert( std::disjunction
<std::false_type
, std::true_type
>::value
);
42 static_assert(!std::disjunction
<std::false_type
, std::false_type
>::value
);
44 static_assert( std::disjunction_v
<std::true_type
, std::true_type
>);
45 static_assert( std::disjunction_v
<std::true_type
, std::false_type
>);
46 static_assert( std::disjunction_v
<std::false_type
, std::true_type
>);
47 static_assert(!std::disjunction_v
<std::false_type
, std::false_type
>);
49 static_assert( std::disjunction
<std::true_type
, std::true_type
, std::true_type
>::value
);
50 static_assert( std::disjunction
<std::true_type
, std::false_type
, std::true_type
>::value
);
51 static_assert( std::disjunction
<std::false_type
, std::true_type
, std::true_type
>::value
);
52 static_assert( std::disjunction
<std::false_type
, std::false_type
, std::true_type
>::value
);
53 static_assert( std::disjunction
<std::true_type
, std::true_type
, std::false_type
>::value
);
54 static_assert( std::disjunction
<std::true_type
, std::false_type
, std::false_type
>::value
);
55 static_assert( std::disjunction
<std::false_type
, std::true_type
, std::false_type
>::value
);
56 static_assert(!std::disjunction
<std::false_type
, std::false_type
, std::false_type
>::value
);
58 static_assert( std::disjunction_v
<std::true_type
, std::true_type
, std::true_type
>);
59 static_assert( std::disjunction_v
<std::true_type
, std::false_type
, std::true_type
>);
60 static_assert( std::disjunction_v
<std::false_type
, std::true_type
, std::true_type
>);
61 static_assert( std::disjunction_v
<std::false_type
, std::false_type
, std::true_type
>);
62 static_assert( std::disjunction_v
<std::true_type
, std::true_type
, std::false_type
>);
63 static_assert( std::disjunction_v
<std::true_type
, std::false_type
, std::false_type
>);
64 static_assert( std::disjunction_v
<std::false_type
, std::true_type
, std::false_type
>);
65 static_assert(!std::disjunction_v
<std::false_type
, std::false_type
, std::false_type
>);
67 static_assert ( std::disjunction
<True
>::value
, "" );
68 static_assert (!std::disjunction
<False
>::value
, "" );
70 static_assert ( std::disjunction_v
<True
>, "" );
71 static_assert (!std::disjunction_v
<False
>, "" );
73 static_assert(std::is_base_of_v
<MySpecialFalseType
, std::disjunction
<MyOtherSpecialFalseType
, MySpecialFalseType
>>);
74 static_assert(std::is_base_of_v
<MyOtherSpecialFalseType
, std::disjunction
<MySpecialFalseType
, MyOtherSpecialFalseType
>>);
75 static_assert(std::is_base_of_v
<MySpecialTrueType
, std::disjunction
<MySpecialTrueType
, MyOtherSpecialFalseType
>>);
76 static_assert(std::is_base_of_v
<MySpecialTrueType
, std::disjunction
<MyOtherSpecialFalseType
, MySpecialTrueType
>>);
78 static_assert(std::is_base_of_v
<std::true_type
, std::disjunction
<std::true_type
, HasNoValue
>>);
80 static_assert(std::disjunction
<std::true_type
, HasNoValue
>::value
);
81 static_assert(std::disjunction_v
<std::true_type
, HasNoValue
>);
83 // Also check the case where HasNoValue is not the last in the list (https://llvm.org/PR584900).
84 static_assert(std::disjunction
<std::true_type
, HasNoValue
, std::true_type
>::value
);
85 static_assert(std::disjunction_v
<std::true_type
, HasNoValue
, std::true_type
>);
87 static_assert(std::disjunction
<std::true_type
, HasNoValue
, std::false_type
>::value
);
88 static_assert(std::disjunction_v
<std::true_type
, HasNoValue
, std::false_type
>);
90 static_assert(std::disjunction
<MySpecialTrueType
>::value
== -1);
91 static_assert(std::disjunction_v
<MySpecialTrueType
>);
93 static_assert(std::is_base_of_v
<ValueExplicitlyConvertible
, std::disjunction
<ValueExplicitlyConvertible
>>);
94 static_assert(std::disjunction_v
<ValueExplicitlyConvertible
, std::true_type
>);