2013-09-27 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / libstdc++-v3 / include / bits / predefined_ops.h
blob30870b7638374947cda300e564de85f3d15171b9
1 // Default predicates for internal use -*- C++ -*-
3 // Copyright (C) 2013 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 bool
41 operator()(_Iterator1 __it1, _Iterator2 __it2) const
42 { return *__it1 < *__it2; }
45 inline _Iter_less_iter
46 __iter_less_iter()
47 { return _Iter_less_iter(); }
49 struct _Iter_less_val
51 template<typename _Iterator, typename _Value>
52 bool
53 operator()(_Iterator __it, _Value& __val) const
54 { return *__it < __val; }
57 inline _Iter_less_val
58 __iter_less_val()
59 { return _Iter_less_val(); }
61 inline _Iter_less_val
62 __iter_comp_val(_Iter_less_iter)
63 { return _Iter_less_val(); }
65 struct _Val_less_iter
67 template<typename _Value, typename _Iterator>
68 bool
69 operator()(_Value& __val, _Iterator __it) const
70 { return __val < *__it; }
73 inline _Val_less_iter
74 __val_less_iter()
75 { return _Val_less_iter(); }
77 inline _Val_less_iter
78 __val_comp_iter(_Iter_less_iter)
79 { return _Val_less_iter(); }
81 struct _Iter_equal_to_iter
83 template<typename _Iterator1, typename _Iterator2>
84 bool
85 operator()(_Iterator1 __it1, _Iterator2 __it2) const
86 { return *__it1 == *__it2; }
89 inline _Iter_equal_to_iter
90 __iter_equal_to_iter()
91 { return _Iter_equal_to_iter(); }
93 struct _Iter_equal_to_val
95 template<typename _Iterator, typename _Value>
96 bool
97 operator()(_Iterator __it, _Value& __val) const
98 { return *__it == __val; }
101 inline _Iter_equal_to_val
102 __iter_equal_to_val()
103 { return _Iter_equal_to_val(); }
105 inline _Iter_equal_to_val
106 __iter_comp_val(_Iter_equal_to_iter)
107 { return _Iter_equal_to_val(); }
109 template<typename _Compare>
110 struct _Iter_comp_iter
112 _Compare _M_comp;
114 _Iter_comp_iter(_Compare __comp)
115 : _M_comp(__comp)
118 template<typename _Iterator1, typename _Iterator2>
119 bool
120 operator()(_Iterator1 __it1, _Iterator2 __it2)
121 { return bool(_M_comp(*__it1, *__it2)); }
124 template<typename _Compare>
125 inline _Iter_comp_iter<_Compare>
126 __iter_comp_iter(_Compare __comp)
127 { return _Iter_comp_iter<_Compare>(__comp); }
129 template<typename _Compare>
130 struct _Iter_comp_val
132 _Compare _M_comp;
134 _Iter_comp_val(_Compare __comp)
135 : _M_comp(__comp)
138 template<typename _Iterator, typename _Value>
139 bool
140 operator()(_Iterator __it, _Value& __val)
141 { return bool(_M_comp(*__it, __val)); }
144 template<typename _Compare>
145 inline _Iter_comp_val<_Compare>
146 __iter_comp_val(_Compare __comp)
147 { return _Iter_comp_val<_Compare>(__comp); }
149 template<typename _Compare>
150 inline _Iter_comp_val<_Compare>
151 __iter_comp_val(_Iter_comp_iter<_Compare> __comp)
152 { return _Iter_comp_val<_Compare>(__comp._M_comp); }
154 template<typename _Compare>
155 struct _Val_comp_iter
157 _Compare _M_comp;
159 _Val_comp_iter(_Compare __comp)
160 : _M_comp(__comp)
163 template<typename _Value, typename _Iterator>
164 bool
165 operator()(_Value& __val, _Iterator __it)
166 { return bool(_M_comp(__val, *__it)); }
169 template<typename _Compare>
170 inline _Val_comp_iter<_Compare>
171 __val_comp_iter(_Compare __comp)
172 { return _Val_comp_iter<_Compare>(__comp); }
174 template<typename _Compare>
175 inline _Val_comp_iter<_Compare>
176 __val_comp_iter(_Iter_comp_iter<_Compare> __comp)
177 { return _Val_comp_iter<_Compare>(__comp._M_comp); }
179 template<typename _Value>
180 struct _Iter_equals_val
182 _Value& _M_value;
184 _Iter_equals_val(_Value& __value)
185 : _M_value(__value)
188 template<typename _Iterator>
189 bool
190 operator()(_Iterator __it)
191 { return *__it == _M_value; }
194 template<typename _Value>
195 inline _Iter_equals_val<_Value>
196 __iter_equals_val(_Value& __val)
197 { return _Iter_equals_val<_Value>(__val); }
199 template<typename _Iterator1>
200 struct _Iter_equals_iter
202 typename std::iterator_traits<_Iterator1>::reference _M_ref;
204 _Iter_equals_iter(_Iterator1 __it1)
205 : _M_ref(*__it1)
208 template<typename _Iterator2>
209 bool
210 operator()(_Iterator2 __it2)
211 { return *__it2 == _M_ref; }
214 template<typename _Iterator>
215 inline _Iter_equals_iter<_Iterator>
216 __iter_comp_iter(_Iter_equal_to_iter, _Iterator __it)
217 { return _Iter_equals_iter<_Iterator>(__it); }
219 template<typename _Predicate>
220 struct _Iter_pred
222 _Predicate _M_pred;
224 _Iter_pred(_Predicate __pred)
225 : _M_pred(__pred)
228 template<typename _Iterator>
229 bool
230 operator()(_Iterator __it)
231 { return bool(_M_pred(*__it)); }
234 template<typename _Predicate>
235 inline _Iter_pred<_Predicate>
236 __pred_iter(_Predicate __pred)
237 { return _Iter_pred<_Predicate>(__pred); }
239 template<typename _Compare, typename _Value>
240 struct _Iter_comp_to_val
242 _Compare _M_comp;
243 _Value& _M_value;
245 _Iter_comp_to_val(_Compare __comp, _Value& __value)
246 : _M_comp(__comp), _M_value(__value)
249 template<typename _Iterator>
250 bool
251 operator()(_Iterator __it)
252 { return bool(_M_comp(*__it, _M_value)); }
255 template<typename _Compare, typename _Value>
256 _Iter_comp_to_val<_Compare, _Value>
257 __iter_comp_val(_Compare __comp, _Value &__val)
258 { return _Iter_comp_to_val<_Compare, _Value>(__comp, __val); }
260 template<typename _Compare, typename _Iterator1>
261 struct _Iter_comp_to_iter
263 _Compare _M_comp;
264 typename std::iterator_traits<_Iterator1>::reference _M_ref;
266 _Iter_comp_to_iter(_Compare __comp, _Iterator1 __it1)
267 : _M_comp(__comp), _M_ref(*__it1)
270 template<typename _Iterator2>
271 bool
272 operator()(_Iterator2 __it2)
273 { return bool(_M_comp(*__it2, _M_ref)); }
276 template<typename _Compare, typename _Iterator>
277 inline _Iter_comp_to_iter<_Compare, _Iterator>
278 __iter_comp_iter(_Iter_comp_iter<_Compare> __comp, _Iterator __it)
279 { return _Iter_comp_to_iter<_Compare, _Iterator>(__comp._M_comp, __it); }
281 template<typename _Predicate>
282 struct _Iter_negate
284 _Predicate _M_pred;
286 _Iter_negate(_Predicate __pred)
287 : _M_pred(__pred)
290 template<typename _Iterator>
291 bool
292 operator()(_Iterator __it)
293 { return !bool(_M_pred(*__it)); }
296 template<typename _Predicate>
297 inline _Iter_negate<_Predicate>
298 __negate(_Iter_pred<_Predicate> __pred)
299 { return _Iter_negate<_Predicate>(__pred._M_pred); }
301 } // namespace __ops
302 } // namespace __gnu_cxx
304 #endif