operations.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___FUNCTIONAL_OPERATIONS_H
  10. #define _LIBCPP___FUNCTIONAL_OPERATIONS_H
  11. #include <__config>
  12. #include <__functional/binary_function.h>
  13. #include <__functional/unary_function.h>
  14. #include <__type_traits/integral_constant.h>
  15. #include <__type_traits/operation_traits.h>
  16. #include <__utility/forward.h>
  17. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  18. # pragma GCC system_header
  19. #endif
  20. _LIBCPP_BEGIN_NAMESPACE_STD
  21. // Arithmetic operations
  22. #if _LIBCPP_STD_VER >= 14
  23. template <class _Tp = void>
  24. #else
  25. template <class _Tp>
  26. #endif
  27. struct _LIBCPP_TEMPLATE_VIS plus : __binary_function<_Tp, _Tp, _Tp> {
  28. typedef _Tp __result_type; // used by valarray
  29. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
  30. return __x + __y;
  31. }
  32. };
  33. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(plus);
  34. // The non-transparent std::plus specialization is only equivalent to a raw plus
  35. // operator when we don't perform an implicit conversion when calling it.
  36. template <class _Tp>
  37. struct __desugars_to<__plus_tag, plus<_Tp>, _Tp, _Tp> : true_type {};
  38. template <class _Tp, class _Up>
  39. struct __desugars_to<__plus_tag, plus<void>, _Tp, _Up> : true_type {};
  40. #if _LIBCPP_STD_VER >= 14
  41. template <>
  42. struct _LIBCPP_TEMPLATE_VIS plus<void> {
  43. template <class _T1, class _T2>
  44. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  45. noexcept(noexcept(std::forward<_T1>(__t) + std::forward<_T2>(__u)))
  46. -> decltype(std::forward<_T1>(__t) + std::forward<_T2>(__u)) {
  47. return std::forward<_T1>(__t) + std::forward<_T2>(__u);
  48. }
  49. typedef void is_transparent;
  50. };
  51. #endif
  52. #if _LIBCPP_STD_VER >= 14
  53. template <class _Tp = void>
  54. #else
  55. template <class _Tp>
  56. #endif
  57. struct _LIBCPP_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp> {
  58. typedef _Tp __result_type; // used by valarray
  59. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
  60. return __x - __y;
  61. }
  62. };
  63. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(minus);
  64. #if _LIBCPP_STD_VER >= 14
  65. template <>
  66. struct _LIBCPP_TEMPLATE_VIS minus<void> {
  67. template <class _T1, class _T2>
  68. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  69. noexcept(noexcept(std::forward<_T1>(__t) - std::forward<_T2>(__u)))
  70. -> decltype(std::forward<_T1>(__t) - std::forward<_T2>(__u)) {
  71. return std::forward<_T1>(__t) - std::forward<_T2>(__u);
  72. }
  73. typedef void is_transparent;
  74. };
  75. #endif
  76. #if _LIBCPP_STD_VER >= 14
  77. template <class _Tp = void>
  78. #else
  79. template <class _Tp>
  80. #endif
  81. struct _LIBCPP_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp> {
  82. typedef _Tp __result_type; // used by valarray
  83. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
  84. return __x * __y;
  85. }
  86. };
  87. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(multiplies);
  88. #if _LIBCPP_STD_VER >= 14
  89. template <>
  90. struct _LIBCPP_TEMPLATE_VIS multiplies<void> {
  91. template <class _T1, class _T2>
  92. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  93. noexcept(noexcept(std::forward<_T1>(__t) * std::forward<_T2>(__u)))
  94. -> decltype(std::forward<_T1>(__t) * std::forward<_T2>(__u)) {
  95. return std::forward<_T1>(__t) * std::forward<_T2>(__u);
  96. }
  97. typedef void is_transparent;
  98. };
  99. #endif
  100. #if _LIBCPP_STD_VER >= 14
  101. template <class _Tp = void>
  102. #else
  103. template <class _Tp>
  104. #endif
  105. struct _LIBCPP_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp> {
  106. typedef _Tp __result_type; // used by valarray
  107. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
  108. return __x / __y;
  109. }
  110. };
  111. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(divides);
  112. #if _LIBCPP_STD_VER >= 14
  113. template <>
  114. struct _LIBCPP_TEMPLATE_VIS divides<void> {
  115. template <class _T1, class _T2>
  116. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  117. noexcept(noexcept(std::forward<_T1>(__t) / std::forward<_T2>(__u)))
  118. -> decltype(std::forward<_T1>(__t) / std::forward<_T2>(__u)) {
  119. return std::forward<_T1>(__t) / std::forward<_T2>(__u);
  120. }
  121. typedef void is_transparent;
  122. };
  123. #endif
  124. #if _LIBCPP_STD_VER >= 14
  125. template <class _Tp = void>
  126. #else
  127. template <class _Tp>
  128. #endif
  129. struct _LIBCPP_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp> {
  130. typedef _Tp __result_type; // used by valarray
  131. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
  132. return __x % __y;
  133. }
  134. };
  135. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(modulus);
  136. #if _LIBCPP_STD_VER >= 14
  137. template <>
  138. struct _LIBCPP_TEMPLATE_VIS modulus<void> {
  139. template <class _T1, class _T2>
  140. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  141. noexcept(noexcept(std::forward<_T1>(__t) % std::forward<_T2>(__u)))
  142. -> decltype(std::forward<_T1>(__t) % std::forward<_T2>(__u)) {
  143. return std::forward<_T1>(__t) % std::forward<_T2>(__u);
  144. }
  145. typedef void is_transparent;
  146. };
  147. #endif
  148. #if _LIBCPP_STD_VER >= 14
  149. template <class _Tp = void>
  150. #else
  151. template <class _Tp>
  152. #endif
  153. struct _LIBCPP_TEMPLATE_VIS negate : __unary_function<_Tp, _Tp> {
  154. typedef _Tp __result_type; // used by valarray
  155. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return -__x; }
  156. };
  157. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(negate);
  158. #if _LIBCPP_STD_VER >= 14
  159. template <>
  160. struct _LIBCPP_TEMPLATE_VIS negate<void> {
  161. template <class _Tp>
  162. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_Tp&& __x) const
  163. noexcept(noexcept(-std::forward<_Tp>(__x))) -> decltype(-std::forward<_Tp>(__x)) {
  164. return -std::forward<_Tp>(__x);
  165. }
  166. typedef void is_transparent;
  167. };
  168. #endif
  169. // Bitwise operations
  170. #if _LIBCPP_STD_VER >= 14
  171. template <class _Tp = void>
  172. #else
  173. template <class _Tp>
  174. #endif
  175. struct _LIBCPP_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp> {
  176. typedef _Tp __result_type; // used by valarray
  177. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
  178. return __x & __y;
  179. }
  180. };
  181. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_and);
  182. #if _LIBCPP_STD_VER >= 14
  183. template <>
  184. struct _LIBCPP_TEMPLATE_VIS bit_and<void> {
  185. template <class _T1, class _T2>
  186. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  187. noexcept(noexcept(std::forward<_T1>(__t) & std::forward<_T2>(__u)))
  188. -> decltype(std::forward<_T1>(__t) & std::forward<_T2>(__u)) {
  189. return std::forward<_T1>(__t) & std::forward<_T2>(__u);
  190. }
  191. typedef void is_transparent;
  192. };
  193. #endif
  194. #if _LIBCPP_STD_VER >= 14
  195. template <class _Tp = void>
  196. struct _LIBCPP_TEMPLATE_VIS bit_not : __unary_function<_Tp, _Tp> {
  197. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return ~__x; }
  198. };
  199. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_not);
  200. template <>
  201. struct _LIBCPP_TEMPLATE_VIS bit_not<void> {
  202. template <class _Tp>
  203. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_Tp&& __x) const
  204. noexcept(noexcept(~std::forward<_Tp>(__x))) -> decltype(~std::forward<_Tp>(__x)) {
  205. return ~std::forward<_Tp>(__x);
  206. }
  207. typedef void is_transparent;
  208. };
  209. #endif
  210. #if _LIBCPP_STD_VER >= 14
  211. template <class _Tp = void>
  212. #else
  213. template <class _Tp>
  214. #endif
  215. struct _LIBCPP_TEMPLATE_VIS bit_or : __binary_function<_Tp, _Tp, _Tp> {
  216. typedef _Tp __result_type; // used by valarray
  217. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
  218. return __x | __y;
  219. }
  220. };
  221. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_or);
  222. #if _LIBCPP_STD_VER >= 14
  223. template <>
  224. struct _LIBCPP_TEMPLATE_VIS bit_or<void> {
  225. template <class _T1, class _T2>
  226. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  227. noexcept(noexcept(std::forward<_T1>(__t) | std::forward<_T2>(__u)))
  228. -> decltype(std::forward<_T1>(__t) | std::forward<_T2>(__u)) {
  229. return std::forward<_T1>(__t) | std::forward<_T2>(__u);
  230. }
  231. typedef void is_transparent;
  232. };
  233. #endif
  234. #if _LIBCPP_STD_VER >= 14
  235. template <class _Tp = void>
  236. #else
  237. template <class _Tp>
  238. #endif
  239. struct _LIBCPP_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp> {
  240. typedef _Tp __result_type; // used by valarray
  241. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
  242. return __x ^ __y;
  243. }
  244. };
  245. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_xor);
  246. #if _LIBCPP_STD_VER >= 14
  247. template <>
  248. struct _LIBCPP_TEMPLATE_VIS bit_xor<void> {
  249. template <class _T1, class _T2>
  250. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  251. noexcept(noexcept(std::forward<_T1>(__t) ^ std::forward<_T2>(__u)))
  252. -> decltype(std::forward<_T1>(__t) ^ std::forward<_T2>(__u)) {
  253. return std::forward<_T1>(__t) ^ std::forward<_T2>(__u);
  254. }
  255. typedef void is_transparent;
  256. };
  257. #endif
  258. // Comparison operations
  259. #if _LIBCPP_STD_VER >= 14
  260. template <class _Tp = void>
  261. #else
  262. template <class _Tp>
  263. #endif
  264. struct _LIBCPP_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool> {
  265. typedef bool __result_type; // used by valarray
  266. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
  267. return __x == __y;
  268. }
  269. };
  270. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(equal_to);
  271. #if _LIBCPP_STD_VER >= 14
  272. template <>
  273. struct _LIBCPP_TEMPLATE_VIS equal_to<void> {
  274. template <class _T1, class _T2>
  275. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  276. noexcept(noexcept(std::forward<_T1>(__t) == std::forward<_T2>(__u)))
  277. -> decltype(std::forward<_T1>(__t) == std::forward<_T2>(__u)) {
  278. return std::forward<_T1>(__t) == std::forward<_T2>(__u);
  279. }
  280. typedef void is_transparent;
  281. };
  282. #endif
  283. // The non-transparent std::equal_to specialization is only equivalent to a raw equality
  284. // comparison when we don't perform an implicit conversion when calling it.
  285. template <class _Tp>
  286. struct __desugars_to<__equal_tag, equal_to<_Tp>, _Tp, _Tp> : true_type {};
  287. // In the transparent case, we do not enforce that
  288. template <class _Tp, class _Up>
  289. struct __desugars_to<__equal_tag, equal_to<void>, _Tp, _Up> : true_type {};
  290. #if _LIBCPP_STD_VER >= 14
  291. template <class _Tp = void>
  292. #else
  293. template <class _Tp>
  294. #endif
  295. struct _LIBCPP_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool> {
  296. typedef bool __result_type; // used by valarray
  297. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
  298. return __x != __y;
  299. }
  300. };
  301. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(not_equal_to);
  302. #if _LIBCPP_STD_VER >= 14
  303. template <>
  304. struct _LIBCPP_TEMPLATE_VIS not_equal_to<void> {
  305. template <class _T1, class _T2>
  306. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  307. noexcept(noexcept(std::forward<_T1>(__t) != std::forward<_T2>(__u)))
  308. -> decltype(std::forward<_T1>(__t) != std::forward<_T2>(__u)) {
  309. return std::forward<_T1>(__t) != std::forward<_T2>(__u);
  310. }
  311. typedef void is_transparent;
  312. };
  313. #endif
  314. #if _LIBCPP_STD_VER >= 14
  315. template <class _Tp = void>
  316. #else
  317. template <class _Tp>
  318. #endif
  319. struct _LIBCPP_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool> {
  320. typedef bool __result_type; // used by valarray
  321. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
  322. return __x < __y;
  323. }
  324. };
  325. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less);
  326. #if _LIBCPP_STD_VER >= 14
  327. template <>
  328. struct _LIBCPP_TEMPLATE_VIS less<void> {
  329. template <class _T1, class _T2>
  330. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  331. noexcept(noexcept(std::forward<_T1>(__t) < std::forward<_T2>(__u)))
  332. -> decltype(std::forward<_T1>(__t) < std::forward<_T2>(__u)) {
  333. return std::forward<_T1>(__t) < std::forward<_T2>(__u);
  334. }
  335. typedef void is_transparent;
  336. };
  337. #endif
  338. #if _LIBCPP_STD_VER >= 14
  339. template <class _Tp = void>
  340. #else
  341. template <class _Tp>
  342. #endif
  343. struct _LIBCPP_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool> {
  344. typedef bool __result_type; // used by valarray
  345. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
  346. return __x <= __y;
  347. }
  348. };
  349. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less_equal);
  350. #if _LIBCPP_STD_VER >= 14
  351. template <>
  352. struct _LIBCPP_TEMPLATE_VIS less_equal<void> {
  353. template <class _T1, class _T2>
  354. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  355. noexcept(noexcept(std::forward<_T1>(__t) <= std::forward<_T2>(__u)))
  356. -> decltype(std::forward<_T1>(__t) <= std::forward<_T2>(__u)) {
  357. return std::forward<_T1>(__t) <= std::forward<_T2>(__u);
  358. }
  359. typedef void is_transparent;
  360. };
  361. #endif
  362. #if _LIBCPP_STD_VER >= 14
  363. template <class _Tp = void>
  364. #else
  365. template <class _Tp>
  366. #endif
  367. struct _LIBCPP_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool> {
  368. typedef bool __result_type; // used by valarray
  369. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
  370. return __x >= __y;
  371. }
  372. };
  373. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater_equal);
  374. #if _LIBCPP_STD_VER >= 14
  375. template <>
  376. struct _LIBCPP_TEMPLATE_VIS greater_equal<void> {
  377. template <class _T1, class _T2>
  378. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  379. noexcept(noexcept(std::forward<_T1>(__t) >= std::forward<_T2>(__u)))
  380. -> decltype(std::forward<_T1>(__t) >= std::forward<_T2>(__u)) {
  381. return std::forward<_T1>(__t) >= std::forward<_T2>(__u);
  382. }
  383. typedef void is_transparent;
  384. };
  385. #endif
  386. #if _LIBCPP_STD_VER >= 14
  387. template <class _Tp = void>
  388. #else
  389. template <class _Tp>
  390. #endif
  391. struct _LIBCPP_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool> {
  392. typedef bool __result_type; // used by valarray
  393. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
  394. return __x > __y;
  395. }
  396. };
  397. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater);
  398. #if _LIBCPP_STD_VER >= 14
  399. template <>
  400. struct _LIBCPP_TEMPLATE_VIS greater<void> {
  401. template <class _T1, class _T2>
  402. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  403. noexcept(noexcept(std::forward<_T1>(__t) > std::forward<_T2>(__u)))
  404. -> decltype(std::forward<_T1>(__t) > std::forward<_T2>(__u)) {
  405. return std::forward<_T1>(__t) > std::forward<_T2>(__u);
  406. }
  407. typedef void is_transparent;
  408. };
  409. #endif
  410. // Logical operations
  411. #if _LIBCPP_STD_VER >= 14
  412. template <class _Tp = void>
  413. #else
  414. template <class _Tp>
  415. #endif
  416. struct _LIBCPP_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool> {
  417. typedef bool __result_type; // used by valarray
  418. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
  419. return __x && __y;
  420. }
  421. };
  422. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_and);
  423. #if _LIBCPP_STD_VER >= 14
  424. template <>
  425. struct _LIBCPP_TEMPLATE_VIS logical_and<void> {
  426. template <class _T1, class _T2>
  427. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  428. noexcept(noexcept(std::forward<_T1>(__t) && std::forward<_T2>(__u)))
  429. -> decltype(std::forward<_T1>(__t) && std::forward<_T2>(__u)) {
  430. return std::forward<_T1>(__t) && std::forward<_T2>(__u);
  431. }
  432. typedef void is_transparent;
  433. };
  434. #endif
  435. #if _LIBCPP_STD_VER >= 14
  436. template <class _Tp = void>
  437. #else
  438. template <class _Tp>
  439. #endif
  440. struct _LIBCPP_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool> {
  441. typedef bool __result_type; // used by valarray
  442. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x) const { return !__x; }
  443. };
  444. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_not);
  445. #if _LIBCPP_STD_VER >= 14
  446. template <>
  447. struct _LIBCPP_TEMPLATE_VIS logical_not<void> {
  448. template <class _Tp>
  449. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_Tp&& __x) const
  450. noexcept(noexcept(!std::forward<_Tp>(__x))) -> decltype(!std::forward<_Tp>(__x)) {
  451. return !std::forward<_Tp>(__x);
  452. }
  453. typedef void is_transparent;
  454. };
  455. #endif
  456. #if _LIBCPP_STD_VER >= 14
  457. template <class _Tp = void>
  458. #else
  459. template <class _Tp>
  460. #endif
  461. struct _LIBCPP_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool> {
  462. typedef bool __result_type; // used by valarray
  463. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
  464. return __x || __y;
  465. }
  466. };
  467. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_or);
  468. #if _LIBCPP_STD_VER >= 14
  469. template <>
  470. struct _LIBCPP_TEMPLATE_VIS logical_or<void> {
  471. template <class _T1, class _T2>
  472. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
  473. noexcept(noexcept(std::forward<_T1>(__t) || std::forward<_T2>(__u)))
  474. -> decltype(std::forward<_T1>(__t) || std::forward<_T2>(__u)) {
  475. return std::forward<_T1>(__t) || std::forward<_T2>(__u);
  476. }
  477. typedef void is_transparent;
  478. };
  479. #endif
  480. _LIBCPP_END_NAMESPACE_STD
  481. #endif // _LIBCPP___FUNCTIONAL_OPERATIONS_H