You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

predefined_ops.h 9.9KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. // Default predicates for internal use -*- C++ -*-
  2. // Copyright (C) 2013-2020 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. namespace __gnu_cxx
  27. {
  28. namespace __ops
  29. {
  30. struct _Iter_less_iter
  31. {
  32. template<typename _Iterator1, typename _Iterator2>
  33. _GLIBCXX14_CONSTEXPR
  34. bool
  35. operator()(_Iterator1 __it1, _Iterator2 __it2) const
  36. { return *__it1 < *__it2; }
  37. };
  38. _GLIBCXX14_CONSTEXPR
  39. inline _Iter_less_iter
  40. __iter_less_iter()
  41. { return _Iter_less_iter(); }
  42. struct _Iter_less_val
  43. {
  44. #if __cplusplus >= 201103L
  45. constexpr _Iter_less_val() = default;
  46. #else
  47. _Iter_less_val() { }
  48. #endif
  49. _GLIBCXX20_CONSTEXPR
  50. explicit
  51. _Iter_less_val(_Iter_less_iter) { }
  52. template<typename _Iterator, typename _Value>
  53. _GLIBCXX20_CONSTEXPR
  54. bool
  55. operator()(_Iterator __it, _Value& __val) const
  56. { return *__it < __val; }
  57. };
  58. _GLIBCXX20_CONSTEXPR
  59. inline _Iter_less_val
  60. __iter_less_val()
  61. { return _Iter_less_val(); }
  62. _GLIBCXX20_CONSTEXPR
  63. inline _Iter_less_val
  64. __iter_comp_val(_Iter_less_iter)
  65. { return _Iter_less_val(); }
  66. struct _Val_less_iter
  67. {
  68. #if __cplusplus >= 201103L
  69. constexpr _Val_less_iter() = default;
  70. #else
  71. _Val_less_iter() { }
  72. #endif
  73. _GLIBCXX20_CONSTEXPR
  74. explicit
  75. _Val_less_iter(_Iter_less_iter) { }
  76. template<typename _Value, typename _Iterator>
  77. _GLIBCXX20_CONSTEXPR
  78. bool
  79. operator()(_Value& __val, _Iterator __it) const
  80. { return __val < *__it; }
  81. };
  82. _GLIBCXX20_CONSTEXPR
  83. inline _Val_less_iter
  84. __val_less_iter()
  85. { return _Val_less_iter(); }
  86. _GLIBCXX20_CONSTEXPR
  87. inline _Val_less_iter
  88. __val_comp_iter(_Iter_less_iter)
  89. { return _Val_less_iter(); }
  90. struct _Iter_equal_to_iter
  91. {
  92. template<typename _Iterator1, typename _Iterator2>
  93. _GLIBCXX20_CONSTEXPR
  94. bool
  95. operator()(_Iterator1 __it1, _Iterator2 __it2) const
  96. { return *__it1 == *__it2; }
  97. };
  98. _GLIBCXX20_CONSTEXPR
  99. inline _Iter_equal_to_iter
  100. __iter_equal_to_iter()
  101. { return _Iter_equal_to_iter(); }
  102. struct _Iter_equal_to_val
  103. {
  104. template<typename _Iterator, typename _Value>
  105. _GLIBCXX20_CONSTEXPR
  106. bool
  107. operator()(_Iterator __it, _Value& __val) const
  108. { return *__it == __val; }
  109. };
  110. _GLIBCXX20_CONSTEXPR
  111. inline _Iter_equal_to_val
  112. __iter_equal_to_val()
  113. { return _Iter_equal_to_val(); }
  114. _GLIBCXX20_CONSTEXPR
  115. inline _Iter_equal_to_val
  116. __iter_comp_val(_Iter_equal_to_iter)
  117. { return _Iter_equal_to_val(); }
  118. template<typename _Compare>
  119. struct _Iter_comp_iter
  120. {
  121. _Compare _M_comp;
  122. explicit _GLIBCXX14_CONSTEXPR
  123. _Iter_comp_iter(_Compare __comp)
  124. : _M_comp(_GLIBCXX_MOVE(__comp))
  125. { }
  126. template<typename _Iterator1, typename _Iterator2>
  127. _GLIBCXX14_CONSTEXPR
  128. bool
  129. operator()(_Iterator1 __it1, _Iterator2 __it2)
  130. { return bool(_M_comp(*__it1, *__it2)); }
  131. };
  132. template<typename _Compare>
  133. _GLIBCXX14_CONSTEXPR
  134. inline _Iter_comp_iter<_Compare>
  135. __iter_comp_iter(_Compare __comp)
  136. { return _Iter_comp_iter<_Compare>(_GLIBCXX_MOVE(__comp)); }
  137. template<typename _Compare>
  138. struct _Iter_comp_val
  139. {
  140. _Compare _M_comp;
  141. _GLIBCXX20_CONSTEXPR
  142. explicit
  143. _Iter_comp_val(_Compare __comp)
  144. : _M_comp(_GLIBCXX_MOVE(__comp))
  145. { }
  146. _GLIBCXX20_CONSTEXPR
  147. explicit
  148. _Iter_comp_val(const _Iter_comp_iter<_Compare>& __comp)
  149. : _M_comp(__comp._M_comp)
  150. { }
  151. #if __cplusplus >= 201103L
  152. _GLIBCXX20_CONSTEXPR
  153. explicit
  154. _Iter_comp_val(_Iter_comp_iter<_Compare>&& __comp)
  155. : _M_comp(std::move(__comp._M_comp))
  156. { }
  157. #endif
  158. template<typename _Iterator, typename _Value>
  159. _GLIBCXX20_CONSTEXPR
  160. bool
  161. operator()(_Iterator __it, _Value& __val)
  162. { return bool(_M_comp(*__it, __val)); }
  163. };
  164. template<typename _Compare>
  165. _GLIBCXX20_CONSTEXPR
  166. inline _Iter_comp_val<_Compare>
  167. __iter_comp_val(_Compare __comp)
  168. { return _Iter_comp_val<_Compare>(_GLIBCXX_MOVE(__comp)); }
  169. template<typename _Compare>
  170. _GLIBCXX20_CONSTEXPR
  171. inline _Iter_comp_val<_Compare>
  172. __iter_comp_val(_Iter_comp_iter<_Compare> __comp)
  173. { return _Iter_comp_val<_Compare>(_GLIBCXX_MOVE(__comp)); }
  174. template<typename _Compare>
  175. struct _Val_comp_iter
  176. {
  177. _Compare _M_comp;
  178. _GLIBCXX20_CONSTEXPR
  179. explicit
  180. _Val_comp_iter(_Compare __comp)
  181. : _M_comp(_GLIBCXX_MOVE(__comp))
  182. { }
  183. _GLIBCXX20_CONSTEXPR
  184. explicit
  185. _Val_comp_iter(const _Iter_comp_iter<_Compare>& __comp)
  186. : _M_comp(__comp._M_comp)
  187. { }
  188. #if __cplusplus >= 201103L
  189. _GLIBCXX20_CONSTEXPR
  190. explicit
  191. _Val_comp_iter(_Iter_comp_iter<_Compare>&& __comp)
  192. : _M_comp(std::move(__comp._M_comp))
  193. { }
  194. #endif
  195. template<typename _Value, typename _Iterator>
  196. _GLIBCXX20_CONSTEXPR
  197. bool
  198. operator()(_Value& __val, _Iterator __it)
  199. { return bool(_M_comp(__val, *__it)); }
  200. };
  201. template<typename _Compare>
  202. _GLIBCXX20_CONSTEXPR
  203. inline _Val_comp_iter<_Compare>
  204. __val_comp_iter(_Compare __comp)
  205. { return _Val_comp_iter<_Compare>(_GLIBCXX_MOVE(__comp)); }
  206. template<typename _Compare>
  207. _GLIBCXX20_CONSTEXPR
  208. inline _Val_comp_iter<_Compare>
  209. __val_comp_iter(_Iter_comp_iter<_Compare> __comp)
  210. { return _Val_comp_iter<_Compare>(_GLIBCXX_MOVE(__comp)); }
  211. template<typename _Value>
  212. struct _Iter_equals_val
  213. {
  214. _Value& _M_value;
  215. _GLIBCXX20_CONSTEXPR
  216. explicit
  217. _Iter_equals_val(_Value& __value)
  218. : _M_value(__value)
  219. { }
  220. template<typename _Iterator>
  221. _GLIBCXX20_CONSTEXPR
  222. bool
  223. operator()(_Iterator __it)
  224. { return *__it == _M_value; }
  225. };
  226. template<typename _Value>
  227. _GLIBCXX20_CONSTEXPR
  228. inline _Iter_equals_val<_Value>
  229. __iter_equals_val(_Value& __val)
  230. { return _Iter_equals_val<_Value>(__val); }
  231. template<typename _Iterator1>
  232. struct _Iter_equals_iter
  233. {
  234. _Iterator1 _M_it1;
  235. _GLIBCXX20_CONSTEXPR
  236. explicit
  237. _Iter_equals_iter(_Iterator1 __it1)
  238. : _M_it1(__it1)
  239. { }
  240. template<typename _Iterator2>
  241. _GLIBCXX20_CONSTEXPR
  242. bool
  243. operator()(_Iterator2 __it2)
  244. { return *__it2 == *_M_it1; }
  245. };
  246. template<typename _Iterator>
  247. _GLIBCXX20_CONSTEXPR
  248. inline _Iter_equals_iter<_Iterator>
  249. __iter_comp_iter(_Iter_equal_to_iter, _Iterator __it)
  250. { return _Iter_equals_iter<_Iterator>(__it); }
  251. template<typename _Predicate>
  252. struct _Iter_pred
  253. {
  254. _Predicate _M_pred;
  255. _GLIBCXX20_CONSTEXPR
  256. explicit
  257. _Iter_pred(_Predicate __pred)
  258. : _M_pred(_GLIBCXX_MOVE(__pred))
  259. { }
  260. template<typename _Iterator>
  261. _GLIBCXX20_CONSTEXPR
  262. bool
  263. operator()(_Iterator __it)
  264. { return bool(_M_pred(*__it)); }
  265. };
  266. template<typename _Predicate>
  267. _GLIBCXX20_CONSTEXPR
  268. inline _Iter_pred<_Predicate>
  269. __pred_iter(_Predicate __pred)
  270. { return _Iter_pred<_Predicate>(_GLIBCXX_MOVE(__pred)); }
  271. template<typename _Compare, typename _Value>
  272. struct _Iter_comp_to_val
  273. {
  274. _Compare _M_comp;
  275. _Value& _M_value;
  276. _GLIBCXX20_CONSTEXPR
  277. _Iter_comp_to_val(_Compare __comp, _Value& __value)
  278. : _M_comp(_GLIBCXX_MOVE(__comp)), _M_value(__value)
  279. { }
  280. template<typename _Iterator>
  281. _GLIBCXX20_CONSTEXPR
  282. bool
  283. operator()(_Iterator __it)
  284. { return bool(_M_comp(*__it, _M_value)); }
  285. };
  286. template<typename _Compare, typename _Value>
  287. _Iter_comp_to_val<_Compare, _Value>
  288. _GLIBCXX20_CONSTEXPR
  289. __iter_comp_val(_Compare __comp, _Value &__val)
  290. {
  291. return _Iter_comp_to_val<_Compare, _Value>(_GLIBCXX_MOVE(__comp), __val);
  292. }
  293. template<typename _Compare, typename _Iterator1>
  294. struct _Iter_comp_to_iter
  295. {
  296. _Compare _M_comp;
  297. _Iterator1 _M_it1;
  298. _GLIBCXX20_CONSTEXPR
  299. _Iter_comp_to_iter(_Compare __comp, _Iterator1 __it1)
  300. : _M_comp(_GLIBCXX_MOVE(__comp)), _M_it1(__it1)
  301. { }
  302. template<typename _Iterator2>
  303. _GLIBCXX20_CONSTEXPR
  304. bool
  305. operator()(_Iterator2 __it2)
  306. { return bool(_M_comp(*__it2, *_M_it1)); }
  307. };
  308. template<typename _Compare, typename _Iterator>
  309. _GLIBCXX20_CONSTEXPR
  310. inline _Iter_comp_to_iter<_Compare, _Iterator>
  311. __iter_comp_iter(_Iter_comp_iter<_Compare> __comp, _Iterator __it)
  312. {
  313. return _Iter_comp_to_iter<_Compare, _Iterator>(
  314. _GLIBCXX_MOVE(__comp._M_comp), __it);
  315. }
  316. template<typename _Predicate>
  317. struct _Iter_negate
  318. {
  319. _Predicate _M_pred;
  320. _GLIBCXX20_CONSTEXPR
  321. explicit
  322. _Iter_negate(_Predicate __pred)
  323. : _M_pred(_GLIBCXX_MOVE(__pred))
  324. { }
  325. template<typename _Iterator>
  326. _GLIBCXX20_CONSTEXPR
  327. bool
  328. operator()(_Iterator __it)
  329. { return !bool(_M_pred(*__it)); }
  330. };
  331. template<typename _Predicate>
  332. _GLIBCXX20_CONSTEXPR
  333. inline _Iter_negate<_Predicate>
  334. __negate(_Iter_pred<_Predicate> __pred)
  335. { return _Iter_negate<_Predicate>(_GLIBCXX_MOVE(__pred._M_pred)); }
  336. } // namespace __ops
  337. } // namespace __gnu_cxx
  338. #endif