PR debug/81307
[official-gcc.git] / libstdc++-v3 / include / bits / predefined_ops.h
blob0624a38a1ba9f096468317ff2824d239d5cce401
1 // Default predicates for internal use -*- C++ -*-
3 // Copyright (C) 2013-2017 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
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 namespace __gnu_cxx
35 namespace __ops
37 struct _Iter_less_iter
39 template<typename _Iterator1, typename _Iterator2>
40 _GLIBCXX14_CONSTEXPR
41 bool
42 operator()(_Iterator1 __it1, _Iterator2 __it2) const
43 { return *__it1 < *__it2; }
46 _GLIBCXX14_CONSTEXPR
47 inline _Iter_less_iter
48 __iter_less_iter()
49 { return _Iter_less_iter(); }
51 struct _Iter_less_val
53 #if __cplusplus >= 201103L
54 constexpr _Iter_less_val() = default;
55 #else
56 _Iter_less_val() { }
57 #endif
59 explicit
60 _Iter_less_val(_Iter_less_iter) { }
62 template<typename _Iterator, typename _Value>
63 bool
64 operator()(_Iterator __it, _Value& __val) const
65 { return *__it < __val; }
68 inline _Iter_less_val
69 __iter_less_val()
70 { return _Iter_less_val(); }
72 inline _Iter_less_val
73 __iter_comp_val(_Iter_less_iter)
74 { return _Iter_less_val(); }
76 struct _Val_less_iter
78 #if __cplusplus >= 201103L
79 constexpr _Val_less_iter() = default;
80 #else
81 _Val_less_iter() { }
82 #endif
84 explicit
85 _Val_less_iter(_Iter_less_iter) { }
87 template<typename _Value, typename _Iterator>
88 bool
89 operator()(_Value& __val, _Iterator __it) const
90 { return __val < *__it; }
93 inline _Val_less_iter
94 __val_less_iter()
95 { return _Val_less_iter(); }
97 inline _Val_less_iter
98 __val_comp_iter(_Iter_less_iter)
99 { return _Val_less_iter(); }
101 struct _Iter_equal_to_iter
103 template<typename _Iterator1, typename _Iterator2>
104 bool
105 operator()(_Iterator1 __it1, _Iterator2 __it2) const
106 { return *__it1 == *__it2; }
109 inline _Iter_equal_to_iter
110 __iter_equal_to_iter()
111 { return _Iter_equal_to_iter(); }
113 struct _Iter_equal_to_val
115 template<typename _Iterator, typename _Value>
116 bool
117 operator()(_Iterator __it, _Value& __val) const
118 { return *__it == __val; }
121 inline _Iter_equal_to_val
122 __iter_equal_to_val()
123 { return _Iter_equal_to_val(); }
125 inline _Iter_equal_to_val
126 __iter_comp_val(_Iter_equal_to_iter)
127 { return _Iter_equal_to_val(); }
129 template<typename _Compare>
130 struct _Iter_comp_iter
132 _Compare _M_comp;
134 explicit _GLIBCXX14_CONSTEXPR
135 _Iter_comp_iter(_Compare __comp)
136 : _M_comp(_GLIBCXX_MOVE(__comp))
139 template<typename _Iterator1, typename _Iterator2>
140 _GLIBCXX14_CONSTEXPR
141 bool
142 operator()(_Iterator1 __it1, _Iterator2 __it2)
143 { return bool(_M_comp(*__it1, *__it2)); }
146 template<typename _Compare>
147 _GLIBCXX14_CONSTEXPR
148 inline _Iter_comp_iter<_Compare>
149 __iter_comp_iter(_Compare __comp)
150 { return _Iter_comp_iter<_Compare>(_GLIBCXX_MOVE(__comp)); }
152 template<typename _Compare>
153 struct _Iter_comp_val
155 _Compare _M_comp;
157 explicit
158 _Iter_comp_val(_Compare __comp)
159 : _M_comp(_GLIBCXX_MOVE(__comp))
162 explicit
163 _Iter_comp_val(const _Iter_comp_iter<_Compare>& __comp)
164 : _M_comp(__comp._M_comp)
167 #if __cplusplus >= 201103L
168 explicit
169 _Iter_comp_val(_Iter_comp_iter<_Compare>&& __comp)
170 : _M_comp(std::move(__comp._M_comp))
172 #endif
174 template<typename _Iterator, typename _Value>
175 bool
176 operator()(_Iterator __it, _Value& __val)
177 { return bool(_M_comp(*__it, __val)); }
180 template<typename _Compare>
181 inline _Iter_comp_val<_Compare>
182 __iter_comp_val(_Compare __comp)
183 { return _Iter_comp_val<_Compare>(_GLIBCXX_MOVE(__comp)); }
185 template<typename _Compare>
186 inline _Iter_comp_val<_Compare>
187 __iter_comp_val(_Iter_comp_iter<_Compare> __comp)
188 { return _Iter_comp_val<_Compare>(_GLIBCXX_MOVE(__comp)); }
190 template<typename _Compare>
191 struct _Val_comp_iter
193 _Compare _M_comp;
195 explicit
196 _Val_comp_iter(_Compare __comp)
197 : _M_comp(_GLIBCXX_MOVE(__comp))
200 explicit
201 _Val_comp_iter(const _Iter_comp_iter<_Compare>& __comp)
202 : _M_comp(__comp._M_comp)
205 #if __cplusplus >= 201103L
206 explicit
207 _Val_comp_iter(_Iter_comp_iter<_Compare>&& __comp)
208 : _M_comp(std::move(__comp._M_comp))
210 #endif
212 template<typename _Value, typename _Iterator>
213 bool
214 operator()(_Value& __val, _Iterator __it)
215 { return bool(_M_comp(__val, *__it)); }
218 template<typename _Compare>
219 inline _Val_comp_iter<_Compare>
220 __val_comp_iter(_Compare __comp)
221 { return _Val_comp_iter<_Compare>(_GLIBCXX_MOVE(__comp)); }
223 template<typename _Compare>
224 inline _Val_comp_iter<_Compare>
225 __val_comp_iter(_Iter_comp_iter<_Compare> __comp)
226 { return _Val_comp_iter<_Compare>(_GLIBCXX_MOVE(__comp)); }
228 template<typename _Value>
229 struct _Iter_equals_val
231 _Value& _M_value;
233 explicit
234 _Iter_equals_val(_Value& __value)
235 : _M_value(__value)
238 template<typename _Iterator>
239 bool
240 operator()(_Iterator __it)
241 { return *__it == _M_value; }
244 template<typename _Value>
245 inline _Iter_equals_val<_Value>
246 __iter_equals_val(_Value& __val)
247 { return _Iter_equals_val<_Value>(__val); }
249 template<typename _Iterator1>
250 struct _Iter_equals_iter
252 _Iterator1 _M_it1;
254 explicit
255 _Iter_equals_iter(_Iterator1 __it1)
256 : _M_it1(__it1)
259 template<typename _Iterator2>
260 bool
261 operator()(_Iterator2 __it2)
262 { return *__it2 == *_M_it1; }
265 template<typename _Iterator>
266 inline _Iter_equals_iter<_Iterator>
267 __iter_comp_iter(_Iter_equal_to_iter, _Iterator __it)
268 { return _Iter_equals_iter<_Iterator>(__it); }
270 template<typename _Predicate>
271 struct _Iter_pred
273 _Predicate _M_pred;
275 explicit
276 _Iter_pred(_Predicate __pred)
277 : _M_pred(_GLIBCXX_MOVE(__pred))
280 template<typename _Iterator>
281 bool
282 operator()(_Iterator __it)
283 { return bool(_M_pred(*__it)); }
286 template<typename _Predicate>
287 inline _Iter_pred<_Predicate>
288 __pred_iter(_Predicate __pred)
289 { return _Iter_pred<_Predicate>(_GLIBCXX_MOVE(__pred)); }
291 template<typename _Compare, typename _Value>
292 struct _Iter_comp_to_val
294 _Compare _M_comp;
295 _Value& _M_value;
297 _Iter_comp_to_val(_Compare __comp, _Value& __value)
298 : _M_comp(_GLIBCXX_MOVE(__comp)), _M_value(__value)
301 template<typename _Iterator>
302 bool
303 operator()(_Iterator __it)
304 { return bool(_M_comp(*__it, _M_value)); }
307 template<typename _Compare, typename _Value>
308 _Iter_comp_to_val<_Compare, _Value>
309 __iter_comp_val(_Compare __comp, _Value &__val)
311 return _Iter_comp_to_val<_Compare, _Value>(_GLIBCXX_MOVE(__comp), __val);
314 template<typename _Compare, typename _Iterator1>
315 struct _Iter_comp_to_iter
317 _Compare _M_comp;
318 _Iterator1 _M_it1;
320 _Iter_comp_to_iter(_Compare __comp, _Iterator1 __it1)
321 : _M_comp(_GLIBCXX_MOVE(__comp)), _M_it1(__it1)
324 template<typename _Iterator2>
325 bool
326 operator()(_Iterator2 __it2)
327 { return bool(_M_comp(*__it2, *_M_it1)); }
330 template<typename _Compare, typename _Iterator>
331 inline _Iter_comp_to_iter<_Compare, _Iterator>
332 __iter_comp_iter(_Iter_comp_iter<_Compare> __comp, _Iterator __it)
334 return _Iter_comp_to_iter<_Compare, _Iterator>(
335 _GLIBCXX_MOVE(__comp._M_comp), __it);
338 template<typename _Predicate>
339 struct _Iter_negate
341 _Predicate _M_pred;
343 explicit
344 _Iter_negate(_Predicate __pred)
345 : _M_pred(_GLIBCXX_MOVE(__pred))
348 template<typename _Iterator>
349 bool
350 operator()(_Iterator __it)
351 { return !bool(_M_pred(*__it)); }
354 template<typename _Predicate>
355 inline _Iter_negate<_Predicate>
356 __negate(_Iter_pred<_Predicate> __pred)
357 { return _Iter_negate<_Predicate>(_GLIBCXX_MOVE(__pred._M_pred)); }
359 } // namespace __ops
360 } // namespace __gnu_cxx
362 #endif