predefined_ops.h 8.9 KB

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