1fe6060f1SDimitry Andric // -*- C++ -*- 2fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 3fe6060f1SDimitry Andric // 4fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 6fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7fe6060f1SDimitry Andric // 8fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 9fe6060f1SDimitry Andric 10fe6060f1SDimitry Andric #ifndef _LIBCPP___FUNCTIONAL_OPERATIONS_H 11fe6060f1SDimitry Andric #define _LIBCPP___FUNCTIONAL_OPERATIONS_H 12fe6060f1SDimitry Andric 13fe6060f1SDimitry Andric #include <__config> 14fe6060f1SDimitry Andric #include <__functional/binary_function.h> 15fe6060f1SDimitry Andric #include <__functional/unary_function.h> 1606c3fb27SDimitry Andric #include <__type_traits/integral_constant.h> 1706c3fb27SDimitry Andric #include <__type_traits/operation_traits.h> 18fe6060f1SDimitry Andric #include <__utility/forward.h> 19fe6060f1SDimitry Andric 20fe6060f1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 21fe6060f1SDimitry Andric # pragma GCC system_header 22fe6060f1SDimitry Andric #endif 23fe6060f1SDimitry Andric 24fe6060f1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 25fe6060f1SDimitry Andric 26fe6060f1SDimitry Andric // Arithmetic operations 27fe6060f1SDimitry Andric 2806c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 29fe6060f1SDimitry Andric template <class _Tp = void> 30fe6060f1SDimitry Andric #else 31fe6060f1SDimitry Andric template <class _Tp> 32fe6060f1SDimitry Andric #endif 33fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS plus 3481ad6265SDimitry Andric : __binary_function<_Tp, _Tp, _Tp> 35fe6060f1SDimitry Andric { 36fe6060f1SDimitry Andric typedef _Tp __result_type; // used by valarray 37*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 38fe6060f1SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 39fe6060f1SDimitry Andric {return __x + __y;} 40fe6060f1SDimitry Andric }; 41bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(plus); 42fe6060f1SDimitry Andric 43*5f757f3fSDimitry Andric // The non-transparent std::plus specialization is only equivalent to a raw plus 44*5f757f3fSDimitry Andric // operator when we don't perform an implicit conversion when calling it. 4506c3fb27SDimitry Andric template <class _Tp> 46*5f757f3fSDimitry Andric struct __desugars_to<__plus_tag, plus<_Tp>, _Tp, _Tp> : true_type {}; 4706c3fb27SDimitry Andric 4806c3fb27SDimitry Andric template <class _Tp, class _Up> 49*5f757f3fSDimitry Andric struct __desugars_to<__plus_tag, plus<void>, _Tp, _Up> : true_type {}; 5006c3fb27SDimitry Andric 5106c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 52fe6060f1SDimitry Andric template <> 53fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS plus<void> 54fe6060f1SDimitry Andric { 55fe6060f1SDimitry Andric template <class _T1, class _T2> 56*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 57fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 58*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) + std::forward<_T2>(__u))) 59*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) + std::forward<_T2>(__u)) 60*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) + std::forward<_T2>(__u); } 61fe6060f1SDimitry Andric typedef void is_transparent; 62fe6060f1SDimitry Andric }; 63fe6060f1SDimitry Andric #endif 64fe6060f1SDimitry Andric 6506c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 66fe6060f1SDimitry Andric template <class _Tp = void> 67fe6060f1SDimitry Andric #else 68fe6060f1SDimitry Andric template <class _Tp> 69fe6060f1SDimitry Andric #endif 70fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS minus 7181ad6265SDimitry Andric : __binary_function<_Tp, _Tp, _Tp> 72fe6060f1SDimitry Andric { 73fe6060f1SDimitry Andric typedef _Tp __result_type; // used by valarray 74*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 75fe6060f1SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 76fe6060f1SDimitry Andric {return __x - __y;} 77fe6060f1SDimitry Andric }; 78bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(minus); 79fe6060f1SDimitry Andric 8006c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 81fe6060f1SDimitry Andric template <> 82fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS minus<void> 83fe6060f1SDimitry Andric { 84fe6060f1SDimitry Andric template <class _T1, class _T2> 85*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 86fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 87*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) - std::forward<_T2>(__u))) 88*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) - std::forward<_T2>(__u)) 89*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) - std::forward<_T2>(__u); } 90fe6060f1SDimitry Andric typedef void is_transparent; 91fe6060f1SDimitry Andric }; 92fe6060f1SDimitry Andric #endif 93fe6060f1SDimitry Andric 9406c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 95fe6060f1SDimitry Andric template <class _Tp = void> 96fe6060f1SDimitry Andric #else 97fe6060f1SDimitry Andric template <class _Tp> 98fe6060f1SDimitry Andric #endif 99fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS multiplies 10081ad6265SDimitry Andric : __binary_function<_Tp, _Tp, _Tp> 101fe6060f1SDimitry Andric { 102fe6060f1SDimitry Andric typedef _Tp __result_type; // used by valarray 103*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 104fe6060f1SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 105fe6060f1SDimitry Andric {return __x * __y;} 106fe6060f1SDimitry Andric }; 107bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(multiplies); 108fe6060f1SDimitry Andric 10906c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 110fe6060f1SDimitry Andric template <> 111fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS multiplies<void> 112fe6060f1SDimitry Andric { 113fe6060f1SDimitry Andric template <class _T1, class _T2> 114*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 115fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 116*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) * std::forward<_T2>(__u))) 117*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) * std::forward<_T2>(__u)) 118*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) * std::forward<_T2>(__u); } 119fe6060f1SDimitry Andric typedef void is_transparent; 120fe6060f1SDimitry Andric }; 121fe6060f1SDimitry Andric #endif 122fe6060f1SDimitry Andric 12306c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 124fe6060f1SDimitry Andric template <class _Tp = void> 125fe6060f1SDimitry Andric #else 126fe6060f1SDimitry Andric template <class _Tp> 127fe6060f1SDimitry Andric #endif 128fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS divides 12981ad6265SDimitry Andric : __binary_function<_Tp, _Tp, _Tp> 130fe6060f1SDimitry Andric { 131fe6060f1SDimitry Andric typedef _Tp __result_type; // used by valarray 132*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 133fe6060f1SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 134fe6060f1SDimitry Andric {return __x / __y;} 135fe6060f1SDimitry Andric }; 136bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(divides); 137fe6060f1SDimitry Andric 13806c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 139fe6060f1SDimitry Andric template <> 140fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS divides<void> 141fe6060f1SDimitry Andric { 142fe6060f1SDimitry Andric template <class _T1, class _T2> 143*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 144fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 145*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) / std::forward<_T2>(__u))) 146*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) / std::forward<_T2>(__u)) 147*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) / std::forward<_T2>(__u); } 148fe6060f1SDimitry Andric typedef void is_transparent; 149fe6060f1SDimitry Andric }; 150fe6060f1SDimitry Andric #endif 151fe6060f1SDimitry Andric 15206c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 153fe6060f1SDimitry Andric template <class _Tp = void> 154fe6060f1SDimitry Andric #else 155fe6060f1SDimitry Andric template <class _Tp> 156fe6060f1SDimitry Andric #endif 157fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS modulus 15881ad6265SDimitry Andric : __binary_function<_Tp, _Tp, _Tp> 159fe6060f1SDimitry Andric { 160fe6060f1SDimitry Andric typedef _Tp __result_type; // used by valarray 161*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 162fe6060f1SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 163fe6060f1SDimitry Andric {return __x % __y;} 164fe6060f1SDimitry Andric }; 165bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(modulus); 166fe6060f1SDimitry Andric 16706c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 168fe6060f1SDimitry Andric template <> 169fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS modulus<void> 170fe6060f1SDimitry Andric { 171fe6060f1SDimitry Andric template <class _T1, class _T2> 172*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 173fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 174*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) % std::forward<_T2>(__u))) 175*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) % std::forward<_T2>(__u)) 176*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) % std::forward<_T2>(__u); } 177fe6060f1SDimitry Andric typedef void is_transparent; 178fe6060f1SDimitry Andric }; 179fe6060f1SDimitry Andric #endif 180fe6060f1SDimitry Andric 18106c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 182fe6060f1SDimitry Andric template <class _Tp = void> 183fe6060f1SDimitry Andric #else 184fe6060f1SDimitry Andric template <class _Tp> 185fe6060f1SDimitry Andric #endif 186fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS negate 18781ad6265SDimitry Andric : __unary_function<_Tp, _Tp> 188fe6060f1SDimitry Andric { 189fe6060f1SDimitry Andric typedef _Tp __result_type; // used by valarray 190*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 191fe6060f1SDimitry Andric _Tp operator()(const _Tp& __x) const 192fe6060f1SDimitry Andric {return -__x;} 193fe6060f1SDimitry Andric }; 194bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(negate); 195fe6060f1SDimitry Andric 19606c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 197fe6060f1SDimitry Andric template <> 198fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS negate<void> 199fe6060f1SDimitry Andric { 200fe6060f1SDimitry Andric template <class _Tp> 201*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 202fe6060f1SDimitry Andric auto operator()(_Tp&& __x) const 203*5f757f3fSDimitry Andric noexcept(noexcept(- std::forward<_Tp>(__x))) 204*5f757f3fSDimitry Andric -> decltype( - std::forward<_Tp>(__x)) 205*5f757f3fSDimitry Andric { return - std::forward<_Tp>(__x); } 206fe6060f1SDimitry Andric typedef void is_transparent; 207fe6060f1SDimitry Andric }; 208fe6060f1SDimitry Andric #endif 209fe6060f1SDimitry Andric 210fe6060f1SDimitry Andric // Bitwise operations 211fe6060f1SDimitry Andric 21206c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 213fe6060f1SDimitry Andric template <class _Tp = void> 214fe6060f1SDimitry Andric #else 215fe6060f1SDimitry Andric template <class _Tp> 216fe6060f1SDimitry Andric #endif 217fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS bit_and 21881ad6265SDimitry Andric : __binary_function<_Tp, _Tp, _Tp> 219fe6060f1SDimitry Andric { 220fe6060f1SDimitry Andric typedef _Tp __result_type; // used by valarray 221*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 222fe6060f1SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 223fe6060f1SDimitry Andric {return __x & __y;} 224fe6060f1SDimitry Andric }; 225bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_and); 226fe6060f1SDimitry Andric 22706c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 228fe6060f1SDimitry Andric template <> 229fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS bit_and<void> 230fe6060f1SDimitry Andric { 231fe6060f1SDimitry Andric template <class _T1, class _T2> 232*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 233fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 234*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) & std::forward<_T2>(__u))) 235*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) & std::forward<_T2>(__u)) 236*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) & std::forward<_T2>(__u); } 237fe6060f1SDimitry Andric typedef void is_transparent; 238fe6060f1SDimitry Andric }; 239fe6060f1SDimitry Andric #endif 240fe6060f1SDimitry Andric 24106c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 242fe6060f1SDimitry Andric template <class _Tp = void> 243fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS bit_not 24481ad6265SDimitry Andric : __unary_function<_Tp, _Tp> 245fe6060f1SDimitry Andric { 246*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 247fe6060f1SDimitry Andric _Tp operator()(const _Tp& __x) const 248fe6060f1SDimitry Andric {return ~__x;} 249fe6060f1SDimitry Andric }; 250bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_not); 251fe6060f1SDimitry Andric 252fe6060f1SDimitry Andric template <> 253fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS bit_not<void> 254fe6060f1SDimitry Andric { 255fe6060f1SDimitry Andric template <class _Tp> 256*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 257fe6060f1SDimitry Andric auto operator()(_Tp&& __x) const 258*5f757f3fSDimitry Andric noexcept(noexcept(~std::forward<_Tp>(__x))) 259*5f757f3fSDimitry Andric -> decltype( ~std::forward<_Tp>(__x)) 260*5f757f3fSDimitry Andric { return ~std::forward<_Tp>(__x); } 261fe6060f1SDimitry Andric typedef void is_transparent; 262fe6060f1SDimitry Andric }; 263fe6060f1SDimitry Andric #endif 264fe6060f1SDimitry Andric 26506c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 266fe6060f1SDimitry Andric template <class _Tp = void> 267fe6060f1SDimitry Andric #else 268fe6060f1SDimitry Andric template <class _Tp> 269fe6060f1SDimitry Andric #endif 270fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS bit_or 27181ad6265SDimitry Andric : __binary_function<_Tp, _Tp, _Tp> 272fe6060f1SDimitry Andric { 273fe6060f1SDimitry Andric typedef _Tp __result_type; // used by valarray 274*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 275fe6060f1SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 276fe6060f1SDimitry Andric {return __x | __y;} 277fe6060f1SDimitry Andric }; 278bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_or); 279fe6060f1SDimitry Andric 28006c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 281fe6060f1SDimitry Andric template <> 282fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS bit_or<void> 283fe6060f1SDimitry Andric { 284fe6060f1SDimitry Andric template <class _T1, class _T2> 285*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 286fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 287*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) | std::forward<_T2>(__u))) 288*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) | std::forward<_T2>(__u)) 289*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) | std::forward<_T2>(__u); } 290fe6060f1SDimitry Andric typedef void is_transparent; 291fe6060f1SDimitry Andric }; 292fe6060f1SDimitry Andric #endif 293fe6060f1SDimitry Andric 29406c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 295fe6060f1SDimitry Andric template <class _Tp = void> 296fe6060f1SDimitry Andric #else 297fe6060f1SDimitry Andric template <class _Tp> 298fe6060f1SDimitry Andric #endif 299fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS bit_xor 30081ad6265SDimitry Andric : __binary_function<_Tp, _Tp, _Tp> 301fe6060f1SDimitry Andric { 302fe6060f1SDimitry Andric typedef _Tp __result_type; // used by valarray 303*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 304fe6060f1SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 305fe6060f1SDimitry Andric {return __x ^ __y;} 306fe6060f1SDimitry Andric }; 307bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_xor); 308fe6060f1SDimitry Andric 30906c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 310fe6060f1SDimitry Andric template <> 311fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS bit_xor<void> 312fe6060f1SDimitry Andric { 313fe6060f1SDimitry Andric template <class _T1, class _T2> 314*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 315fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 316*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) ^ std::forward<_T2>(__u))) 317*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) ^ std::forward<_T2>(__u)) 318*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) ^ std::forward<_T2>(__u); } 319fe6060f1SDimitry Andric typedef void is_transparent; 320fe6060f1SDimitry Andric }; 321fe6060f1SDimitry Andric #endif 322fe6060f1SDimitry Andric 323fe6060f1SDimitry Andric // Comparison operations 324fe6060f1SDimitry Andric 32506c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 326fe6060f1SDimitry Andric template <class _Tp = void> 327fe6060f1SDimitry Andric #else 328fe6060f1SDimitry Andric template <class _Tp> 329fe6060f1SDimitry Andric #endif 330fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS equal_to 33181ad6265SDimitry Andric : __binary_function<_Tp, _Tp, bool> 332fe6060f1SDimitry Andric { 333fe6060f1SDimitry Andric typedef bool __result_type; // used by valarray 334*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 335fe6060f1SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 336fe6060f1SDimitry Andric {return __x == __y;} 337fe6060f1SDimitry Andric }; 338bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(equal_to); 339fe6060f1SDimitry Andric 34006c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 341fe6060f1SDimitry Andric template <> 342fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS equal_to<void> 343fe6060f1SDimitry Andric { 344fe6060f1SDimitry Andric template <class _T1, class _T2> 345*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 346fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 347*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) == std::forward<_T2>(__u))) 348*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) == std::forward<_T2>(__u)) 349*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) == std::forward<_T2>(__u); } 350fe6060f1SDimitry Andric typedef void is_transparent; 351fe6060f1SDimitry Andric }; 352fe6060f1SDimitry Andric #endif 353fe6060f1SDimitry Andric 354*5f757f3fSDimitry Andric // The non-transparent std::equal_to specialization is only equivalent to a raw equality 355*5f757f3fSDimitry Andric // comparison when we don't perform an implicit conversion when calling it. 35606c3fb27SDimitry Andric template <class _Tp> 357*5f757f3fSDimitry Andric struct __desugars_to<__equal_tag, equal_to<_Tp>, _Tp, _Tp> : true_type {}; 35806c3fb27SDimitry Andric 359*5f757f3fSDimitry Andric // In the transparent case, we do not enforce that 360*5f757f3fSDimitry Andric template <class _Tp, class _Up> 361*5f757f3fSDimitry Andric struct __desugars_to<__equal_tag, equal_to<void>, _Tp, _Up> : true_type {}; 36206c3fb27SDimitry Andric 36306c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 364fe6060f1SDimitry Andric template <class _Tp = void> 365fe6060f1SDimitry Andric #else 366fe6060f1SDimitry Andric template <class _Tp> 367fe6060f1SDimitry Andric #endif 368fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS not_equal_to 36981ad6265SDimitry Andric : __binary_function<_Tp, _Tp, bool> 370fe6060f1SDimitry Andric { 371fe6060f1SDimitry Andric typedef bool __result_type; // used by valarray 372*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 373fe6060f1SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 374fe6060f1SDimitry Andric {return __x != __y;} 375fe6060f1SDimitry Andric }; 376bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(not_equal_to); 377fe6060f1SDimitry Andric 37806c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 379fe6060f1SDimitry Andric template <> 380fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS not_equal_to<void> 381fe6060f1SDimitry Andric { 382fe6060f1SDimitry Andric template <class _T1, class _T2> 383*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 384fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 385*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) != std::forward<_T2>(__u))) 386*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) != std::forward<_T2>(__u)) 387*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) != std::forward<_T2>(__u); } 388fe6060f1SDimitry Andric typedef void is_transparent; 389fe6060f1SDimitry Andric }; 390fe6060f1SDimitry Andric #endif 391fe6060f1SDimitry Andric 39206c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 393fe6060f1SDimitry Andric template <class _Tp = void> 394fe6060f1SDimitry Andric #else 395fe6060f1SDimitry Andric template <class _Tp> 396fe6060f1SDimitry Andric #endif 397fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS less 39881ad6265SDimitry Andric : __binary_function<_Tp, _Tp, bool> 399fe6060f1SDimitry Andric { 400fe6060f1SDimitry Andric typedef bool __result_type; // used by valarray 401*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 402fe6060f1SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 403fe6060f1SDimitry Andric {return __x < __y;} 404fe6060f1SDimitry Andric }; 405bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less); 406fe6060f1SDimitry Andric 40706c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 408fe6060f1SDimitry Andric template <> 409fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS less<void> 410fe6060f1SDimitry Andric { 411fe6060f1SDimitry Andric template <class _T1, class _T2> 412*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 413fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 414*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) < std::forward<_T2>(__u))) 415*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) < std::forward<_T2>(__u)) 416*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) < std::forward<_T2>(__u); } 417fe6060f1SDimitry Andric typedef void is_transparent; 418fe6060f1SDimitry Andric }; 419fe6060f1SDimitry Andric #endif 420fe6060f1SDimitry Andric 42106c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 422fe6060f1SDimitry Andric template <class _Tp = void> 423fe6060f1SDimitry Andric #else 424fe6060f1SDimitry Andric template <class _Tp> 425fe6060f1SDimitry Andric #endif 426fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS less_equal 42781ad6265SDimitry Andric : __binary_function<_Tp, _Tp, bool> 428fe6060f1SDimitry Andric { 429fe6060f1SDimitry Andric typedef bool __result_type; // used by valarray 430*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 431fe6060f1SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 432fe6060f1SDimitry Andric {return __x <= __y;} 433fe6060f1SDimitry Andric }; 434bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less_equal); 435fe6060f1SDimitry Andric 43606c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 437fe6060f1SDimitry Andric template <> 438fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS less_equal<void> 439fe6060f1SDimitry Andric { 440fe6060f1SDimitry Andric template <class _T1, class _T2> 441*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 442fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 443*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) <= std::forward<_T2>(__u))) 444*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) <= std::forward<_T2>(__u)) 445*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) <= std::forward<_T2>(__u); } 446fe6060f1SDimitry Andric typedef void is_transparent; 447fe6060f1SDimitry Andric }; 448fe6060f1SDimitry Andric #endif 449fe6060f1SDimitry Andric 45006c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 451fe6060f1SDimitry Andric template <class _Tp = void> 452fe6060f1SDimitry Andric #else 453fe6060f1SDimitry Andric template <class _Tp> 454fe6060f1SDimitry Andric #endif 455fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS greater_equal 45681ad6265SDimitry Andric : __binary_function<_Tp, _Tp, bool> 457fe6060f1SDimitry Andric { 458fe6060f1SDimitry Andric typedef bool __result_type; // used by valarray 459*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 460fe6060f1SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 461fe6060f1SDimitry Andric {return __x >= __y;} 462fe6060f1SDimitry Andric }; 463bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater_equal); 464fe6060f1SDimitry Andric 46506c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 466fe6060f1SDimitry Andric template <> 467fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS greater_equal<void> 468fe6060f1SDimitry Andric { 469fe6060f1SDimitry Andric template <class _T1, class _T2> 470*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 471fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 472*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) >= std::forward<_T2>(__u))) 473*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) >= std::forward<_T2>(__u)) 474*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) >= std::forward<_T2>(__u); } 475fe6060f1SDimitry Andric typedef void is_transparent; 476fe6060f1SDimitry Andric }; 477fe6060f1SDimitry Andric #endif 478fe6060f1SDimitry Andric 47906c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 480fe6060f1SDimitry Andric template <class _Tp = void> 481fe6060f1SDimitry Andric #else 482fe6060f1SDimitry Andric template <class _Tp> 483fe6060f1SDimitry Andric #endif 484fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS greater 48581ad6265SDimitry Andric : __binary_function<_Tp, _Tp, bool> 486fe6060f1SDimitry Andric { 487fe6060f1SDimitry Andric typedef bool __result_type; // used by valarray 488*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 489fe6060f1SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 490fe6060f1SDimitry Andric {return __x > __y;} 491fe6060f1SDimitry Andric }; 492bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater); 493fe6060f1SDimitry Andric 49406c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 495fe6060f1SDimitry Andric template <> 496fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS greater<void> 497fe6060f1SDimitry Andric { 498fe6060f1SDimitry Andric template <class _T1, class _T2> 499*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 500fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 501*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) > std::forward<_T2>(__u))) 502*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) > std::forward<_T2>(__u)) 503*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) > std::forward<_T2>(__u); } 504fe6060f1SDimitry Andric typedef void is_transparent; 505fe6060f1SDimitry Andric }; 506fe6060f1SDimitry Andric #endif 507fe6060f1SDimitry Andric 508fe6060f1SDimitry Andric // Logical operations 509fe6060f1SDimitry Andric 51006c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 511fe6060f1SDimitry Andric template <class _Tp = void> 512fe6060f1SDimitry Andric #else 513fe6060f1SDimitry Andric template <class _Tp> 514fe6060f1SDimitry Andric #endif 515fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS logical_and 51681ad6265SDimitry Andric : __binary_function<_Tp, _Tp, bool> 517fe6060f1SDimitry Andric { 518fe6060f1SDimitry Andric typedef bool __result_type; // used by valarray 519*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 520fe6060f1SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 521fe6060f1SDimitry Andric {return __x && __y;} 522fe6060f1SDimitry Andric }; 523bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_and); 524fe6060f1SDimitry Andric 52506c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 526fe6060f1SDimitry Andric template <> 527fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS logical_and<void> 528fe6060f1SDimitry Andric { 529fe6060f1SDimitry Andric template <class _T1, class _T2> 530*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 531fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 532*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) && std::forward<_T2>(__u))) 533*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) && std::forward<_T2>(__u)) 534*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) && std::forward<_T2>(__u); } 535fe6060f1SDimitry Andric typedef void is_transparent; 536fe6060f1SDimitry Andric }; 537fe6060f1SDimitry Andric #endif 538fe6060f1SDimitry Andric 53906c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 540fe6060f1SDimitry Andric template <class _Tp = void> 541fe6060f1SDimitry Andric #else 542fe6060f1SDimitry Andric template <class _Tp> 543fe6060f1SDimitry Andric #endif 544fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS logical_not 54581ad6265SDimitry Andric : __unary_function<_Tp, bool> 546fe6060f1SDimitry Andric { 547fe6060f1SDimitry Andric typedef bool __result_type; // used by valarray 548*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 549fe6060f1SDimitry Andric bool operator()(const _Tp& __x) const 550fe6060f1SDimitry Andric {return !__x;} 551fe6060f1SDimitry Andric }; 552bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_not); 553fe6060f1SDimitry Andric 55406c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 555fe6060f1SDimitry Andric template <> 556fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS logical_not<void> 557fe6060f1SDimitry Andric { 558fe6060f1SDimitry Andric template <class _Tp> 559*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 560fe6060f1SDimitry Andric auto operator()(_Tp&& __x) const 561*5f757f3fSDimitry Andric noexcept(noexcept(!std::forward<_Tp>(__x))) 562*5f757f3fSDimitry Andric -> decltype( !std::forward<_Tp>(__x)) 563*5f757f3fSDimitry Andric { return !std::forward<_Tp>(__x); } 564fe6060f1SDimitry Andric typedef void is_transparent; 565fe6060f1SDimitry Andric }; 566fe6060f1SDimitry Andric #endif 567fe6060f1SDimitry Andric 56806c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 569fe6060f1SDimitry Andric template <class _Tp = void> 570fe6060f1SDimitry Andric #else 571fe6060f1SDimitry Andric template <class _Tp> 572fe6060f1SDimitry Andric #endif 573fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS logical_or 57481ad6265SDimitry Andric : __binary_function<_Tp, _Tp, bool> 575fe6060f1SDimitry Andric { 576fe6060f1SDimitry Andric typedef bool __result_type; // used by valarray 577*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 578fe6060f1SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 579fe6060f1SDimitry Andric {return __x || __y;} 580fe6060f1SDimitry Andric }; 581bdd1243dSDimitry Andric _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_or); 582fe6060f1SDimitry Andric 58306c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 14 584fe6060f1SDimitry Andric template <> 585fe6060f1SDimitry Andric struct _LIBCPP_TEMPLATE_VIS logical_or<void> 586fe6060f1SDimitry Andric { 587fe6060f1SDimitry Andric template <class _T1, class _T2> 588*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI 589fe6060f1SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 590*5f757f3fSDimitry Andric noexcept(noexcept(std::forward<_T1>(__t) || std::forward<_T2>(__u))) 591*5f757f3fSDimitry Andric -> decltype( std::forward<_T1>(__t) || std::forward<_T2>(__u)) 592*5f757f3fSDimitry Andric { return std::forward<_T1>(__t) || std::forward<_T2>(__u); } 593fe6060f1SDimitry Andric typedef void is_transparent; 594fe6060f1SDimitry Andric }; 595fe6060f1SDimitry Andric #endif 596fe6060f1SDimitry Andric 597fe6060f1SDimitry Andric _LIBCPP_END_NAMESPACE_STD 598fe6060f1SDimitry Andric 599fe6060f1SDimitry Andric #endif // _LIBCPP___FUNCTIONAL_OPERATIONS_H 600