1 // Default predicates for internal use -*- C++ -*-
3 // Copyright (C) 2013-2024 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file predefined_ops.h
26 * This is an internal header file, included by other library headers.
27 * You should not attempt to use it directly. @headername{algorithm}
30 #ifndef _GLIBCXX_PREDEFINED_OPS_H
31 #define _GLIBCXX_PREDEFINED_OPS_H 1
33 #include <bits/move.h>
39 struct _Iter_less_iter
41 template<typename _Iterator1
, typename _Iterator2
>
44 operator()(_Iterator1 __it1
, _Iterator2 __it2
) const
45 { return *__it1
< *__it2
; }
49 inline _Iter_less_iter
51 { return _Iter_less_iter(); }
55 #if __cplusplus >= 201103L
56 constexpr _Iter_less_val() = default;
63 _Iter_less_val(_Iter_less_iter
) { }
65 template<typename _Iterator
, typename _Value
>
68 operator()(_Iterator __it
, _Value
& __val
) const
69 { return *__it
< __val
; }
75 { return _Iter_less_val(); }
79 __iter_comp_val(_Iter_less_iter
)
80 { return _Iter_less_val(); }
84 #if __cplusplus >= 201103L
85 constexpr _Val_less_iter() = default;
92 _Val_less_iter(_Iter_less_iter
) { }
94 template<typename _Value
, typename _Iterator
>
97 operator()(_Value
& __val
, _Iterator __it
) const
98 { return __val
< *__it
; }
102 inline _Val_less_iter
104 { return _Val_less_iter(); }
107 inline _Val_less_iter
108 __val_comp_iter(_Iter_less_iter
)
109 { return _Val_less_iter(); }
111 struct _Iter_equal_to_iter
113 template<typename _Iterator1
, typename _Iterator2
>
116 operator()(_Iterator1 __it1
, _Iterator2 __it2
) const
117 { return *__it1
== *__it2
; }
121 inline _Iter_equal_to_iter
122 __iter_equal_to_iter()
123 { return _Iter_equal_to_iter(); }
125 struct _Iter_equal_to_val
127 template<typename _Iterator
, typename _Value
>
130 operator()(_Iterator __it
, _Value
& __val
) const
131 { return *__it
== __val
; }
135 inline _Iter_equal_to_val
136 __iter_equal_to_val()
137 { return _Iter_equal_to_val(); }
140 inline _Iter_equal_to_val
141 __iter_comp_val(_Iter_equal_to_iter
)
142 { return _Iter_equal_to_val(); }
144 template<typename _Compare
>
145 struct _Iter_comp_iter
149 explicit _GLIBCXX14_CONSTEXPR
150 _Iter_comp_iter(_Compare __comp
)
151 : _M_comp(_GLIBCXX_MOVE(__comp
))
154 template<typename _Iterator1
, typename _Iterator2
>
157 operator()(_Iterator1 __it1
, _Iterator2 __it2
)
158 { return bool(_M_comp(*__it1
, *__it2
)); }
161 template<typename _Compare
>
163 inline _Iter_comp_iter
<_Compare
>
164 __iter_comp_iter(_Compare __comp
)
165 { return _Iter_comp_iter
<_Compare
>(_GLIBCXX_MOVE(__comp
)); }
167 template<typename _Compare
>
168 struct _Iter_comp_val
174 _Iter_comp_val(_Compare __comp
)
175 : _M_comp(_GLIBCXX_MOVE(__comp
))
180 _Iter_comp_val(const _Iter_comp_iter
<_Compare
>& __comp
)
181 : _M_comp(__comp
._M_comp
)
184 #if __cplusplus >= 201103L
187 _Iter_comp_val(_Iter_comp_iter
<_Compare
>&& __comp
)
188 : _M_comp(std::move(__comp
._M_comp
))
192 template<typename _Iterator
, typename _Value
>
195 operator()(_Iterator __it
, _Value
& __val
)
196 { return bool(_M_comp(*__it
, __val
)); }
199 template<typename _Compare
>
201 inline _Iter_comp_val
<_Compare
>
202 __iter_comp_val(_Compare __comp
)
203 { return _Iter_comp_val
<_Compare
>(_GLIBCXX_MOVE(__comp
)); }
205 template<typename _Compare
>
207 inline _Iter_comp_val
<_Compare
>
208 __iter_comp_val(_Iter_comp_iter
<_Compare
> __comp
)
209 { return _Iter_comp_val
<_Compare
>(_GLIBCXX_MOVE(__comp
)); }
211 template<typename _Compare
>
212 struct _Val_comp_iter
218 _Val_comp_iter(_Compare __comp
)
219 : _M_comp(_GLIBCXX_MOVE(__comp
))
224 _Val_comp_iter(const _Iter_comp_iter
<_Compare
>& __comp
)
225 : _M_comp(__comp
._M_comp
)
228 #if __cplusplus >= 201103L
231 _Val_comp_iter(_Iter_comp_iter
<_Compare
>&& __comp
)
232 : _M_comp(std::move(__comp
._M_comp
))
236 template<typename _Value
, typename _Iterator
>
239 operator()(_Value
& __val
, _Iterator __it
)
240 { return bool(_M_comp(__val
, *__it
)); }
243 template<typename _Compare
>
245 inline _Val_comp_iter
<_Compare
>
246 __val_comp_iter(_Compare __comp
)
247 { return _Val_comp_iter
<_Compare
>(_GLIBCXX_MOVE(__comp
)); }
249 template<typename _Compare
>
251 inline _Val_comp_iter
<_Compare
>
252 __val_comp_iter(_Iter_comp_iter
<_Compare
> __comp
)
253 { return _Val_comp_iter
<_Compare
>(_GLIBCXX_MOVE(__comp
)); }
255 template<typename _Value
>
256 struct _Iter_equals_val
262 _Iter_equals_val(_Value
& __value
)
266 template<typename _Iterator
>
269 operator()(_Iterator __it
)
270 { return *__it
== _M_value
; }
273 template<typename _Value
>
275 inline _Iter_equals_val
<_Value
>
276 __iter_equals_val(_Value
& __val
)
277 { return _Iter_equals_val
<_Value
>(__val
); }
279 template<typename _Iterator1
>
280 struct _Iter_equals_iter
286 _Iter_equals_iter(_Iterator1 __it1
)
290 template<typename _Iterator2
>
293 operator()(_Iterator2 __it2
)
294 { return *__it2
== *_M_it1
; }
297 template<typename _Iterator
>
299 inline _Iter_equals_iter
<_Iterator
>
300 __iter_comp_iter(_Iter_equal_to_iter
, _Iterator __it
)
301 { return _Iter_equals_iter
<_Iterator
>(__it
); }
303 template<typename _Predicate
>
310 _Iter_pred(_Predicate __pred
)
311 : _M_pred(_GLIBCXX_MOVE(__pred
))
314 template<typename _Iterator
>
317 operator()(_Iterator __it
)
318 { return bool(_M_pred(*__it
)); }
321 template<typename _Predicate
>
323 inline _Iter_pred
<_Predicate
>
324 __pred_iter(_Predicate __pred
)
325 { return _Iter_pred
<_Predicate
>(_GLIBCXX_MOVE(__pred
)); }
327 template<typename _Compare
, typename _Value
>
328 struct _Iter_comp_to_val
334 _Iter_comp_to_val(_Compare __comp
, _Value
& __value
)
335 : _M_comp(_GLIBCXX_MOVE(__comp
)), _M_value(__value
)
338 template<typename _Iterator
>
341 operator()(_Iterator __it
)
342 { return bool(_M_comp(*__it
, _M_value
)); }
345 template<typename _Compare
, typename _Value
>
346 _Iter_comp_to_val
<_Compare
, _Value
>
348 __iter_comp_val(_Compare __comp
, _Value
&__val
)
350 return _Iter_comp_to_val
<_Compare
, _Value
>(_GLIBCXX_MOVE(__comp
), __val
);
353 template<typename _Compare
, typename _Iterator1
>
354 struct _Iter_comp_to_iter
360 _Iter_comp_to_iter(_Compare __comp
, _Iterator1 __it1
)
361 : _M_comp(_GLIBCXX_MOVE(__comp
)), _M_it1(__it1
)
364 template<typename _Iterator2
>
367 operator()(_Iterator2 __it2
)
368 { return bool(_M_comp(*__it2
, *_M_it1
)); }
371 template<typename _Compare
, typename _Iterator
>
373 inline _Iter_comp_to_iter
<_Compare
, _Iterator
>
374 __iter_comp_iter(_Iter_comp_iter
<_Compare
> __comp
, _Iterator __it
)
376 return _Iter_comp_to_iter
<_Compare
, _Iterator
>(
377 _GLIBCXX_MOVE(__comp
._M_comp
), __it
);
380 template<typename _Predicate
>
387 _Iter_negate(_Predicate __pred
)
388 : _M_pred(_GLIBCXX_MOVE(__pred
))
391 template<typename _Iterator
>
394 operator()(_Iterator __it
)
395 { return !bool(_M_pred(*__it
)); }
398 template<typename _Predicate
>
400 inline _Iter_negate
<_Predicate
>
401 __negate(_Iter_pred
<_Predicate
> __pred
)
402 { return _Iter_negate
<_Predicate
>(_GLIBCXX_MOVE(__pred
._M_pred
)); }
405 } // namespace __gnu_cxx