operations.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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 <__type_traits/predicate_traits.h>
  17. #include <__utility/forward.h>
  18. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  19. # pragma GCC system_header
  20. #endif
  21. _LIBCPP_BEGIN_NAMESPACE_STD
  22. // Arithmetic operations
  23. #if _LIBCPP_STD_VER >= 14
  24. template <class _Tp = void>
  25. #else
  26. template <class _Tp>
  27. #endif
  28. struct _LIBCPP_TEMPLATE_VIS plus
  29. : __binary_function<_Tp, _Tp, _Tp>
  30. {
  31. typedef _Tp __result_type; // used by valarray
  32. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  33. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  34. {return __x + __y;}
  35. };
  36. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(plus);
  37. template <class _Tp>
  38. struct __is_trivial_plus_operation<plus<_Tp>, _Tp, _Tp> : true_type {};
  39. #if _LIBCPP_STD_VER >= 14
  40. template <class _Tp, class _Up>
  41. struct __is_trivial_plus_operation<plus<>, _Tp, _Up> : true_type {};
  42. #endif
  43. #if _LIBCPP_STD_VER >= 14
  44. template <>
  45. struct _LIBCPP_TEMPLATE_VIS plus<void>
  46. {
  47. template <class _T1, class _T2>
  48. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  49. auto operator()(_T1&& __t, _T2&& __u) const
  50. noexcept(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
  51. -> decltype( _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
  52. { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
  53. typedef void is_transparent;
  54. };
  55. #endif
  56. #if _LIBCPP_STD_VER >= 14
  57. template <class _Tp = void>
  58. #else
  59. template <class _Tp>
  60. #endif
  61. struct _LIBCPP_TEMPLATE_VIS minus
  62. : __binary_function<_Tp, _Tp, _Tp>
  63. {
  64. typedef _Tp __result_type; // used by valarray
  65. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  66. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  67. {return __x - __y;}
  68. };
  69. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(minus);
  70. #if _LIBCPP_STD_VER >= 14
  71. template <>
  72. struct _LIBCPP_TEMPLATE_VIS minus<void>
  73. {
  74. template <class _T1, class _T2>
  75. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  76. auto operator()(_T1&& __t, _T2&& __u) const
  77. noexcept(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
  78. -> decltype( _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
  79. { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
  80. typedef void is_transparent;
  81. };
  82. #endif
  83. #if _LIBCPP_STD_VER >= 14
  84. template <class _Tp = void>
  85. #else
  86. template <class _Tp>
  87. #endif
  88. struct _LIBCPP_TEMPLATE_VIS multiplies
  89. : __binary_function<_Tp, _Tp, _Tp>
  90. {
  91. typedef _Tp __result_type; // used by valarray
  92. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  93. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  94. {return __x * __y;}
  95. };
  96. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(multiplies);
  97. #if _LIBCPP_STD_VER >= 14
  98. template <>
  99. struct _LIBCPP_TEMPLATE_VIS multiplies<void>
  100. {
  101. template <class _T1, class _T2>
  102. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  103. auto operator()(_T1&& __t, _T2&& __u) const
  104. noexcept(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
  105. -> decltype( _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
  106. { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
  107. typedef void is_transparent;
  108. };
  109. #endif
  110. #if _LIBCPP_STD_VER >= 14
  111. template <class _Tp = void>
  112. #else
  113. template <class _Tp>
  114. #endif
  115. struct _LIBCPP_TEMPLATE_VIS divides
  116. : __binary_function<_Tp, _Tp, _Tp>
  117. {
  118. typedef _Tp __result_type; // used by valarray
  119. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  120. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  121. {return __x / __y;}
  122. };
  123. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(divides);
  124. #if _LIBCPP_STD_VER >= 14
  125. template <>
  126. struct _LIBCPP_TEMPLATE_VIS divides<void>
  127. {
  128. template <class _T1, class _T2>
  129. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  130. auto operator()(_T1&& __t, _T2&& __u) const
  131. noexcept(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
  132. -> decltype( _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
  133. { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
  134. typedef void is_transparent;
  135. };
  136. #endif
  137. #if _LIBCPP_STD_VER >= 14
  138. template <class _Tp = void>
  139. #else
  140. template <class _Tp>
  141. #endif
  142. struct _LIBCPP_TEMPLATE_VIS modulus
  143. : __binary_function<_Tp, _Tp, _Tp>
  144. {
  145. typedef _Tp __result_type; // used by valarray
  146. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  147. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  148. {return __x % __y;}
  149. };
  150. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(modulus);
  151. #if _LIBCPP_STD_VER >= 14
  152. template <>
  153. struct _LIBCPP_TEMPLATE_VIS modulus<void>
  154. {
  155. template <class _T1, class _T2>
  156. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  157. auto operator()(_T1&& __t, _T2&& __u) const
  158. noexcept(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
  159. -> decltype( _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
  160. { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
  161. typedef void is_transparent;
  162. };
  163. #endif
  164. #if _LIBCPP_STD_VER >= 14
  165. template <class _Tp = void>
  166. #else
  167. template <class _Tp>
  168. #endif
  169. struct _LIBCPP_TEMPLATE_VIS negate
  170. : __unary_function<_Tp, _Tp>
  171. {
  172. typedef _Tp __result_type; // used by valarray
  173. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  174. _Tp operator()(const _Tp& __x) const
  175. {return -__x;}
  176. };
  177. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(negate);
  178. #if _LIBCPP_STD_VER >= 14
  179. template <>
  180. struct _LIBCPP_TEMPLATE_VIS negate<void>
  181. {
  182. template <class _Tp>
  183. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  184. auto operator()(_Tp&& __x) const
  185. noexcept(noexcept(- _VSTD::forward<_Tp>(__x)))
  186. -> decltype( - _VSTD::forward<_Tp>(__x))
  187. { return - _VSTD::forward<_Tp>(__x); }
  188. typedef void is_transparent;
  189. };
  190. #endif
  191. // Bitwise operations
  192. #if _LIBCPP_STD_VER >= 14
  193. template <class _Tp = void>
  194. #else
  195. template <class _Tp>
  196. #endif
  197. struct _LIBCPP_TEMPLATE_VIS bit_and
  198. : __binary_function<_Tp, _Tp, _Tp>
  199. {
  200. typedef _Tp __result_type; // used by valarray
  201. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  202. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  203. {return __x & __y;}
  204. };
  205. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_and);
  206. #if _LIBCPP_STD_VER >= 14
  207. template <>
  208. struct _LIBCPP_TEMPLATE_VIS bit_and<void>
  209. {
  210. template <class _T1, class _T2>
  211. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  212. auto operator()(_T1&& __t, _T2&& __u) const
  213. noexcept(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
  214. -> decltype( _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
  215. { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
  216. typedef void is_transparent;
  217. };
  218. #endif
  219. #if _LIBCPP_STD_VER >= 14
  220. template <class _Tp = void>
  221. struct _LIBCPP_TEMPLATE_VIS bit_not
  222. : __unary_function<_Tp, _Tp>
  223. {
  224. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  225. _Tp operator()(const _Tp& __x) const
  226. {return ~__x;}
  227. };
  228. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_not);
  229. template <>
  230. struct _LIBCPP_TEMPLATE_VIS bit_not<void>
  231. {
  232. template <class _Tp>
  233. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  234. auto operator()(_Tp&& __x) const
  235. noexcept(noexcept(~_VSTD::forward<_Tp>(__x)))
  236. -> decltype( ~_VSTD::forward<_Tp>(__x))
  237. { return ~_VSTD::forward<_Tp>(__x); }
  238. typedef void is_transparent;
  239. };
  240. #endif
  241. #if _LIBCPP_STD_VER >= 14
  242. template <class _Tp = void>
  243. #else
  244. template <class _Tp>
  245. #endif
  246. struct _LIBCPP_TEMPLATE_VIS bit_or
  247. : __binary_function<_Tp, _Tp, _Tp>
  248. {
  249. typedef _Tp __result_type; // used by valarray
  250. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  251. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  252. {return __x | __y;}
  253. };
  254. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_or);
  255. #if _LIBCPP_STD_VER >= 14
  256. template <>
  257. struct _LIBCPP_TEMPLATE_VIS bit_or<void>
  258. {
  259. template <class _T1, class _T2>
  260. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  261. auto operator()(_T1&& __t, _T2&& __u) const
  262. noexcept(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
  263. -> decltype( _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
  264. { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
  265. typedef void is_transparent;
  266. };
  267. #endif
  268. #if _LIBCPP_STD_VER >= 14
  269. template <class _Tp = void>
  270. #else
  271. template <class _Tp>
  272. #endif
  273. struct _LIBCPP_TEMPLATE_VIS bit_xor
  274. : __binary_function<_Tp, _Tp, _Tp>
  275. {
  276. typedef _Tp __result_type; // used by valarray
  277. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  278. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  279. {return __x ^ __y;}
  280. };
  281. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_xor);
  282. #if _LIBCPP_STD_VER >= 14
  283. template <>
  284. struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
  285. {
  286. template <class _T1, class _T2>
  287. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  288. auto operator()(_T1&& __t, _T2&& __u) const
  289. noexcept(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
  290. -> decltype( _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
  291. { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
  292. typedef void is_transparent;
  293. };
  294. #endif
  295. // Comparison operations
  296. #if _LIBCPP_STD_VER >= 14
  297. template <class _Tp = void>
  298. #else
  299. template <class _Tp>
  300. #endif
  301. struct _LIBCPP_TEMPLATE_VIS equal_to
  302. : __binary_function<_Tp, _Tp, bool>
  303. {
  304. typedef bool __result_type; // used by valarray
  305. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  306. bool operator()(const _Tp& __x, const _Tp& __y) const
  307. {return __x == __y;}
  308. };
  309. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(equal_to);
  310. #if _LIBCPP_STD_VER >= 14
  311. template <>
  312. struct _LIBCPP_TEMPLATE_VIS equal_to<void>
  313. {
  314. template <class _T1, class _T2>
  315. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  316. auto operator()(_T1&& __t, _T2&& __u) const
  317. noexcept(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
  318. -> decltype( _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
  319. { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
  320. typedef void is_transparent;
  321. };
  322. #endif
  323. template <class _Tp>
  324. struct __is_trivial_equality_predicate<equal_to<_Tp>, _Tp, _Tp> : true_type {};
  325. #if _LIBCPP_STD_VER >= 14
  326. template <class _Tp>
  327. struct __is_trivial_equality_predicate<equal_to<>, _Tp, _Tp> : true_type {};
  328. #endif
  329. #if _LIBCPP_STD_VER >= 14
  330. template <class _Tp = void>
  331. #else
  332. template <class _Tp>
  333. #endif
  334. struct _LIBCPP_TEMPLATE_VIS not_equal_to
  335. : __binary_function<_Tp, _Tp, bool>
  336. {
  337. typedef bool __result_type; // used by valarray
  338. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  339. bool operator()(const _Tp& __x, const _Tp& __y) const
  340. {return __x != __y;}
  341. };
  342. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(not_equal_to);
  343. #if _LIBCPP_STD_VER >= 14
  344. template <>
  345. struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
  346. {
  347. template <class _T1, class _T2>
  348. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  349. auto operator()(_T1&& __t, _T2&& __u) const
  350. noexcept(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
  351. -> decltype( _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
  352. { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
  353. typedef void is_transparent;
  354. };
  355. #endif
  356. #if _LIBCPP_STD_VER >= 14
  357. template <class _Tp = void>
  358. #else
  359. template <class _Tp>
  360. #endif
  361. struct _LIBCPP_TEMPLATE_VIS less
  362. : __binary_function<_Tp, _Tp, bool>
  363. {
  364. typedef bool __result_type; // used by valarray
  365. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  366. bool operator()(const _Tp& __x, const _Tp& __y) const
  367. {return __x < __y;}
  368. };
  369. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less);
  370. #if _LIBCPP_STD_VER >= 14
  371. template <>
  372. struct _LIBCPP_TEMPLATE_VIS less<void>
  373. {
  374. template <class _T1, class _T2>
  375. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  376. auto operator()(_T1&& __t, _T2&& __u) const
  377. noexcept(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)))
  378. -> decltype( _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))
  379. { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
  380. typedef void is_transparent;
  381. };
  382. #endif
  383. #if _LIBCPP_STD_VER >= 14
  384. template <class _Tp = void>
  385. #else
  386. template <class _Tp>
  387. #endif
  388. struct _LIBCPP_TEMPLATE_VIS less_equal
  389. : __binary_function<_Tp, _Tp, bool>
  390. {
  391. typedef bool __result_type; // used by valarray
  392. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  393. bool operator()(const _Tp& __x, const _Tp& __y) const
  394. {return __x <= __y;}
  395. };
  396. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less_equal);
  397. #if _LIBCPP_STD_VER >= 14
  398. template <>
  399. struct _LIBCPP_TEMPLATE_VIS less_equal<void>
  400. {
  401. template <class _T1, class _T2>
  402. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  403. auto operator()(_T1&& __t, _T2&& __u) const
  404. noexcept(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
  405. -> decltype( _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
  406. { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
  407. typedef void is_transparent;
  408. };
  409. #endif
  410. #if _LIBCPP_STD_VER >= 14
  411. template <class _Tp = void>
  412. #else
  413. template <class _Tp>
  414. #endif
  415. struct _LIBCPP_TEMPLATE_VIS greater_equal
  416. : __binary_function<_Tp, _Tp, bool>
  417. {
  418. typedef bool __result_type; // used by valarray
  419. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  420. bool operator()(const _Tp& __x, const _Tp& __y) const
  421. {return __x >= __y;}
  422. };
  423. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater_equal);
  424. #if _LIBCPP_STD_VER >= 14
  425. template <>
  426. struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
  427. {
  428. template <class _T1, class _T2>
  429. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  430. auto operator()(_T1&& __t, _T2&& __u) const
  431. noexcept(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
  432. -> decltype( _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
  433. { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
  434. typedef void is_transparent;
  435. };
  436. #endif
  437. #if _LIBCPP_STD_VER >= 14
  438. template <class _Tp = void>
  439. #else
  440. template <class _Tp>
  441. #endif
  442. struct _LIBCPP_TEMPLATE_VIS greater
  443. : __binary_function<_Tp, _Tp, bool>
  444. {
  445. typedef bool __result_type; // used by valarray
  446. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  447. bool operator()(const _Tp& __x, const _Tp& __y) const
  448. {return __x > __y;}
  449. };
  450. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater);
  451. #if _LIBCPP_STD_VER >= 14
  452. template <>
  453. struct _LIBCPP_TEMPLATE_VIS greater<void>
  454. {
  455. template <class _T1, class _T2>
  456. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  457. auto operator()(_T1&& __t, _T2&& __u) const
  458. noexcept(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
  459. -> decltype( _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
  460. { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
  461. typedef void is_transparent;
  462. };
  463. #endif
  464. // Logical operations
  465. #if _LIBCPP_STD_VER >= 14
  466. template <class _Tp = void>
  467. #else
  468. template <class _Tp>
  469. #endif
  470. struct _LIBCPP_TEMPLATE_VIS logical_and
  471. : __binary_function<_Tp, _Tp, bool>
  472. {
  473. typedef bool __result_type; // used by valarray
  474. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  475. bool operator()(const _Tp& __x, const _Tp& __y) const
  476. {return __x && __y;}
  477. };
  478. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_and);
  479. #if _LIBCPP_STD_VER >= 14
  480. template <>
  481. struct _LIBCPP_TEMPLATE_VIS logical_and<void>
  482. {
  483. template <class _T1, class _T2>
  484. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  485. auto operator()(_T1&& __t, _T2&& __u) const
  486. noexcept(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
  487. -> decltype( _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
  488. { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
  489. typedef void is_transparent;
  490. };
  491. #endif
  492. #if _LIBCPP_STD_VER >= 14
  493. template <class _Tp = void>
  494. #else
  495. template <class _Tp>
  496. #endif
  497. struct _LIBCPP_TEMPLATE_VIS logical_not
  498. : __unary_function<_Tp, bool>
  499. {
  500. typedef bool __result_type; // used by valarray
  501. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  502. bool operator()(const _Tp& __x) const
  503. {return !__x;}
  504. };
  505. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_not);
  506. #if _LIBCPP_STD_VER >= 14
  507. template <>
  508. struct _LIBCPP_TEMPLATE_VIS logical_not<void>
  509. {
  510. template <class _Tp>
  511. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  512. auto operator()(_Tp&& __x) const
  513. noexcept(noexcept(!_VSTD::forward<_Tp>(__x)))
  514. -> decltype( !_VSTD::forward<_Tp>(__x))
  515. { return !_VSTD::forward<_Tp>(__x); }
  516. typedef void is_transparent;
  517. };
  518. #endif
  519. #if _LIBCPP_STD_VER >= 14
  520. template <class _Tp = void>
  521. #else
  522. template <class _Tp>
  523. #endif
  524. struct _LIBCPP_TEMPLATE_VIS logical_or
  525. : __binary_function<_Tp, _Tp, bool>
  526. {
  527. typedef bool __result_type; // used by valarray
  528. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  529. bool operator()(const _Tp& __x, const _Tp& __y) const
  530. {return __x || __y;}
  531. };
  532. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_or);
  533. #if _LIBCPP_STD_VER >= 14
  534. template <>
  535. struct _LIBCPP_TEMPLATE_VIS logical_or<void>
  536. {
  537. template <class _T1, class _T2>
  538. _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
  539. auto operator()(_T1&& __t, _T2&& __u) const
  540. noexcept(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
  541. -> decltype( _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
  542. { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
  543. typedef void is_transparent;
  544. };
  545. #endif
  546. _LIBCPP_END_NAMESPACE_STD
  547. #endif // _LIBCPP___FUNCTIONAL_OPERATIONS_H