1    	// Default predicates for internal use -*- C++ -*-
2    	
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.
10   	
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.
15   	
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.
19   	
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/>.
24   	
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}
28   	 */
29   	
30   	#ifndef _GLIBCXX_PREDEFINED_OPS_H
31   	#define _GLIBCXX_PREDEFINED_OPS_H	1
32   	
33   	namespace __gnu_cxx
34   	{
35   	namespace __ops
36   	{
37   	  struct _Iter_less_iter
38   	  {
39   	    template<typename _Iterator1, typename _Iterator2>
40   	      _GLIBCXX14_CONSTEXPR
41   	      bool
42   	      operator()(_Iterator1 __it1, _Iterator2 __it2) const
43   	      { return *__it1 < *__it2; }
44   	  };
45   	
46   	  _GLIBCXX14_CONSTEXPR
47   	  inline _Iter_less_iter
48   	  __iter_less_iter()
49   	  { return _Iter_less_iter(); }
50   	
51   	  struct _Iter_less_val
52   	  {
53   	#if __cplusplus >= 201103L
54   	    constexpr _Iter_less_val() = default;
55   	#else
56   	    _Iter_less_val() { }
57   	#endif
58   	
59   	    explicit
60   	    _Iter_less_val(_Iter_less_iter) { }
61   	
62   	    template<typename _Iterator, typename _Value>
63   	      bool
64   	      operator()(_Iterator __it, _Value& __val) const
65   	      { return *__it < __val; }
66   	  };
67   	
68   	  inline _Iter_less_val
69   	  __iter_less_val()
70   	  { return _Iter_less_val(); }
71   	
72   	  inline _Iter_less_val
73   	  __iter_comp_val(_Iter_less_iter)
74   	  { return _Iter_less_val(); }
75   	
76   	  struct _Val_less_iter
77   	  {
78   	#if __cplusplus >= 201103L
79   	    constexpr _Val_less_iter() = default;
80   	#else
81   	    _Val_less_iter() { }
82   	#endif
83   	
84   	    explicit
85   	    _Val_less_iter(_Iter_less_iter) { }
86   	
87   	    template<typename _Value, typename _Iterator>
88   	      bool
89   	      operator()(_Value& __val, _Iterator __it) const
90   	      { return __val < *__it; }
91   	  };
92   	
93   	  inline _Val_less_iter
94   	  __val_less_iter()
95   	  { return _Val_less_iter(); }
96   	
97   	  inline _Val_less_iter
98   	  __val_comp_iter(_Iter_less_iter)
99   	  { return _Val_less_iter(); }
100  	
101  	  struct _Iter_equal_to_iter
102  	  {
103  	    template<typename _Iterator1, typename _Iterator2>
104  	      bool
105  	      operator()(_Iterator1 __it1, _Iterator2 __it2) const
106  	      { return *__it1 == *__it2; }
107  	  };
108  	
109  	  inline _Iter_equal_to_iter
110  	  __iter_equal_to_iter()
111  	  { return _Iter_equal_to_iter(); }
112  	
113  	  struct _Iter_equal_to_val
114  	  {
115  	    template<typename _Iterator, typename _Value>
116  	      bool
117  	      operator()(_Iterator __it, _Value& __val) const
118  	      { return *__it == __val; }
119  	  };
120  	
121  	  inline _Iter_equal_to_val
122  	  __iter_equal_to_val()
123  	  { return _Iter_equal_to_val(); }
124  	
125  	  inline _Iter_equal_to_val
126  	  __iter_comp_val(_Iter_equal_to_iter)
127  	  { return _Iter_equal_to_val(); }
128  	
129  	  template<typename _Compare>
130  	    struct _Iter_comp_iter
131  	    {
132  	      _Compare _M_comp;
133  	
134  	      explicit _GLIBCXX14_CONSTEXPR
135  	      _Iter_comp_iter(_Compare __comp)
136  		: _M_comp(_GLIBCXX_MOVE(__comp))
137  	      { }
138  	
139  	      template<typename _Iterator1, typename _Iterator2>
140  	        _GLIBCXX14_CONSTEXPR
141  	        bool
142  	        operator()(_Iterator1 __it1, _Iterator2 __it2)
143  	        { return bool(_M_comp(*__it1, *__it2)); }
144  	    };
145  	
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)); }
151  	
152  	  template<typename _Compare>
153  	    struct _Iter_comp_val
154  	    {
155  	      _Compare _M_comp;
156  	
157  	      explicit
158  	      _Iter_comp_val(_Compare __comp)
159  		: _M_comp(_GLIBCXX_MOVE(__comp))
160  	      { }
161  	
162  	      explicit
163  	      _Iter_comp_val(const _Iter_comp_iter<_Compare>& __comp)
164  		: _M_comp(__comp._M_comp)
165  	      { }
166  	
167  	#if __cplusplus >= 201103L
168  	      explicit
169  	      _Iter_comp_val(_Iter_comp_iter<_Compare>&& __comp)
170  		: _M_comp(std::move(__comp._M_comp))
171  	      { }
172  	#endif
173  	
174  	      template<typename _Iterator, typename _Value>
175  		bool
176  		operator()(_Iterator __it, _Value& __val)
177  		{ return bool(_M_comp(*__it, __val)); }
178  	    };
179  	
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)); }
184  	
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)); }
189  	
190  	  template<typename _Compare>
191  	    struct _Val_comp_iter
192  	    {
193  	      _Compare _M_comp;
194  	
195  	      explicit
196  	      _Val_comp_iter(_Compare __comp)
197  		: _M_comp(_GLIBCXX_MOVE(__comp))
198  	      { }
199  	
200  	      explicit
201  	      _Val_comp_iter(const _Iter_comp_iter<_Compare>& __comp)
202  		: _M_comp(__comp._M_comp)
203  	      { }
204  	
205  	#if __cplusplus >= 201103L
206  	      explicit
207  	      _Val_comp_iter(_Iter_comp_iter<_Compare>&& __comp)
208  		: _M_comp(std::move(__comp._M_comp))
209  	      { }
210  	#endif
211  	
212  	      template<typename _Value, typename _Iterator>
213  		bool
214  		operator()(_Value& __val, _Iterator __it)
215  		{ return bool(_M_comp(__val, *__it)); }
216  	    };
217  	
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)); }
222  	
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)); }
227  	
228  	  template<typename _Value>
229  	    struct _Iter_equals_val
230  	    {
231  	      _Value& _M_value;
232  	
233  	      explicit
234  	      _Iter_equals_val(_Value& __value)
235  		: _M_value(__value)
236  	      { }
237  	
238  	      template<typename _Iterator>
239  		bool
240  		operator()(_Iterator __it)
241  		{ return *__it == _M_value; }
242  	    };
243  	
244  	  template<typename _Value>
245  	    inline _Iter_equals_val<_Value>
246  	    __iter_equals_val(_Value& __val)
247  	    { return _Iter_equals_val<_Value>(__val); }
248  	
249  	  template<typename _Iterator1>
250  	    struct _Iter_equals_iter
251  	    {
252  	      _Iterator1 _M_it1;
253  	
254  	      explicit
255  	      _Iter_equals_iter(_Iterator1 __it1)
256  		: _M_it1(__it1)
257  	      { }
258  	
259  	      template<typename _Iterator2>
260  		bool
261  		operator()(_Iterator2 __it2)
262  		{ return *__it2 == *_M_it1; }
263  	    };
264  	
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); }
269  	
270  	  template<typename _Predicate>
271  	    struct _Iter_pred
272  	    {
273  	      _Predicate _M_pred;
274  	
275  	      explicit
276  	      _Iter_pred(_Predicate __pred)
277  		: _M_pred(_GLIBCXX_MOVE(__pred))
278  	      { }
279  	
280  	      template<typename _Iterator>
281  		bool
282  		operator()(_Iterator __it)
283  		{ return bool(_M_pred(*__it)); }
284  	    };
285  	
286  	  template<typename _Predicate>
287  	    inline _Iter_pred<_Predicate>
288  	    __pred_iter(_Predicate __pred)
289  	    { return _Iter_pred<_Predicate>(_GLIBCXX_MOVE(__pred)); }
290  	
291  	  template<typename _Compare, typename _Value>
292  	    struct _Iter_comp_to_val
293  	    {
294  	      _Compare _M_comp;
295  	      _Value& _M_value;
296  	
297  	      _Iter_comp_to_val(_Compare __comp, _Value& __value)
298  		: _M_comp(_GLIBCXX_MOVE(__comp)), _M_value(__value)
299  	      { }
300  	
301  	      template<typename _Iterator>
302  		bool
303  		operator()(_Iterator __it)
304  		{ return bool(_M_comp(*__it, _M_value)); }
305  	    };
306  	
307  	  template<typename _Compare, typename _Value>
308  	    _Iter_comp_to_val<_Compare, _Value>
309  	    __iter_comp_val(_Compare __comp, _Value &__val)
310  	    {
311  	      return _Iter_comp_to_val<_Compare, _Value>(_GLIBCXX_MOVE(__comp), __val);
312  	    }
313  	
314  	  template<typename _Compare, typename _Iterator1>
315  	    struct _Iter_comp_to_iter
316  	    {
317  	      _Compare _M_comp;
318  	      _Iterator1 _M_it1;
319  	
320  	      _Iter_comp_to_iter(_Compare __comp, _Iterator1 __it1)
321  		: _M_comp(_GLIBCXX_MOVE(__comp)), _M_it1(__it1)
322  	      { }
323  	
324  	      template<typename _Iterator2>
325  		bool
326  		operator()(_Iterator2 __it2)
327  		{ return bool(_M_comp(*__it2, *_M_it1)); }
328  	    };
329  	
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)
333  	    {
334  	      return _Iter_comp_to_iter<_Compare, _Iterator>(
335  		  _GLIBCXX_MOVE(__comp._M_comp), __it);
336  	    }
337  	
338  	  template<typename _Predicate>
339  	    struct _Iter_negate
340  	    {
341  	      _Predicate _M_pred;
342  	
343  	      explicit
344  	      _Iter_negate(_Predicate __pred)
345  		: _M_pred(_GLIBCXX_MOVE(__pred))
346  	      { }
347  	
348  	      template<typename _Iterator>
349  		bool
350  		operator()(_Iterator __it)
351  		{ return !bool(_M_pred(*__it)); }
352  	    };
353  	
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)); }
358  	
359  	} // namespace __ops
360  	} // namespace __gnu_cxx
361  	
362  	#endif
363