predefined_ops.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. // Default predicates for internal use -*- C++ -*-
  2. // Copyright (C) 2013-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file predefined_ops.h
  21. * This is an internal header file, included by other library headers.
  22. * You should not attempt to use it directly. @headername{algorithm}
  23. */
  24. #ifndef _GLIBCXX_PREDEFINED_OPS_H
  25. #define _GLIBCXX_PREDEFINED_OPS_H 1
  26. #include <bits/move.h>
  27. namespace __gnu_cxx
  28. {
  29. namespace __ops
  30. {
  31. struct _Iter_less_iter
  32. {
  33. template<typename _Iterator1, typename _Iterator2>
  34. _GLIBCXX14_CONSTEXPR
  35. bool
  36. operator()(_Iterator1 __it1, _Iterator2 __it2) const
  37. { return *__it1 < *__it2; }
  38. };
  39. _GLIBCXX14_CONSTEXPR
  40. inline _Iter_less_iter
  41. __iter_less_iter()
  42. { return _Iter_less_iter(); }
  43. struct _Iter_less_val
  44. {
  45. #if __cplusplus >= 201103L
  46. constexpr _Iter_less_val() = default;
  47. #else
  48. _Iter_less_val() { }
  49. #endif
  50. _GLIBCXX20_CONSTEXPR
  51. explicit
  52. _Iter_less_val(_Iter_less_iter) { }
  53. template<typename _Iterator, typename _Value>
  54. _GLIBCXX20_CONSTEXPR
  55. bool
  56. operator()(_Iterator __it, _Value& __val) const
  57. { return *__it < __val; }
  58. };
  59. _GLIBCXX20_CONSTEXPR
  60. inline _Iter_less_val
  61. __iter_less_val()
  62. { return _Iter_less_val(); }
  63. _GLIBCXX20_CONSTEXPR
  64. inline _Iter_less_val
  65. __iter_comp_val(_Iter_less_iter)
  66. { return _Iter_less_val(); }
  67. struct _Val_less_iter
  68. {
  69. #if __cplusplus >= 201103L
  70. constexpr _Val_less_iter() = default;
  71. #else
  72. _Val_less_iter() { }
  73. #endif
  74. _GLIBCXX20_CONSTEXPR
  75. explicit
  76. _Val_less_iter(_Iter_less_iter) { }
  77. template<typename _Value, typename _Iterator>
  78. _GLIBCXX20_CONSTEXPR
  79. bool
  80. operator()(_Value& __val, _Iterator __it) const
  81. { return __val < *__it; }
  82. };
  83. _GLIBCXX20_CONSTEXPR
  84. inline _Val_less_iter
  85. __val_less_iter()
  86. { return _Val_less_iter(); }
  87. _GLIBCXX20_CONSTEXPR
  88. inline _Val_less_iter
  89. __val_comp_iter(_Iter_less_iter)
  90. { return _Val_less_iter(); }
  91. struct _Iter_equal_to_iter
  92. {
  93. template<typename _Iterator1, typename _Iterator2>
  94. _GLIBCXX20_CONSTEXPR
  95. bool
  96. operator()(_Iterator1 __it1, _Iterator2 __it2) const
  97. { return *__it1 == *__it2; }
  98. };
  99. _GLIBCXX20_CONSTEXPR
  100. inline _Iter_equal_to_iter
  101. __iter_equal_to_iter()
  102. { return _Iter_equal_to_iter(); }
  103. struct _Iter_equal_to_val
  104. {
  105. template<typename _Iterator, typename _Value>
  106. _GLIBCXX20_CONSTEXPR
  107. bool
  108. operator()(_Iterator __it, _Value& __val) const
  109. { return *__it == __val; }
  110. };
  111. _GLIBCXX20_CONSTEXPR
  112. inline _Iter_equal_to_val
  113. __iter_equal_to_val()
  114. { return _Iter_equal_to_val(); }
  115. _GLIBCXX20_CONSTEXPR
  116. inline _Iter_equal_to_val
  117. __iter_comp_val(_Iter_equal_to_iter)
  118. { return _Iter_equal_to_val(); }
  119. template<typename _Compare>
  120. struct _Iter_comp_iter
  121. {
  122. _Compare _M_comp;
  123. explicit _GLIBCXX14_CONSTEXPR
  124. _Iter_comp_iter(_Compare __comp)
  125. : _M_comp(_GLIBCXX_MOVE(__comp))
  126. { }
  127. template<typename _Iterator1, typename _Iterator2>
  128. _GLIBCXX14_CONSTEXPR
  129. bool
  130. operator()(_Iterator1 __it1, _Iterator2 __it2)
  131. { return bool(_M_comp(*__it1, *__it2)); }
  132. };
  133. template<typename _Compare>
  134. _GLIBCXX14_CONSTEXPR
  135. inline _Iter_comp_iter<_Compare>
  136. __iter_comp_iter(_Compare __comp)
  137. { return _Iter_comp_iter<_Compare>(_GLIBCXX_MOVE(__comp)); }
  138. template<typename _Compare>
  139. struct _Iter_comp_val
  140. {
  141. _Compare _M_comp;
  142. _GLIBCXX20_CONSTEXPR
  143. explicit
  144. _Iter_comp_val(_Compare __comp)
  145. : _M_comp(_GLIBCXX_MOVE(__comp))
  146. { }
  147. _GLIBCXX20_CONSTEXPR
  148. explicit
  149. _Iter_comp_val(const _Iter_comp_iter<_Compare>& __comp)
  150. : _M_comp(__comp._M_comp)
  151. { }
  152. #if __cplusplus >= 201103L
  153. _GLIBCXX20_CONSTEXPR
  154. explicit
  155. _Iter_comp_val(_Iter_comp_iter<_Compare>&& __comp)
  156. : _M_comp(std::move(__comp._M_comp))
  157. { }
  158. #endif
  159. template<typename _Iterator, typename _Value>
  160. _GLIBCXX20_CONSTEXPR
  161. bool
  162. operator()(_Iterator __it, _Value& __val)
  163. { return bool(_M_comp(*__it, __val)); }
  164. };
  165. template<typename _Compare>
  166. _GLIBCXX20_CONSTEXPR
  167. inline _Iter_comp_val<_Compare>
  168. __iter_comp_val(_Compare __comp)
  169. { return _Iter_comp_val<_Compare>(_GLIBCXX_MOVE(__comp)); }
  170. template<typename _Compare>
  171. _GLIBCXX20_CONSTEXPR
  172. inline _Iter_comp_val<_Compare>
  173. __iter_comp_val(_Iter_comp_iter<_Compare> __comp)
  174. { return _Iter_comp_val<_Compare>(_GLIBCXX_MOVE(__comp)); }
  175. template<typename _Compare>
  176. struct _Val_comp_iter
  177. {
  178. _Compare _M_comp;
  179. _GLIBCXX20_CONSTEXPR
  180. explicit
  181. _Val_comp_iter(_Compare __comp)
  182. : _M_comp(_GLIBCXX_MOVE(__comp))
  183. { }
  184. _GLIBCXX20_CONSTEXPR
  185. explicit
  186. _Val_comp_iter(const _Iter_comp_iter<_Compare>& __comp)
  187. : _M_comp(__comp._M_comp)
  188. { }
  189. #if __cplusplus >= 201103L
  190. _GLIBCXX20_CONSTEXPR
  191. explicit
  192. _Val_comp_iter(_Iter_comp_iter<_Compare>&& __comp)
  193. : _M_comp(std::move(__comp._M_comp))
  194. { }
  195. #endif
  196. template<typename _Value, typename _Iterator>
  197. _GLIBCXX20_CONSTEXPR
  198. bool
  199. operator()(_Value& __val, _Iterator __it)
  200. { return bool(_M_comp(__val, *__it)); }
  201. };
  202. template<typename _Compare>
  203. _GLIBCXX20_CONSTEXPR
  204. inline _Val_comp_iter<_Compare>
  205. __val_comp_iter(_Compare __comp)
  206. { return _Val_comp_iter<_Compare>(_GLIBCXX_MOVE(__comp)); }
  207. template<typename _Compare>
  208. _GLIBCXX20_CONSTEXPR
  209. inline _Val_comp_iter<_Compare>
  210. __val_comp_iter(_Iter_comp_iter<_Compare> __comp)
  211. { return _Val_comp_iter<_Compare>(_GLIBCXX_MOVE(__comp)); }
  212. template<typename _Value>
  213. struct _Iter_equals_val
  214. {
  215. _Value& _M_value;
  216. _GLIBCXX20_CONSTEXPR
  217. explicit
  218. _Iter_equals_val(_Value& __value)
  219. : _M_value(__value)
  220. { }
  221. template<typename _Iterator>
  222. _GLIBCXX20_CONSTEXPR
  223. bool
  224. operator()(_Iterator __it)
  225. { return *__it == _M_value; }
  226. };
  227. template<typename _Value>
  228. _GLIBCXX20_CONSTEXPR
  229. inline _Iter_equals_val<_Value>
  230. __iter_equals_val(_Value& __val)
  231. { return _Iter_equals_val<_Value>(__val); }
  232. template<typename _Iterator1>
  233. struct _Iter_equals_iter
  234. {
  235. _Iterator1 _M_it1;
  236. _GLIBCXX20_CONSTEXPR
  237. explicit
  238. _Iter_equals_iter(_Iterator1 __it1)
  239. : _M_it1(__it1)
  240. { }
  241. template<typename _Iterator2>
  242. _GLIBCXX20_CONSTEXPR
  243. bool
  244. operator()(_Iterator2 __it2)
  245. { return *__it2 == *_M_it1; }
  246. };
  247. template<typename _Iterator>
  248. _GLIBCXX20_CONSTEXPR
  249. inline _Iter_equals_iter<_Iterator>
  250. __iter_comp_iter(_Iter_equal_to_iter, _Iterator __it)
  251. { return _Iter_equals_iter<_Iterator>(__it); }
  252. template<typename _Predicate>
  253. struct _Iter_pred
  254. {
  255. _Predicate _M_pred;
  256. _GLIBCXX20_CONSTEXPR
  257. explicit
  258. _Iter_pred(_Predicate __pred)
  259. : _M_pred(_GLIBCXX_MOVE(__pred))
  260. { }
  261. template<typename _Iterator>
  262. _GLIBCXX20_CONSTEXPR
  263. bool
  264. operator()(_Iterator __it)
  265. { return bool(_M_pred(*__it)); }
  266. };
  267. template<typename _Predicate>
  268. _GLIBCXX20_CONSTEXPR
  269. inline _Iter_pred<_Predicate>
  270. __pred_iter(_Predicate __pred)
  271. { return _Iter_pred<_Predicate>(_GLIBCXX_MOVE(__pred)); }
  272. template<typename _Compare, typename _Value>
  273. struct _Iter_comp_to_val
  274. {
  275. _Compare _M_comp;
  276. _Value& _M_value;
  277. _GLIBCXX20_CONSTEXPR
  278. _Iter_comp_to_val(_Compare __comp, _Value& __value)
  279. : _M_comp(_GLIBCXX_MOVE(__comp)), _M_value(__value)
  280. { }
  281. template<typename _Iterator>
  282. _GLIBCXX20_CONSTEXPR
  283. bool
  284. operator()(_Iterator __it)
  285. { return bool(_M_comp(*__it, _M_value)); }
  286. };
  287. template<typename _Compare, typename _Value>
  288. _Iter_comp_to_val<_Compare, _Value>
  289. _GLIBCXX20_CONSTEXPR
  290. __iter_comp_val(_Compare __comp, _Value &__val)
  291. {
  292. return _Iter_comp_to_val<_Compare, _Value>(_GLIBCXX_MOVE(__comp), __val);
  293. }
  294. template<typename _Compare, typename _Iterator1>
  295. struct _Iter_comp_to_iter
  296. {
  297. _Compare _M_comp;
  298. _Iterator1 _M_it1;
  299. _GLIBCXX20_CONSTEXPR
  300. _Iter_comp_to_iter(_Compare __comp, _Iterator1 __it1)
  301. : _M_comp(_GLIBCXX_MOVE(__comp)), _M_it1(__it1)
  302. { }
  303. template<typename _Iterator2>
  304. _GLIBCXX20_CONSTEXPR
  305. bool
  306. operator()(_Iterator2 __it2)
  307. { return bool(_M_comp(*__it2, *_M_it1)); }
  308. };
  309. template<typename _Compare, typename _Iterator>
  310. _GLIBCXX20_CONSTEXPR
  311. inline _Iter_comp_to_iter<_Compare, _Iterator>
  312. __iter_comp_iter(_Iter_comp_iter<_Compare> __comp, _Iterator __it)
  313. {
  314. return _Iter_comp_to_iter<_Compare, _Iterator>(
  315. _GLIBCXX_MOVE(__comp._M_comp), __it);
  316. }
  317. template<typename _Predicate>
  318. struct _Iter_negate
  319. {
  320. _Predicate _M_pred;
  321. _GLIBCXX20_CONSTEXPR
  322. explicit
  323. _Iter_negate(_Predicate __pred)
  324. : _M_pred(_GLIBCXX_MOVE(__pred))
  325. { }
  326. template<typename _Iterator>
  327. _GLIBCXX20_CONSTEXPR
  328. bool
  329. operator()(_Iterator __it)
  330. { return !bool(_M_pred(*__it)); }
  331. };
  332. template<typename _Predicate>
  333. _GLIBCXX20_CONSTEXPR
  334. inline _Iter_negate<_Predicate>
  335. __negate(_Iter_pred<_Predicate> __pred)
  336. { return _Iter_negate<_Predicate>(_GLIBCXX_MOVE(__pred._M_pred)); }
  337. } // namespace __ops
  338. } // namespace __gnu_cxx
  339. #endif