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 #ifndef _LIBCPP___TYPE_TRAITS_DISJUNCTION_H 10 #define _LIBCPP___TYPE_TRAITS_DISJUNCTION_H 11 12 #include <__config> 13 #include <__type_traits/integral_constant.h> 14 15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 16 # pragma GCC system_header 17 #endif 18 19 _LIBCPP_BEGIN_NAMESPACE_STD 20 21 template <bool> 22 struct _OrImpl; 23 24 template <> 25 struct _OrImpl<true> { 26 template <class _Res, class _First, class... _Rest> 27 using _Result _LIBCPP_NODEBUG = 28 typename _OrImpl<!bool(_First::value) && sizeof...(_Rest) != 0>::template _Result<_First, _Rest...>; 29 }; 30 31 template <> 32 struct _OrImpl<false> { 33 template <class _Res, class...> 34 using _Result = _Res; 35 }; 36 37 // _Or always performs lazy evaluation of its arguments. 38 // 39 // However, `_Or<_Pred...>` itself will evaluate its result immediately (without having to 40 // be instantiated) since it is an alias, unlike `disjunction<_Pred...>`, which is a struct. 41 // If you want to defer the evaluation of `_Or<_Pred...>` itself, use `_Lazy<_Or, _Pred...>` 42 // or `disjunction<_Pred...>` directly. 43 template <class... _Args> 44 using _Or _LIBCPP_NODEBUG = typename _OrImpl<sizeof...(_Args) != 0>::template _Result<false_type, _Args...>; 45 46 #if _LIBCPP_STD_VER > 14 47 48 template <class... _Args> 49 struct disjunction : _Or<_Args...> {}; 50 51 template <class... _Args> 52 inline constexpr bool disjunction_v = _Or<_Args...>::value; 53 54 #endif // _LIBCPP_STD_VER > 14 55 56 _LIBCPP_END_NAMESPACE_STD 57 58 #endif // _LIBCPP___TYPE_TRAITS_DISJUNCTION_H 59