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

source code of libcxx/test/std/utilities/meta/meta.logical/disjunction.compile.pass.cpp