2015-05-29 François Dumont fdumont@gcc.gnu.org>
[official-gcc.git] / libstdc++-v3 / include / bits / predefined_ops.h
blob7178567c9e6e9363fbd37b9f3450c90c8d2b8758
1 // Default predicates for internal use -*- C++ -*-
3 // Copyright (C) 2013-2015 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.
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; }
45 _GLIBCXX14_CONSTEXPR
46 inline _Iter_less_iter
47 __iter_less_iter()
48 { return _Iter_less_iter(); }
50 struct _Iter_less_val
52 template<typename _Iterator, typename _Value>
53 bool
54 operator()(_Iterator __it, _Value& __val) const
55 { return *__it < __val; }
58 inline _Iter_less_val
59 __iter_less_val()
60 { return _Iter_less_val(); }
62 inline _Iter_less_val
63 __iter_comp_val(_Iter_less_iter)
64 { return _Iter_less_val(); }
66 struct _Val_less_iter
68 template<typename _Value, typename _Iterator>
69 bool
70 operator()(_Value& __val, _Iterator __it) const
71 { return __val < *__it; }
74 inline _Val_less_iter
75 __val_less_iter()
76 { return _Val_less_iter(); }
78 inline _Val_less_iter
79 __val_comp_iter(_Iter_less_iter)
80 { return _Val_less_iter(); }
82 struct _Iter_equal_to_iter
84 template<typename _Iterator1, typename _Iterator2>
85 bool
86 operator()(_Iterator1 __it1, _Iterator2 __it2) const
87 { return *__it1 == *__it2; }
90 inline _Iter_equal_to_iter
91 __iter_equal_to_iter()
92 { return _Iter_equal_to_iter(); }
94 struct _Iter_equal_to_val
96 template<typename _Iterator, typename _Value>
97 bool
98 operator()(_Iterator __it, _Value& __val) const
99 { return *__it == __val; }
102 inline _Iter_equal_to_val
103 __iter_equal_to_val()
104 { return _Iter_equal_to_val(); }
106 inline _Iter_equal_to_val
107 __iter_comp_val(_Iter_equal_to_iter)
108 { return _Iter_equal_to_val(); }
110 template<typename _Compare>
111 struct _Iter_comp_iter
113 _Compare _M_comp;
114 _GLIBCXX14_CONSTEXPR
115 _Iter_comp_iter(_Compare __comp)
116 : _M_comp(__comp)
119 template<typename _Iterator1, typename _Iterator2>
120 _GLIBCXX14_CONSTEXPR
121 bool
122 operator()(_Iterator1 __it1, _Iterator2 __it2)
123 { return bool(_M_comp(*__it1, *__it2)); }
126 template<typename _Compare>
127 _GLIBCXX14_CONSTEXPR
128 inline _Iter_comp_iter<_Compare>
129 __iter_comp_iter(_Compare __comp)
130 { return _Iter_comp_iter<_Compare>(__comp); }
132 template<typename _Compare>
133 struct _Iter_comp_val
135 _Compare _M_comp;
137 _Iter_comp_val(_Compare __comp)
138 : _M_comp(__comp)
141 template<typename _Iterator, typename _Value>
142 bool
143 operator()(_Iterator __it, _Value& __val)
144 { return bool(_M_comp(*__it, __val)); }
147 template<typename _Compare>
148 inline _Iter_comp_val<_Compare>
149 __iter_comp_val(_Compare __comp)
150 { return _Iter_comp_val<_Compare>(__comp); }
152 template<typename _Compare>
153 inline _Iter_comp_val<_Compare>
154 __iter_comp_val(_Iter_comp_iter<_Compare> __comp)
155 { return _Iter_comp_val<_Compare>(__comp._M_comp); }
157 template<typename _Compare>
158 struct _Val_comp_iter
160 _Compare _M_comp;
162 _Val_comp_iter(_Compare __comp)
163 : _M_comp(__comp)
166 template<typename _Value, typename _Iterator>
167 bool
168 operator()(_Value& __val, _Iterator __it)
169 { return bool(_M_comp(__val, *__it)); }
172 template<typename _Compare>
173 inline _Val_comp_iter<_Compare>
174 __val_comp_iter(_Compare __comp)
175 { return _Val_comp_iter<_Compare>(__comp); }
177 template<typename _Compare>
178 inline _Val_comp_iter<_Compare>
179 __val_comp_iter(_Iter_comp_iter<_Compare> __comp)
180 { return _Val_comp_iter<_Compare>(__comp._M_comp); }
182 template<typename _Value>
183 struct _Iter_equals_val
185 _Value& _M_value;
187 _Iter_equals_val(_Value& __value)
188 : _M_value(__value)
191 template<typename _Iterator>
192 bool
193 operator()(_Iterator __it)
194 { return *__it == _M_value; }
197 template<typename _Value>
198 inline _Iter_equals_val<_Value>
199 __iter_equals_val(_Value& __val)
200 { return _Iter_equals_val<_Value>(__val); }
202 template<typename _Iterator1>
203 struct _Iter_equals_iter
205 typename std::iterator_traits<_Iterator1>::reference _M_ref;
207 _Iter_equals_iter(_Iterator1 __it1)
208 : _M_ref(*__it1)
211 template<typename _Iterator2>
212 bool
213 operator()(_Iterator2 __it2)
214 { return *__it2 == _M_ref; }
217 template<typename _Iterator>
218 inline _Iter_equals_iter<_Iterator>
219 __iter_comp_iter(_Iter_equal_to_iter, _Iterator __it)
220 { return _Iter_equals_iter<_Iterator>(__it); }
222 template<typename _Predicate>
223 struct _Iter_pred
225 _Predicate _M_pred;
227 _Iter_pred(_Predicate __pred)
228 : _M_pred(__pred)
231 template<typename _Iterator>
232 bool
233 operator()(_Iterator __it)
234 { return bool(_M_pred(*__it)); }
237 template<typename _Predicate>
238 inline _Iter_pred<_Predicate>
239 __pred_iter(_Predicate __pred)
240 { return _Iter_pred<_Predicate>(__pred); }
242 template<typename _Compare, typename _Value>
243 struct _Iter_comp_to_val
245 _Compare _M_comp;
246 _Value& _M_value;
248 _Iter_comp_to_val(_Compare __comp, _Value& __value)
249 : _M_comp(__comp), _M_value(__value)
252 template<typename _Iterator>
253 bool
254 operator()(_Iterator __it)
255 { return bool(_M_comp(*__it, _M_value)); }
258 template<typename _Compare, typename _Value>
259 _Iter_comp_to_val<_Compare, _Value>
260 __iter_comp_val(_Compare __comp, _Value &__val)
261 { return _Iter_comp_to_val<_Compare, _Value>(__comp, __val); }
263 template<typename _Compare, typename _Iterator1>
264 struct _Iter_comp_to_iter
266 _Compare _M_comp;
267 typename std::iterator_traits<_Iterator1>::reference _M_ref;
269 _Iter_comp_to_iter(_Compare __comp, _Iterator1 __it1)
270 : _M_comp(__comp), _M_ref(*__it1)
273 template<typename _Iterator2>
274 bool
275 operator()(_Iterator2 __it2)
276 { return bool(_M_comp(*__it2, _M_ref)); }
279 template<typename _Compare, typename _Iterator>
280 inline _Iter_comp_to_iter<_Compare, _Iterator>
281 __iter_comp_iter(_Iter_comp_iter<_Compare> __comp, _Iterator __it)
282 { return _Iter_comp_to_iter<_Compare, _Iterator>(__comp._M_comp, __it); }
284 template<typename _Predicate>
285 struct _Iter_negate
287 _Predicate _M_pred;
289 _Iter_negate(_Predicate __pred)
290 : _M_pred(__pred)
293 template<typename _Iterator>
294 bool
295 operator()(_Iterator __it)
296 { return !bool(_M_pred(*__it)); }
299 template<typename _Predicate>
300 inline _Iter_negate<_Predicate>
301 __negate(_Iter_pred<_Predicate> __pred)
302 { return _Iter_negate<_Predicate>(__pred._M_pred); }
304 } // namespace __ops
305 } // namespace __gnu_cxx
307 #endif