xref: /dflybsd-src/contrib/gcc-8.0/libstdc++-v3/include/bits/stl_function.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj // Functor implementations -*- C++ -*-
2*38fd1498Szrj 
3*38fd1498Szrj // Copyright (C) 2001-2018 Free Software Foundation, Inc.
4*38fd1498Szrj //
5*38fd1498Szrj // This file is part of the GNU ISO C++ Library.  This library is free
6*38fd1498Szrj // software; you can redistribute it and/or modify it under the
7*38fd1498Szrj // terms of the GNU General Public License as published by the
8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj // any later version.
10*38fd1498Szrj 
11*38fd1498Szrj // This library is distributed in the hope that it will be useful,
12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*38fd1498Szrj // GNU General Public License for more details.
15*38fd1498Szrj 
16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj // 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj 
20*38fd1498Szrj // You should have received a copy of the GNU General Public License and
21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*38fd1498Szrj // <http://www.gnu.org/licenses/>.
24*38fd1498Szrj 
25*38fd1498Szrj /*
26*38fd1498Szrj  *
27*38fd1498Szrj  * Copyright (c) 1994
28*38fd1498Szrj  * Hewlett-Packard Company
29*38fd1498Szrj  *
30*38fd1498Szrj  * Permission to use, copy, modify, distribute and sell this software
31*38fd1498Szrj  * and its documentation for any purpose is hereby granted without fee,
32*38fd1498Szrj  * provided that the above copyright notice appear in all copies and
33*38fd1498Szrj  * that both that copyright notice and this permission notice appear
34*38fd1498Szrj  * in supporting documentation.  Hewlett-Packard Company makes no
35*38fd1498Szrj  * representations about the suitability of this software for any
36*38fd1498Szrj  * purpose.  It is provided "as is" without express or implied warranty.
37*38fd1498Szrj  *
38*38fd1498Szrj  *
39*38fd1498Szrj  * Copyright (c) 1996-1998
40*38fd1498Szrj  * Silicon Graphics Computer Systems, Inc.
41*38fd1498Szrj  *
42*38fd1498Szrj  * Permission to use, copy, modify, distribute and sell this software
43*38fd1498Szrj  * and its documentation for any purpose is hereby granted without fee,
44*38fd1498Szrj  * provided that the above copyright notice appear in all copies and
45*38fd1498Szrj  * that both that copyright notice and this permission notice appear
46*38fd1498Szrj  * in supporting documentation.  Silicon Graphics makes no
47*38fd1498Szrj  * representations about the suitability of this software for any
48*38fd1498Szrj  * purpose.  It is provided "as is" without express or implied warranty.
49*38fd1498Szrj  */
50*38fd1498Szrj 
51*38fd1498Szrj /** @file bits/stl_function.h
52*38fd1498Szrj  *  This is an internal header file, included by other library headers.
53*38fd1498Szrj  *  Do not attempt to use it directly. @headername{functional}
54*38fd1498Szrj  */
55*38fd1498Szrj 
56*38fd1498Szrj #ifndef _STL_FUNCTION_H
57*38fd1498Szrj #define _STL_FUNCTION_H 1
58*38fd1498Szrj 
59*38fd1498Szrj #if __cplusplus > 201103L
60*38fd1498Szrj #include <bits/move.h>
61*38fd1498Szrj #endif
62*38fd1498Szrj 
_GLIBCXX_VISIBILITY(default)63*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
64*38fd1498Szrj {
65*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
66*38fd1498Szrj 
67*38fd1498Szrj   // 20.3.1 base classes
68*38fd1498Szrj   /** @defgroup functors Function Objects
69*38fd1498Szrj    * @ingroup utilities
70*38fd1498Szrj    *
71*38fd1498Szrj    *  Function objects, or @e functors, are objects with an @c operator()
72*38fd1498Szrj    *  defined and accessible.  They can be passed as arguments to algorithm
73*38fd1498Szrj    *  templates and used in place of a function pointer.  Not only is the
74*38fd1498Szrj    *  resulting expressiveness of the library increased, but the generated
75*38fd1498Szrj    *  code can be more efficient than what you might write by hand.  When we
76*38fd1498Szrj    *  refer to @a functors, then, generally we include function pointers in
77*38fd1498Szrj    *  the description as well.
78*38fd1498Szrj    *
79*38fd1498Szrj    *  Often, functors are only created as temporaries passed to algorithm
80*38fd1498Szrj    *  calls, rather than being created as named variables.
81*38fd1498Szrj    *
82*38fd1498Szrj    *  Two examples taken from the standard itself follow.  To perform a
83*38fd1498Szrj    *  by-element addition of two vectors @c a and @c b containing @c double,
84*38fd1498Szrj    *  and put the result in @c a, use
85*38fd1498Szrj    *  \code
86*38fd1498Szrj    *  transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
87*38fd1498Szrj    *  \endcode
88*38fd1498Szrj    *  To negate every element in @c a, use
89*38fd1498Szrj    *  \code
90*38fd1498Szrj    *  transform(a.begin(), a.end(), a.begin(), negate<double>());
91*38fd1498Szrj    *  \endcode
92*38fd1498Szrj    *  The addition and negation functions will be inlined directly.
93*38fd1498Szrj    *
94*38fd1498Szrj    *  The standard functors are derived from structs named @c unary_function
95*38fd1498Szrj    *  and @c binary_function.  These two classes contain nothing but typedefs,
96*38fd1498Szrj    *  to aid in generic (template) programming.  If you write your own
97*38fd1498Szrj    *  functors, you might consider doing the same.
98*38fd1498Szrj    *
99*38fd1498Szrj    *  @{
100*38fd1498Szrj    */
101*38fd1498Szrj   /**
102*38fd1498Szrj    *  This is one of the @link functors functor base classes@endlink.
103*38fd1498Szrj    */
104*38fd1498Szrj   template<typename _Arg, typename _Result>
105*38fd1498Szrj     struct unary_function
106*38fd1498Szrj     {
107*38fd1498Szrj       /// @c argument_type is the type of the argument
108*38fd1498Szrj       typedef _Arg 	argument_type;
109*38fd1498Szrj 
110*38fd1498Szrj       /// @c result_type is the return type
111*38fd1498Szrj       typedef _Result 	result_type;
112*38fd1498Szrj     };
113*38fd1498Szrj 
114*38fd1498Szrj   /**
115*38fd1498Szrj    *  This is one of the @link functors functor base classes@endlink.
116*38fd1498Szrj    */
117*38fd1498Szrj   template<typename _Arg1, typename _Arg2, typename _Result>
118*38fd1498Szrj     struct binary_function
119*38fd1498Szrj     {
120*38fd1498Szrj       /// @c first_argument_type is the type of the first argument
121*38fd1498Szrj       typedef _Arg1 	first_argument_type;
122*38fd1498Szrj 
123*38fd1498Szrj       /// @c second_argument_type is the type of the second argument
124*38fd1498Szrj       typedef _Arg2 	second_argument_type;
125*38fd1498Szrj 
126*38fd1498Szrj       /// @c result_type is the return type
127*38fd1498Szrj       typedef _Result 	result_type;
128*38fd1498Szrj     };
129*38fd1498Szrj   /** @}  */
130*38fd1498Szrj 
131*38fd1498Szrj   // 20.3.2 arithmetic
132*38fd1498Szrj   /** @defgroup arithmetic_functors Arithmetic Classes
133*38fd1498Szrj    * @ingroup functors
134*38fd1498Szrj    *
135*38fd1498Szrj    *  Because basic math often needs to be done during an algorithm,
136*38fd1498Szrj    *  the library provides functors for those operations.  See the
137*38fd1498Szrj    *  documentation for @link functors the base classes@endlink
138*38fd1498Szrj    *  for examples of their use.
139*38fd1498Szrj    *
140*38fd1498Szrj    *  @{
141*38fd1498Szrj    */
142*38fd1498Szrj 
143*38fd1498Szrj #if __cplusplus > 201103L
144*38fd1498Szrj   struct __is_transparent;  // undefined
145*38fd1498Szrj 
146*38fd1498Szrj   template<typename _Tp = void>
147*38fd1498Szrj     struct plus;
148*38fd1498Szrj 
149*38fd1498Szrj   template<typename _Tp = void>
150*38fd1498Szrj     struct minus;
151*38fd1498Szrj 
152*38fd1498Szrj   template<typename _Tp = void>
153*38fd1498Szrj     struct multiplies;
154*38fd1498Szrj 
155*38fd1498Szrj   template<typename _Tp = void>
156*38fd1498Szrj     struct divides;
157*38fd1498Szrj 
158*38fd1498Szrj   template<typename _Tp = void>
159*38fd1498Szrj     struct modulus;
160*38fd1498Szrj 
161*38fd1498Szrj   template<typename _Tp = void>
162*38fd1498Szrj     struct negate;
163*38fd1498Szrj #endif
164*38fd1498Szrj 
165*38fd1498Szrj   /// One of the @link arithmetic_functors math functors@endlink.
166*38fd1498Szrj   template<typename _Tp>
167*38fd1498Szrj     struct plus : public binary_function<_Tp, _Tp, _Tp>
168*38fd1498Szrj     {
169*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
170*38fd1498Szrj       _Tp
171*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
172*38fd1498Szrj       { return __x + __y; }
173*38fd1498Szrj     };
174*38fd1498Szrj 
175*38fd1498Szrj   /// One of the @link arithmetic_functors math functors@endlink.
176*38fd1498Szrj   template<typename _Tp>
177*38fd1498Szrj     struct minus : public binary_function<_Tp, _Tp, _Tp>
178*38fd1498Szrj     {
179*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
180*38fd1498Szrj       _Tp
181*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
182*38fd1498Szrj       { return __x - __y; }
183*38fd1498Szrj     };
184*38fd1498Szrj 
185*38fd1498Szrj   /// One of the @link arithmetic_functors math functors@endlink.
186*38fd1498Szrj   template<typename _Tp>
187*38fd1498Szrj     struct multiplies : public binary_function<_Tp, _Tp, _Tp>
188*38fd1498Szrj     {
189*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
190*38fd1498Szrj       _Tp
191*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
192*38fd1498Szrj       { return __x * __y; }
193*38fd1498Szrj     };
194*38fd1498Szrj 
195*38fd1498Szrj   /// One of the @link arithmetic_functors math functors@endlink.
196*38fd1498Szrj   template<typename _Tp>
197*38fd1498Szrj     struct divides : public binary_function<_Tp, _Tp, _Tp>
198*38fd1498Szrj     {
199*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
200*38fd1498Szrj       _Tp
201*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
202*38fd1498Szrj       { return __x / __y; }
203*38fd1498Szrj     };
204*38fd1498Szrj 
205*38fd1498Szrj   /// One of the @link arithmetic_functors math functors@endlink.
206*38fd1498Szrj   template<typename _Tp>
207*38fd1498Szrj     struct modulus : public binary_function<_Tp, _Tp, _Tp>
208*38fd1498Szrj     {
209*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
210*38fd1498Szrj       _Tp
211*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
212*38fd1498Szrj       { return __x % __y; }
213*38fd1498Szrj     };
214*38fd1498Szrj 
215*38fd1498Szrj   /// One of the @link arithmetic_functors math functors@endlink.
216*38fd1498Szrj   template<typename _Tp>
217*38fd1498Szrj     struct negate : public unary_function<_Tp, _Tp>
218*38fd1498Szrj     {
219*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
220*38fd1498Szrj       _Tp
221*38fd1498Szrj       operator()(const _Tp& __x) const
222*38fd1498Szrj       { return -__x; }
223*38fd1498Szrj     };
224*38fd1498Szrj 
225*38fd1498Szrj #if __cplusplus > 201103L
226*38fd1498Szrj 
227*38fd1498Szrj #define __cpp_lib_transparent_operators 201510
228*38fd1498Szrj 
229*38fd1498Szrj   template<>
230*38fd1498Szrj     struct plus<void>
231*38fd1498Szrj     {
232*38fd1498Szrj       template <typename _Tp, typename _Up>
233*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
234*38fd1498Szrj 	auto
235*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
236*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) + std::forward<_Up>(__u)))
237*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) + std::forward<_Up>(__u))
238*38fd1498Szrj 	{ return std::forward<_Tp>(__t) + std::forward<_Up>(__u); }
239*38fd1498Szrj 
240*38fd1498Szrj       typedef __is_transparent is_transparent;
241*38fd1498Szrj     };
242*38fd1498Szrj 
243*38fd1498Szrj   /// One of the @link arithmetic_functors math functors@endlink.
244*38fd1498Szrj   template<>
245*38fd1498Szrj     struct minus<void>
246*38fd1498Szrj     {
247*38fd1498Szrj       template <typename _Tp, typename _Up>
248*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
249*38fd1498Szrj 	auto
250*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
251*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) - std::forward<_Up>(__u)))
252*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) - std::forward<_Up>(__u))
253*38fd1498Szrj 	{ return std::forward<_Tp>(__t) - std::forward<_Up>(__u); }
254*38fd1498Szrj 
255*38fd1498Szrj       typedef __is_transparent is_transparent;
256*38fd1498Szrj     };
257*38fd1498Szrj 
258*38fd1498Szrj   /// One of the @link arithmetic_functors math functors@endlink.
259*38fd1498Szrj   template<>
260*38fd1498Szrj     struct multiplies<void>
261*38fd1498Szrj     {
262*38fd1498Szrj       template <typename _Tp, typename _Up>
263*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
264*38fd1498Szrj 	auto
265*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
266*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) * std::forward<_Up>(__u)))
267*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) * std::forward<_Up>(__u))
268*38fd1498Szrj 	{ return std::forward<_Tp>(__t) * std::forward<_Up>(__u); }
269*38fd1498Szrj 
270*38fd1498Szrj       typedef __is_transparent is_transparent;
271*38fd1498Szrj     };
272*38fd1498Szrj 
273*38fd1498Szrj   /// One of the @link arithmetic_functors math functors@endlink.
274*38fd1498Szrj   template<>
275*38fd1498Szrj     struct divides<void>
276*38fd1498Szrj     {
277*38fd1498Szrj       template <typename _Tp, typename _Up>
278*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
279*38fd1498Szrj 	auto
280*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
281*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) / std::forward<_Up>(__u)))
282*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) / std::forward<_Up>(__u))
283*38fd1498Szrj 	{ return std::forward<_Tp>(__t) / std::forward<_Up>(__u); }
284*38fd1498Szrj 
285*38fd1498Szrj       typedef __is_transparent is_transparent;
286*38fd1498Szrj     };
287*38fd1498Szrj 
288*38fd1498Szrj   /// One of the @link arithmetic_functors math functors@endlink.
289*38fd1498Szrj   template<>
290*38fd1498Szrj     struct modulus<void>
291*38fd1498Szrj     {
292*38fd1498Szrj       template <typename _Tp, typename _Up>
293*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
294*38fd1498Szrj 	auto
295*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
296*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) % std::forward<_Up>(__u)))
297*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) % std::forward<_Up>(__u))
298*38fd1498Szrj 	{ return std::forward<_Tp>(__t) % std::forward<_Up>(__u); }
299*38fd1498Szrj 
300*38fd1498Szrj       typedef __is_transparent is_transparent;
301*38fd1498Szrj     };
302*38fd1498Szrj 
303*38fd1498Szrj   /// One of the @link arithmetic_functors math functors@endlink.
304*38fd1498Szrj   template<>
305*38fd1498Szrj     struct negate<void>
306*38fd1498Szrj     {
307*38fd1498Szrj       template <typename _Tp>
308*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
309*38fd1498Szrj 	auto
310*38fd1498Szrj 	operator()(_Tp&& __t) const
311*38fd1498Szrj 	noexcept(noexcept(-std::forward<_Tp>(__t)))
312*38fd1498Szrj 	-> decltype(-std::forward<_Tp>(__t))
313*38fd1498Szrj 	{ return -std::forward<_Tp>(__t); }
314*38fd1498Szrj 
315*38fd1498Szrj       typedef __is_transparent is_transparent;
316*38fd1498Szrj     };
317*38fd1498Szrj #endif
318*38fd1498Szrj   /** @}  */
319*38fd1498Szrj 
320*38fd1498Szrj   // 20.3.3 comparisons
321*38fd1498Szrj   /** @defgroup comparison_functors Comparison Classes
322*38fd1498Szrj    * @ingroup functors
323*38fd1498Szrj    *
324*38fd1498Szrj    *  The library provides six wrapper functors for all the basic comparisons
325*38fd1498Szrj    *  in C++, like @c <.
326*38fd1498Szrj    *
327*38fd1498Szrj    *  @{
328*38fd1498Szrj    */
329*38fd1498Szrj #if __cplusplus > 201103L
330*38fd1498Szrj   template<typename _Tp = void>
331*38fd1498Szrj     struct equal_to;
332*38fd1498Szrj 
333*38fd1498Szrj   template<typename _Tp = void>
334*38fd1498Szrj     struct not_equal_to;
335*38fd1498Szrj 
336*38fd1498Szrj   template<typename _Tp = void>
337*38fd1498Szrj     struct greater;
338*38fd1498Szrj 
339*38fd1498Szrj   template<typename _Tp = void>
340*38fd1498Szrj     struct less;
341*38fd1498Szrj 
342*38fd1498Szrj   template<typename _Tp = void>
343*38fd1498Szrj     struct greater_equal;
344*38fd1498Szrj 
345*38fd1498Szrj   template<typename _Tp = void>
346*38fd1498Szrj     struct less_equal;
347*38fd1498Szrj #endif
348*38fd1498Szrj 
349*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
350*38fd1498Szrj   template<typename _Tp>
351*38fd1498Szrj     struct equal_to : public binary_function<_Tp, _Tp, bool>
352*38fd1498Szrj     {
353*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
354*38fd1498Szrj       bool
355*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
356*38fd1498Szrj       { return __x == __y; }
357*38fd1498Szrj     };
358*38fd1498Szrj 
359*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
360*38fd1498Szrj   template<typename _Tp>
361*38fd1498Szrj     struct not_equal_to : public binary_function<_Tp, _Tp, bool>
362*38fd1498Szrj     {
363*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
364*38fd1498Szrj       bool
365*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
366*38fd1498Szrj       { return __x != __y; }
367*38fd1498Szrj     };
368*38fd1498Szrj 
369*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
370*38fd1498Szrj   template<typename _Tp>
371*38fd1498Szrj     struct greater : public binary_function<_Tp, _Tp, bool>
372*38fd1498Szrj     {
373*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
374*38fd1498Szrj       bool
375*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
376*38fd1498Szrj       { return __x > __y; }
377*38fd1498Szrj     };
378*38fd1498Szrj 
379*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
380*38fd1498Szrj   template<typename _Tp>
381*38fd1498Szrj     struct less : public binary_function<_Tp, _Tp, bool>
382*38fd1498Szrj     {
383*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
384*38fd1498Szrj       bool
385*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
386*38fd1498Szrj       { return __x < __y; }
387*38fd1498Szrj     };
388*38fd1498Szrj 
389*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
390*38fd1498Szrj   template<typename _Tp>
391*38fd1498Szrj     struct greater_equal : public binary_function<_Tp, _Tp, bool>
392*38fd1498Szrj     {
393*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
394*38fd1498Szrj       bool
395*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
396*38fd1498Szrj       { return __x >= __y; }
397*38fd1498Szrj     };
398*38fd1498Szrj 
399*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
400*38fd1498Szrj   template<typename _Tp>
401*38fd1498Szrj     struct less_equal : public binary_function<_Tp, _Tp, bool>
402*38fd1498Szrj     {
403*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
404*38fd1498Szrj       bool
405*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
406*38fd1498Szrj       { return __x <= __y; }
407*38fd1498Szrj     };
408*38fd1498Szrj 
409*38fd1498Szrj   // Partial specialization of std::greater for pointers.
410*38fd1498Szrj   template<typename _Tp>
411*38fd1498Szrj     struct greater<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
412*38fd1498Szrj     {
413*38fd1498Szrj       _GLIBCXX14_CONSTEXPR bool
414*38fd1498Szrj       operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
415*38fd1498Szrj       {
416*38fd1498Szrj 	if (__builtin_constant_p (__x > __y))
417*38fd1498Szrj 	  return __x > __y;
418*38fd1498Szrj 	return (__UINTPTR_TYPE__)__x > (__UINTPTR_TYPE__)__y;
419*38fd1498Szrj       }
420*38fd1498Szrj     };
421*38fd1498Szrj 
422*38fd1498Szrj   // Partial specialization of std::less for pointers.
423*38fd1498Szrj   template<typename _Tp>
424*38fd1498Szrj     struct less<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
425*38fd1498Szrj     {
426*38fd1498Szrj       _GLIBCXX14_CONSTEXPR bool
427*38fd1498Szrj       operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
428*38fd1498Szrj       {
429*38fd1498Szrj 	if (__builtin_constant_p (__x < __y))
430*38fd1498Szrj 	  return __x < __y;
431*38fd1498Szrj 	return (__UINTPTR_TYPE__)__x < (__UINTPTR_TYPE__)__y;
432*38fd1498Szrj       }
433*38fd1498Szrj     };
434*38fd1498Szrj 
435*38fd1498Szrj   // Partial specialization of std::greater_equal for pointers.
436*38fd1498Szrj   template<typename _Tp>
437*38fd1498Szrj     struct greater_equal<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
438*38fd1498Szrj     {
439*38fd1498Szrj       _GLIBCXX14_CONSTEXPR bool
440*38fd1498Szrj       operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
441*38fd1498Szrj       {
442*38fd1498Szrj 	if (__builtin_constant_p (__x >= __y))
443*38fd1498Szrj 	  return __x >= __y;
444*38fd1498Szrj 	return (__UINTPTR_TYPE__)__x >= (__UINTPTR_TYPE__)__y;
445*38fd1498Szrj       }
446*38fd1498Szrj     };
447*38fd1498Szrj 
448*38fd1498Szrj   // Partial specialization of std::less_equal for pointers.
449*38fd1498Szrj   template<typename _Tp>
450*38fd1498Szrj     struct less_equal<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
451*38fd1498Szrj     {
452*38fd1498Szrj       _GLIBCXX14_CONSTEXPR bool
453*38fd1498Szrj       operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
454*38fd1498Szrj       {
455*38fd1498Szrj 	if (__builtin_constant_p (__x <= __y))
456*38fd1498Szrj 	  return __x <= __y;
457*38fd1498Szrj 	return (__UINTPTR_TYPE__)__x <= (__UINTPTR_TYPE__)__y;
458*38fd1498Szrj       }
459*38fd1498Szrj     };
460*38fd1498Szrj 
461*38fd1498Szrj #if __cplusplus >= 201402L
462*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
463*38fd1498Szrj   template<>
464*38fd1498Szrj     struct equal_to<void>
465*38fd1498Szrj     {
466*38fd1498Szrj       template <typename _Tp, typename _Up>
467*38fd1498Szrj 	constexpr auto
468*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
469*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u)))
470*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u))
471*38fd1498Szrj 	{ return std::forward<_Tp>(__t) == std::forward<_Up>(__u); }
472*38fd1498Szrj 
473*38fd1498Szrj       typedef __is_transparent is_transparent;
474*38fd1498Szrj     };
475*38fd1498Szrj 
476*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
477*38fd1498Szrj   template<>
478*38fd1498Szrj     struct not_equal_to<void>
479*38fd1498Szrj     {
480*38fd1498Szrj       template <typename _Tp, typename _Up>
481*38fd1498Szrj 	constexpr auto
482*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
483*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) != std::forward<_Up>(__u)))
484*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) != std::forward<_Up>(__u))
485*38fd1498Szrj 	{ return std::forward<_Tp>(__t) != std::forward<_Up>(__u); }
486*38fd1498Szrj 
487*38fd1498Szrj       typedef __is_transparent is_transparent;
488*38fd1498Szrj     };
489*38fd1498Szrj 
490*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
491*38fd1498Szrj   template<>
492*38fd1498Szrj     struct greater<void>
493*38fd1498Szrj     {
494*38fd1498Szrj       template <typename _Tp, typename _Up>
495*38fd1498Szrj 	constexpr auto
496*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
497*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) > std::forward<_Up>(__u)))
498*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) > std::forward<_Up>(__u))
499*38fd1498Szrj 	{
500*38fd1498Szrj 	  return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
501*38fd1498Szrj 			__ptr_cmp<_Tp, _Up>{});
502*38fd1498Szrj 	}
503*38fd1498Szrj 
504*38fd1498Szrj       template<typename _Tp, typename _Up>
505*38fd1498Szrj 	constexpr bool
506*38fd1498Szrj 	operator()(_Tp* __t, _Up* __u) const noexcept
507*38fd1498Szrj 	{ return greater<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
508*38fd1498Szrj 
509*38fd1498Szrj       typedef __is_transparent is_transparent;
510*38fd1498Szrj 
511*38fd1498Szrj     private:
512*38fd1498Szrj       template <typename _Tp, typename _Up>
513*38fd1498Szrj 	static constexpr decltype(auto)
514*38fd1498Szrj 	_S_cmp(_Tp&& __t, _Up&& __u, false_type)
515*38fd1498Szrj 	{ return std::forward<_Tp>(__t) > std::forward<_Up>(__u); }
516*38fd1498Szrj 
517*38fd1498Szrj       template <typename _Tp, typename _Up>
518*38fd1498Szrj 	static constexpr bool
519*38fd1498Szrj 	_S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
520*38fd1498Szrj 	{
521*38fd1498Szrj 	  return greater<const volatile void*>{}(
522*38fd1498Szrj 	      static_cast<const volatile void*>(std::forward<_Tp>(__t)),
523*38fd1498Szrj 	      static_cast<const volatile void*>(std::forward<_Up>(__u)));
524*38fd1498Szrj 	}
525*38fd1498Szrj 
526*38fd1498Szrj       // True if there is no viable operator> member function.
527*38fd1498Szrj       template<typename _Tp, typename _Up, typename = void>
528*38fd1498Szrj 	struct __not_overloaded2 : true_type { };
529*38fd1498Szrj 
530*38fd1498Szrj       // False if we can call T.operator>(U)
531*38fd1498Szrj       template<typename _Tp, typename _Up>
532*38fd1498Szrj 	struct __not_overloaded2<_Tp, _Up, __void_t<
533*38fd1498Szrj 	  decltype(std::declval<_Tp>().operator>(std::declval<_Up>()))>>
534*38fd1498Szrj 	: false_type { };
535*38fd1498Szrj 
536*38fd1498Szrj       // True if there is no overloaded operator> for these operands.
537*38fd1498Szrj       template<typename _Tp, typename _Up, typename = void>
538*38fd1498Szrj 	struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
539*38fd1498Szrj 
540*38fd1498Szrj       // False if we can call operator>(T,U)
541*38fd1498Szrj       template<typename _Tp, typename _Up>
542*38fd1498Szrj 	struct __not_overloaded<_Tp, _Up, __void_t<
543*38fd1498Szrj 	  decltype(operator>(std::declval<_Tp>(), std::declval<_Up>()))>>
544*38fd1498Szrj 	: false_type { };
545*38fd1498Szrj 
546*38fd1498Szrj       template<typename _Tp, typename _Up>
547*38fd1498Szrj 	using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
548*38fd1498Szrj 	      is_convertible<_Tp, const volatile void*>,
549*38fd1498Szrj 	      is_convertible<_Up, const volatile void*>>;
550*38fd1498Szrj     };
551*38fd1498Szrj 
552*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
553*38fd1498Szrj   template<>
554*38fd1498Szrj     struct less<void>
555*38fd1498Szrj     {
556*38fd1498Szrj       template <typename _Tp, typename _Up>
557*38fd1498Szrj 	constexpr auto
558*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
559*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) < std::forward<_Up>(__u)))
560*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) < std::forward<_Up>(__u))
561*38fd1498Szrj 	{
562*38fd1498Szrj 	  return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
563*38fd1498Szrj 			__ptr_cmp<_Tp, _Up>{});
564*38fd1498Szrj 	}
565*38fd1498Szrj 
566*38fd1498Szrj       template<typename _Tp, typename _Up>
567*38fd1498Szrj 	constexpr bool
568*38fd1498Szrj 	operator()(_Tp* __t, _Up* __u) const noexcept
569*38fd1498Szrj 	{ return less<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
570*38fd1498Szrj 
571*38fd1498Szrj       typedef __is_transparent is_transparent;
572*38fd1498Szrj 
573*38fd1498Szrj     private:
574*38fd1498Szrj       template <typename _Tp, typename _Up>
575*38fd1498Szrj 	static constexpr decltype(auto)
576*38fd1498Szrj 	_S_cmp(_Tp&& __t, _Up&& __u, false_type)
577*38fd1498Szrj 	{ return std::forward<_Tp>(__t) < std::forward<_Up>(__u); }
578*38fd1498Szrj 
579*38fd1498Szrj       template <typename _Tp, typename _Up>
580*38fd1498Szrj 	static constexpr bool
581*38fd1498Szrj 	_S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
582*38fd1498Szrj 	{
583*38fd1498Szrj 	  return less<const volatile void*>{}(
584*38fd1498Szrj 	      static_cast<const volatile void*>(std::forward<_Tp>(__t)),
585*38fd1498Szrj 	      static_cast<const volatile void*>(std::forward<_Up>(__u)));
586*38fd1498Szrj 	}
587*38fd1498Szrj 
588*38fd1498Szrj       // True if there is no viable operator< member function.
589*38fd1498Szrj       template<typename _Tp, typename _Up, typename = void>
590*38fd1498Szrj 	struct __not_overloaded2 : true_type { };
591*38fd1498Szrj 
592*38fd1498Szrj       // False if we can call T.operator<(U)
593*38fd1498Szrj       template<typename _Tp, typename _Up>
594*38fd1498Szrj 	struct __not_overloaded2<_Tp, _Up, __void_t<
595*38fd1498Szrj 	  decltype(std::declval<_Tp>().operator<(std::declval<_Up>()))>>
596*38fd1498Szrj 	: false_type { };
597*38fd1498Szrj 
598*38fd1498Szrj       // True if there is no overloaded operator< for these operands.
599*38fd1498Szrj       template<typename _Tp, typename _Up, typename = void>
600*38fd1498Szrj 	struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
601*38fd1498Szrj 
602*38fd1498Szrj       // False if we can call operator<(T,U)
603*38fd1498Szrj       template<typename _Tp, typename _Up>
604*38fd1498Szrj 	struct __not_overloaded<_Tp, _Up, __void_t<
605*38fd1498Szrj 	  decltype(operator<(std::declval<_Tp>(), std::declval<_Up>()))>>
606*38fd1498Szrj 	: false_type { };
607*38fd1498Szrj 
608*38fd1498Szrj       template<typename _Tp, typename _Up>
609*38fd1498Szrj 	using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
610*38fd1498Szrj 	      is_convertible<_Tp, const volatile void*>,
611*38fd1498Szrj 	      is_convertible<_Up, const volatile void*>>;
612*38fd1498Szrj     };
613*38fd1498Szrj 
614*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
615*38fd1498Szrj   template<>
616*38fd1498Szrj     struct greater_equal<void>
617*38fd1498Szrj     {
618*38fd1498Szrj       template <typename _Tp, typename _Up>
619*38fd1498Szrj 	constexpr auto
620*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
621*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) >= std::forward<_Up>(__u)))
622*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) >= std::forward<_Up>(__u))
623*38fd1498Szrj 	{
624*38fd1498Szrj 	  return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
625*38fd1498Szrj 			__ptr_cmp<_Tp, _Up>{});
626*38fd1498Szrj 	}
627*38fd1498Szrj 
628*38fd1498Szrj       template<typename _Tp, typename _Up>
629*38fd1498Szrj 	constexpr bool
630*38fd1498Szrj 	operator()(_Tp* __t, _Up* __u) const noexcept
631*38fd1498Szrj 	{ return greater_equal<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
632*38fd1498Szrj 
633*38fd1498Szrj       typedef __is_transparent is_transparent;
634*38fd1498Szrj 
635*38fd1498Szrj     private:
636*38fd1498Szrj       template <typename _Tp, typename _Up>
637*38fd1498Szrj 	static constexpr decltype(auto)
638*38fd1498Szrj 	_S_cmp(_Tp&& __t, _Up&& __u, false_type)
639*38fd1498Szrj 	{ return std::forward<_Tp>(__t) >= std::forward<_Up>(__u); }
640*38fd1498Szrj 
641*38fd1498Szrj       template <typename _Tp, typename _Up>
642*38fd1498Szrj 	static constexpr bool
643*38fd1498Szrj 	_S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
644*38fd1498Szrj 	{
645*38fd1498Szrj 	  return greater_equal<const volatile void*>{}(
646*38fd1498Szrj 	      static_cast<const volatile void*>(std::forward<_Tp>(__t)),
647*38fd1498Szrj 	      static_cast<const volatile void*>(std::forward<_Up>(__u)));
648*38fd1498Szrj 	}
649*38fd1498Szrj 
650*38fd1498Szrj       // True if there is no viable operator>= member function.
651*38fd1498Szrj       template<typename _Tp, typename _Up, typename = void>
652*38fd1498Szrj 	struct __not_overloaded2 : true_type { };
653*38fd1498Szrj 
654*38fd1498Szrj       // False if we can call T.operator>=(U)
655*38fd1498Szrj       template<typename _Tp, typename _Up>
656*38fd1498Szrj 	struct __not_overloaded2<_Tp, _Up, __void_t<
657*38fd1498Szrj 	  decltype(std::declval<_Tp>().operator>=(std::declval<_Up>()))>>
658*38fd1498Szrj 	: false_type { };
659*38fd1498Szrj 
660*38fd1498Szrj       // True if there is no overloaded operator>= for these operands.
661*38fd1498Szrj       template<typename _Tp, typename _Up, typename = void>
662*38fd1498Szrj 	struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
663*38fd1498Szrj 
664*38fd1498Szrj       // False if we can call operator>=(T,U)
665*38fd1498Szrj       template<typename _Tp, typename _Up>
666*38fd1498Szrj 	struct __not_overloaded<_Tp, _Up, __void_t<
667*38fd1498Szrj 	  decltype(operator>=(std::declval<_Tp>(), std::declval<_Up>()))>>
668*38fd1498Szrj 	: false_type { };
669*38fd1498Szrj 
670*38fd1498Szrj       template<typename _Tp, typename _Up>
671*38fd1498Szrj 	using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
672*38fd1498Szrj 	      is_convertible<_Tp, const volatile void*>,
673*38fd1498Szrj 	      is_convertible<_Up, const volatile void*>>;
674*38fd1498Szrj     };
675*38fd1498Szrj 
676*38fd1498Szrj   /// One of the @link comparison_functors comparison functors@endlink.
677*38fd1498Szrj   template<>
678*38fd1498Szrj     struct less_equal<void>
679*38fd1498Szrj     {
680*38fd1498Szrj       template <typename _Tp, typename _Up>
681*38fd1498Szrj 	constexpr auto
682*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
683*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) <= std::forward<_Up>(__u)))
684*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) <= std::forward<_Up>(__u))
685*38fd1498Szrj 	{
686*38fd1498Szrj 	  return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
687*38fd1498Szrj 			__ptr_cmp<_Tp, _Up>{});
688*38fd1498Szrj 	}
689*38fd1498Szrj 
690*38fd1498Szrj       template<typename _Tp, typename _Up>
691*38fd1498Szrj 	constexpr bool
692*38fd1498Szrj 	operator()(_Tp* __t, _Up* __u) const noexcept
693*38fd1498Szrj 	{ return less_equal<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
694*38fd1498Szrj 
695*38fd1498Szrj       typedef __is_transparent is_transparent;
696*38fd1498Szrj 
697*38fd1498Szrj     private:
698*38fd1498Szrj       template <typename _Tp, typename _Up>
699*38fd1498Szrj 	static constexpr decltype(auto)
700*38fd1498Szrj 	_S_cmp(_Tp&& __t, _Up&& __u, false_type)
701*38fd1498Szrj 	{ return std::forward<_Tp>(__t) <= std::forward<_Up>(__u); }
702*38fd1498Szrj 
703*38fd1498Szrj       template <typename _Tp, typename _Up>
704*38fd1498Szrj 	static constexpr bool
705*38fd1498Szrj 	_S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
706*38fd1498Szrj 	{
707*38fd1498Szrj 	  return less_equal<const volatile void*>{}(
708*38fd1498Szrj 	      static_cast<const volatile void*>(std::forward<_Tp>(__t)),
709*38fd1498Szrj 	      static_cast<const volatile void*>(std::forward<_Up>(__u)));
710*38fd1498Szrj 	}
711*38fd1498Szrj 
712*38fd1498Szrj       // True if there is no viable operator<= member function.
713*38fd1498Szrj       template<typename _Tp, typename _Up, typename = void>
714*38fd1498Szrj 	struct __not_overloaded2 : true_type { };
715*38fd1498Szrj 
716*38fd1498Szrj       // False if we can call T.operator<=(U)
717*38fd1498Szrj       template<typename _Tp, typename _Up>
718*38fd1498Szrj 	struct __not_overloaded2<_Tp, _Up, __void_t<
719*38fd1498Szrj 	  decltype(std::declval<_Tp>().operator<=(std::declval<_Up>()))>>
720*38fd1498Szrj 	: false_type { };
721*38fd1498Szrj 
722*38fd1498Szrj       // True if there is no overloaded operator<= for these operands.
723*38fd1498Szrj       template<typename _Tp, typename _Up, typename = void>
724*38fd1498Szrj 	struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
725*38fd1498Szrj 
726*38fd1498Szrj       // False if we can call operator<=(T,U)
727*38fd1498Szrj       template<typename _Tp, typename _Up>
728*38fd1498Szrj 	struct __not_overloaded<_Tp, _Up, __void_t<
729*38fd1498Szrj 	  decltype(operator<=(std::declval<_Tp>(), std::declval<_Up>()))>>
730*38fd1498Szrj 	: false_type { };
731*38fd1498Szrj 
732*38fd1498Szrj       template<typename _Tp, typename _Up>
733*38fd1498Szrj 	using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
734*38fd1498Szrj 	      is_convertible<_Tp, const volatile void*>,
735*38fd1498Szrj 	      is_convertible<_Up, const volatile void*>>;
736*38fd1498Szrj     };
737*38fd1498Szrj #endif // C++14
738*38fd1498Szrj   /** @}  */
739*38fd1498Szrj 
740*38fd1498Szrj   // 20.3.4 logical operations
741*38fd1498Szrj   /** @defgroup logical_functors Boolean Operations Classes
742*38fd1498Szrj    * @ingroup functors
743*38fd1498Szrj    *
744*38fd1498Szrj    *  Here are wrapper functors for Boolean operations: @c &&, @c ||,
745*38fd1498Szrj    *  and @c !.
746*38fd1498Szrj    *
747*38fd1498Szrj    *  @{
748*38fd1498Szrj    */
749*38fd1498Szrj #if __cplusplus > 201103L
750*38fd1498Szrj   template<typename _Tp = void>
751*38fd1498Szrj     struct logical_and;
752*38fd1498Szrj 
753*38fd1498Szrj   template<typename _Tp = void>
754*38fd1498Szrj     struct logical_or;
755*38fd1498Szrj 
756*38fd1498Szrj   template<typename _Tp = void>
757*38fd1498Szrj     struct logical_not;
758*38fd1498Szrj #endif
759*38fd1498Szrj 
760*38fd1498Szrj   /// One of the @link logical_functors Boolean operations functors@endlink.
761*38fd1498Szrj   template<typename _Tp>
762*38fd1498Szrj     struct logical_and : public binary_function<_Tp, _Tp, bool>
763*38fd1498Szrj     {
764*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
765*38fd1498Szrj       bool
766*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
767*38fd1498Szrj       { return __x && __y; }
768*38fd1498Szrj     };
769*38fd1498Szrj 
770*38fd1498Szrj   /// One of the @link logical_functors Boolean operations functors@endlink.
771*38fd1498Szrj   template<typename _Tp>
772*38fd1498Szrj     struct logical_or : public binary_function<_Tp, _Tp, bool>
773*38fd1498Szrj     {
774*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
775*38fd1498Szrj       bool
776*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
777*38fd1498Szrj       { return __x || __y; }
778*38fd1498Szrj     };
779*38fd1498Szrj 
780*38fd1498Szrj   /// One of the @link logical_functors Boolean operations functors@endlink.
781*38fd1498Szrj   template<typename _Tp>
782*38fd1498Szrj     struct logical_not : public unary_function<_Tp, bool>
783*38fd1498Szrj     {
784*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
785*38fd1498Szrj       bool
786*38fd1498Szrj       operator()(const _Tp& __x) const
787*38fd1498Szrj       { return !__x; }
788*38fd1498Szrj     };
789*38fd1498Szrj 
790*38fd1498Szrj #if __cplusplus > 201103L
791*38fd1498Szrj   /// One of the @link logical_functors Boolean operations functors@endlink.
792*38fd1498Szrj   template<>
793*38fd1498Szrj     struct logical_and<void>
794*38fd1498Szrj     {
795*38fd1498Szrj       template <typename _Tp, typename _Up>
796*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
797*38fd1498Szrj 	auto
798*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
799*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) && std::forward<_Up>(__u)))
800*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) && std::forward<_Up>(__u))
801*38fd1498Szrj 	{ return std::forward<_Tp>(__t) && std::forward<_Up>(__u); }
802*38fd1498Szrj 
803*38fd1498Szrj       typedef __is_transparent is_transparent;
804*38fd1498Szrj     };
805*38fd1498Szrj 
806*38fd1498Szrj   /// One of the @link logical_functors Boolean operations functors@endlink.
807*38fd1498Szrj   template<>
808*38fd1498Szrj     struct logical_or<void>
809*38fd1498Szrj     {
810*38fd1498Szrj       template <typename _Tp, typename _Up>
811*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
812*38fd1498Szrj 	auto
813*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
814*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) || std::forward<_Up>(__u)))
815*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) || std::forward<_Up>(__u))
816*38fd1498Szrj 	{ return std::forward<_Tp>(__t) || std::forward<_Up>(__u); }
817*38fd1498Szrj 
818*38fd1498Szrj       typedef __is_transparent is_transparent;
819*38fd1498Szrj     };
820*38fd1498Szrj 
821*38fd1498Szrj   /// One of the @link logical_functors Boolean operations functors@endlink.
822*38fd1498Szrj   template<>
823*38fd1498Szrj     struct logical_not<void>
824*38fd1498Szrj     {
825*38fd1498Szrj       template <typename _Tp>
826*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
827*38fd1498Szrj 	auto
828*38fd1498Szrj 	operator()(_Tp&& __t) const
829*38fd1498Szrj 	noexcept(noexcept(!std::forward<_Tp>(__t)))
830*38fd1498Szrj 	-> decltype(!std::forward<_Tp>(__t))
831*38fd1498Szrj 	{ return !std::forward<_Tp>(__t); }
832*38fd1498Szrj 
833*38fd1498Szrj       typedef __is_transparent is_transparent;
834*38fd1498Szrj     };
835*38fd1498Szrj #endif
836*38fd1498Szrj   /** @}  */
837*38fd1498Szrj 
838*38fd1498Szrj #if __cplusplus > 201103L
839*38fd1498Szrj   template<typename _Tp = void>
840*38fd1498Szrj     struct bit_and;
841*38fd1498Szrj 
842*38fd1498Szrj   template<typename _Tp = void>
843*38fd1498Szrj     struct bit_or;
844*38fd1498Szrj 
845*38fd1498Szrj   template<typename _Tp = void>
846*38fd1498Szrj     struct bit_xor;
847*38fd1498Szrj 
848*38fd1498Szrj   template<typename _Tp = void>
849*38fd1498Szrj     struct bit_not;
850*38fd1498Szrj #endif
851*38fd1498Szrj 
852*38fd1498Szrj   // _GLIBCXX_RESOLVE_LIB_DEFECTS
853*38fd1498Szrj   // DR 660. Missing Bitwise Operations.
854*38fd1498Szrj   template<typename _Tp>
855*38fd1498Szrj     struct bit_and : public binary_function<_Tp, _Tp, _Tp>
856*38fd1498Szrj     {
857*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
858*38fd1498Szrj       _Tp
859*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
860*38fd1498Szrj       { return __x & __y; }
861*38fd1498Szrj     };
862*38fd1498Szrj 
863*38fd1498Szrj   template<typename _Tp>
864*38fd1498Szrj     struct bit_or : public binary_function<_Tp, _Tp, _Tp>
865*38fd1498Szrj     {
866*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
867*38fd1498Szrj       _Tp
868*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
869*38fd1498Szrj       { return __x | __y; }
870*38fd1498Szrj     };
871*38fd1498Szrj 
872*38fd1498Szrj   template<typename _Tp>
873*38fd1498Szrj     struct bit_xor : public binary_function<_Tp, _Tp, _Tp>
874*38fd1498Szrj     {
875*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
876*38fd1498Szrj       _Tp
877*38fd1498Szrj       operator()(const _Tp& __x, const _Tp& __y) const
878*38fd1498Szrj       { return __x ^ __y; }
879*38fd1498Szrj     };
880*38fd1498Szrj 
881*38fd1498Szrj   template<typename _Tp>
882*38fd1498Szrj     struct bit_not : public unary_function<_Tp, _Tp>
883*38fd1498Szrj     {
884*38fd1498Szrj     _GLIBCXX14_CONSTEXPR
885*38fd1498Szrj       _Tp
886*38fd1498Szrj       operator()(const _Tp& __x) const
887*38fd1498Szrj       { return ~__x; }
888*38fd1498Szrj     };
889*38fd1498Szrj 
890*38fd1498Szrj #if __cplusplus > 201103L
891*38fd1498Szrj   template <>
892*38fd1498Szrj     struct bit_and<void>
893*38fd1498Szrj     {
894*38fd1498Szrj       template <typename _Tp, typename _Up>
895*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
896*38fd1498Szrj 	auto
897*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
898*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) & std::forward<_Up>(__u)))
899*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) & std::forward<_Up>(__u))
900*38fd1498Szrj 	{ return std::forward<_Tp>(__t) & std::forward<_Up>(__u); }
901*38fd1498Szrj 
902*38fd1498Szrj       typedef __is_transparent is_transparent;
903*38fd1498Szrj     };
904*38fd1498Szrj 
905*38fd1498Szrj   template <>
906*38fd1498Szrj     struct bit_or<void>
907*38fd1498Szrj     {
908*38fd1498Szrj       template <typename _Tp, typename _Up>
909*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
910*38fd1498Szrj 	auto
911*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
912*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) | std::forward<_Up>(__u)))
913*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) | std::forward<_Up>(__u))
914*38fd1498Szrj 	{ return std::forward<_Tp>(__t) | std::forward<_Up>(__u); }
915*38fd1498Szrj 
916*38fd1498Szrj       typedef __is_transparent is_transparent;
917*38fd1498Szrj     };
918*38fd1498Szrj 
919*38fd1498Szrj   template <>
920*38fd1498Szrj     struct bit_xor<void>
921*38fd1498Szrj     {
922*38fd1498Szrj       template <typename _Tp, typename _Up>
923*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
924*38fd1498Szrj 	auto
925*38fd1498Szrj 	operator()(_Tp&& __t, _Up&& __u) const
926*38fd1498Szrj 	noexcept(noexcept(std::forward<_Tp>(__t) ^ std::forward<_Up>(__u)))
927*38fd1498Szrj 	-> decltype(std::forward<_Tp>(__t) ^ std::forward<_Up>(__u))
928*38fd1498Szrj 	{ return std::forward<_Tp>(__t) ^ std::forward<_Up>(__u); }
929*38fd1498Szrj 
930*38fd1498Szrj       typedef __is_transparent is_transparent;
931*38fd1498Szrj     };
932*38fd1498Szrj 
933*38fd1498Szrj   template <>
934*38fd1498Szrj     struct bit_not<void>
935*38fd1498Szrj     {
936*38fd1498Szrj       template <typename _Tp>
937*38fd1498Szrj 	_GLIBCXX14_CONSTEXPR
938*38fd1498Szrj 	auto
939*38fd1498Szrj 	operator()(_Tp&& __t) const
940*38fd1498Szrj 	noexcept(noexcept(~std::forward<_Tp>(__t)))
941*38fd1498Szrj 	-> decltype(~std::forward<_Tp>(__t))
942*38fd1498Szrj 	{ return ~std::forward<_Tp>(__t); }
943*38fd1498Szrj 
944*38fd1498Szrj       typedef __is_transparent is_transparent;
945*38fd1498Szrj     };
946*38fd1498Szrj #endif
947*38fd1498Szrj 
948*38fd1498Szrj   // 20.3.5 negators
949*38fd1498Szrj   /** @defgroup negators Negators
950*38fd1498Szrj    * @ingroup functors
951*38fd1498Szrj    *
952*38fd1498Szrj    *  The functions @c not1 and @c not2 each take a predicate functor
953*38fd1498Szrj    *  and return an instance of @c unary_negate or
954*38fd1498Szrj    *  @c binary_negate, respectively.  These classes are functors whose
955*38fd1498Szrj    *  @c operator() performs the stored predicate function and then returns
956*38fd1498Szrj    *  the negation of the result.
957*38fd1498Szrj    *
958*38fd1498Szrj    *  For example, given a vector of integers and a trivial predicate,
959*38fd1498Szrj    *  \code
960*38fd1498Szrj    *  struct IntGreaterThanThree
961*38fd1498Szrj    *    : public std::unary_function<int, bool>
962*38fd1498Szrj    *  {
963*38fd1498Szrj    *      bool operator() (int x) { return x > 3; }
964*38fd1498Szrj    *  };
965*38fd1498Szrj    *
966*38fd1498Szrj    *  std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
967*38fd1498Szrj    *  \endcode
968*38fd1498Szrj    *  The call to @c find_if will locate the first index (i) of @c v for which
969*38fd1498Szrj    *  <code>!(v[i] > 3)</code> is true.
970*38fd1498Szrj    *
971*38fd1498Szrj    *  The not1/unary_negate combination works on predicates taking a single
972*38fd1498Szrj    *  argument.  The not2/binary_negate combination works on predicates which
973*38fd1498Szrj    *  take two arguments.
974*38fd1498Szrj    *
975*38fd1498Szrj    *  @{
976*38fd1498Szrj    */
977*38fd1498Szrj   /// One of the @link negators negation functors@endlink.
978*38fd1498Szrj   template<typename _Predicate>
979*38fd1498Szrj     class unary_negate
980*38fd1498Szrj     : public unary_function<typename _Predicate::argument_type, bool>
981*38fd1498Szrj     {
982*38fd1498Szrj     protected:
983*38fd1498Szrj       _Predicate _M_pred;
984*38fd1498Szrj 
985*38fd1498Szrj     public:
986*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
987*38fd1498Szrj       explicit
988*38fd1498Szrj       unary_negate(const _Predicate& __x) : _M_pred(__x) { }
989*38fd1498Szrj 
990*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
991*38fd1498Szrj       bool
992*38fd1498Szrj       operator()(const typename _Predicate::argument_type& __x) const
993*38fd1498Szrj       { return !_M_pred(__x); }
994*38fd1498Szrj     };
995*38fd1498Szrj 
996*38fd1498Szrj   /// One of the @link negators negation functors@endlink.
997*38fd1498Szrj   template<typename _Predicate>
998*38fd1498Szrj     _GLIBCXX14_CONSTEXPR
999*38fd1498Szrj     inline unary_negate<_Predicate>
1000*38fd1498Szrj     not1(const _Predicate& __pred)
1001*38fd1498Szrj     { return unary_negate<_Predicate>(__pred); }
1002*38fd1498Szrj 
1003*38fd1498Szrj   /// One of the @link negators negation functors@endlink.
1004*38fd1498Szrj   template<typename _Predicate>
1005*38fd1498Szrj     class binary_negate
1006*38fd1498Szrj     : public binary_function<typename _Predicate::first_argument_type,
1007*38fd1498Szrj 			     typename _Predicate::second_argument_type, bool>
1008*38fd1498Szrj     {
1009*38fd1498Szrj     protected:
1010*38fd1498Szrj       _Predicate _M_pred;
1011*38fd1498Szrj 
1012*38fd1498Szrj     public:
1013*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
1014*38fd1498Szrj       explicit
1015*38fd1498Szrj       binary_negate(const _Predicate& __x) : _M_pred(__x) { }
1016*38fd1498Szrj 
1017*38fd1498Szrj       _GLIBCXX14_CONSTEXPR
1018*38fd1498Szrj       bool
1019*38fd1498Szrj       operator()(const typename _Predicate::first_argument_type& __x,
1020*38fd1498Szrj 		 const typename _Predicate::second_argument_type& __y) const
1021*38fd1498Szrj       { return !_M_pred(__x, __y); }
1022*38fd1498Szrj     };
1023*38fd1498Szrj 
1024*38fd1498Szrj   /// One of the @link negators negation functors@endlink.
1025*38fd1498Szrj   template<typename _Predicate>
1026*38fd1498Szrj     _GLIBCXX14_CONSTEXPR
1027*38fd1498Szrj     inline binary_negate<_Predicate>
1028*38fd1498Szrj     not2(const _Predicate& __pred)
1029*38fd1498Szrj     { return binary_negate<_Predicate>(__pred); }
1030*38fd1498Szrj   /** @}  */
1031*38fd1498Szrj 
1032*38fd1498Szrj   // 20.3.7 adaptors pointers functions
1033*38fd1498Szrj   /** @defgroup pointer_adaptors Adaptors for pointers to functions
1034*38fd1498Szrj    * @ingroup functors
1035*38fd1498Szrj    *
1036*38fd1498Szrj    *  The advantage of function objects over pointers to functions is that
1037*38fd1498Szrj    *  the objects in the standard library declare nested typedefs describing
1038*38fd1498Szrj    *  their argument and result types with uniform names (e.g., @c result_type
1039*38fd1498Szrj    *  from the base classes @c unary_function and @c binary_function).
1040*38fd1498Szrj    *  Sometimes those typedefs are required, not just optional.
1041*38fd1498Szrj    *
1042*38fd1498Szrj    *  Adaptors are provided to turn pointers to unary (single-argument) and
1043*38fd1498Szrj    *  binary (double-argument) functions into function objects.  The
1044*38fd1498Szrj    *  long-winded functor @c pointer_to_unary_function is constructed with a
1045*38fd1498Szrj    *  function pointer @c f, and its @c operator() called with argument @c x
1046*38fd1498Szrj    *  returns @c f(x).  The functor @c pointer_to_binary_function does the same
1047*38fd1498Szrj    *  thing, but with a double-argument @c f and @c operator().
1048*38fd1498Szrj    *
1049*38fd1498Szrj    *  The function @c ptr_fun takes a pointer-to-function @c f and constructs
1050*38fd1498Szrj    *  an instance of the appropriate functor.
1051*38fd1498Szrj    *
1052*38fd1498Szrj    *  @{
1053*38fd1498Szrj    */
1054*38fd1498Szrj   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
1055*38fd1498Szrj   template<typename _Arg, typename _Result>
1056*38fd1498Szrj     class pointer_to_unary_function : public unary_function<_Arg, _Result>
1057*38fd1498Szrj     {
1058*38fd1498Szrj     protected:
1059*38fd1498Szrj       _Result (*_M_ptr)(_Arg);
1060*38fd1498Szrj 
1061*38fd1498Szrj     public:
1062*38fd1498Szrj       pointer_to_unary_function() { }
1063*38fd1498Szrj 
1064*38fd1498Szrj       explicit
1065*38fd1498Szrj       pointer_to_unary_function(_Result (*__x)(_Arg))
1066*38fd1498Szrj       : _M_ptr(__x) { }
1067*38fd1498Szrj 
1068*38fd1498Szrj       _Result
1069*38fd1498Szrj       operator()(_Arg __x) const
1070*38fd1498Szrj       { return _M_ptr(__x); }
1071*38fd1498Szrj     };
1072*38fd1498Szrj 
1073*38fd1498Szrj   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
1074*38fd1498Szrj   template<typename _Arg, typename _Result>
1075*38fd1498Szrj     inline pointer_to_unary_function<_Arg, _Result>
1076*38fd1498Szrj     ptr_fun(_Result (*__x)(_Arg))
1077*38fd1498Szrj     { return pointer_to_unary_function<_Arg, _Result>(__x); }
1078*38fd1498Szrj 
1079*38fd1498Szrj   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
1080*38fd1498Szrj   template<typename _Arg1, typename _Arg2, typename _Result>
1081*38fd1498Szrj     class pointer_to_binary_function
1082*38fd1498Szrj     : public binary_function<_Arg1, _Arg2, _Result>
1083*38fd1498Szrj     {
1084*38fd1498Szrj     protected:
1085*38fd1498Szrj       _Result (*_M_ptr)(_Arg1, _Arg2);
1086*38fd1498Szrj 
1087*38fd1498Szrj     public:
1088*38fd1498Szrj       pointer_to_binary_function() { }
1089*38fd1498Szrj 
1090*38fd1498Szrj       explicit
1091*38fd1498Szrj       pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
1092*38fd1498Szrj       : _M_ptr(__x) { }
1093*38fd1498Szrj 
1094*38fd1498Szrj       _Result
1095*38fd1498Szrj       operator()(_Arg1 __x, _Arg2 __y) const
1096*38fd1498Szrj       { return _M_ptr(__x, __y); }
1097*38fd1498Szrj     };
1098*38fd1498Szrj 
1099*38fd1498Szrj   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
1100*38fd1498Szrj   template<typename _Arg1, typename _Arg2, typename _Result>
1101*38fd1498Szrj     inline pointer_to_binary_function<_Arg1, _Arg2, _Result>
1102*38fd1498Szrj     ptr_fun(_Result (*__x)(_Arg1, _Arg2))
1103*38fd1498Szrj     { return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x); }
1104*38fd1498Szrj   /** @}  */
1105*38fd1498Szrj 
1106*38fd1498Szrj   template<typename _Tp>
1107*38fd1498Szrj     struct _Identity
1108*38fd1498Szrj     : public unary_function<_Tp, _Tp>
1109*38fd1498Szrj     {
1110*38fd1498Szrj       _Tp&
1111*38fd1498Szrj       operator()(_Tp& __x) const
1112*38fd1498Szrj       { return __x; }
1113*38fd1498Szrj 
1114*38fd1498Szrj       const _Tp&
1115*38fd1498Szrj       operator()(const _Tp& __x) const
1116*38fd1498Szrj       { return __x; }
1117*38fd1498Szrj     };
1118*38fd1498Szrj 
1119*38fd1498Szrj   // Partial specialization, avoids confusing errors in e.g. std::set<const T>.
1120*38fd1498Szrj   template<typename _Tp> struct _Identity<const _Tp> : _Identity<_Tp> { };
1121*38fd1498Szrj 
1122*38fd1498Szrj   template<typename _Pair>
1123*38fd1498Szrj     struct _Select1st
1124*38fd1498Szrj     : public unary_function<_Pair, typename _Pair::first_type>
1125*38fd1498Szrj     {
1126*38fd1498Szrj       typename _Pair::first_type&
1127*38fd1498Szrj       operator()(_Pair& __x) const
1128*38fd1498Szrj       { return __x.first; }
1129*38fd1498Szrj 
1130*38fd1498Szrj       const typename _Pair::first_type&
1131*38fd1498Szrj       operator()(const _Pair& __x) const
1132*38fd1498Szrj       { return __x.first; }
1133*38fd1498Szrj 
1134*38fd1498Szrj #if __cplusplus >= 201103L
1135*38fd1498Szrj       template<typename _Pair2>
1136*38fd1498Szrj         typename _Pair2::first_type&
1137*38fd1498Szrj         operator()(_Pair2& __x) const
1138*38fd1498Szrj         { return __x.first; }
1139*38fd1498Szrj 
1140*38fd1498Szrj       template<typename _Pair2>
1141*38fd1498Szrj         const typename _Pair2::first_type&
1142*38fd1498Szrj         operator()(const _Pair2& __x) const
1143*38fd1498Szrj         { return __x.first; }
1144*38fd1498Szrj #endif
1145*38fd1498Szrj     };
1146*38fd1498Szrj 
1147*38fd1498Szrj   template<typename _Pair>
1148*38fd1498Szrj     struct _Select2nd
1149*38fd1498Szrj     : public unary_function<_Pair, typename _Pair::second_type>
1150*38fd1498Szrj     {
1151*38fd1498Szrj       typename _Pair::second_type&
1152*38fd1498Szrj       operator()(_Pair& __x) const
1153*38fd1498Szrj       { return __x.second; }
1154*38fd1498Szrj 
1155*38fd1498Szrj       const typename _Pair::second_type&
1156*38fd1498Szrj       operator()(const _Pair& __x) const
1157*38fd1498Szrj       { return __x.second; }
1158*38fd1498Szrj     };
1159*38fd1498Szrj 
1160*38fd1498Szrj   // 20.3.8 adaptors pointers members
1161*38fd1498Szrj   /** @defgroup memory_adaptors Adaptors for pointers to members
1162*38fd1498Szrj    * @ingroup functors
1163*38fd1498Szrj    *
1164*38fd1498Szrj    *  There are a total of 8 = 2^3 function objects in this family.
1165*38fd1498Szrj    *   (1) Member functions taking no arguments vs member functions taking
1166*38fd1498Szrj    *        one argument.
1167*38fd1498Szrj    *   (2) Call through pointer vs call through reference.
1168*38fd1498Szrj    *   (3) Const vs non-const member function.
1169*38fd1498Szrj    *
1170*38fd1498Szrj    *  All of this complexity is in the function objects themselves.  You can
1171*38fd1498Szrj    *   ignore it by using the helper function mem_fun and mem_fun_ref,
1172*38fd1498Szrj    *   which create whichever type of adaptor is appropriate.
1173*38fd1498Szrj    *
1174*38fd1498Szrj    *  @{
1175*38fd1498Szrj    */
1176*38fd1498Szrj   /// One of the @link memory_adaptors adaptors for member
1177*38fd1498Szrj   /// pointers@endlink.
1178*38fd1498Szrj   template<typename _Ret, typename _Tp>
1179*38fd1498Szrj     class mem_fun_t : public unary_function<_Tp*, _Ret>
1180*38fd1498Szrj     {
1181*38fd1498Szrj     public:
1182*38fd1498Szrj       explicit
1183*38fd1498Szrj       mem_fun_t(_Ret (_Tp::*__pf)())
1184*38fd1498Szrj       : _M_f(__pf) { }
1185*38fd1498Szrj 
1186*38fd1498Szrj       _Ret
1187*38fd1498Szrj       operator()(_Tp* __p) const
1188*38fd1498Szrj       { return (__p->*_M_f)(); }
1189*38fd1498Szrj 
1190*38fd1498Szrj     private:
1191*38fd1498Szrj       _Ret (_Tp::*_M_f)();
1192*38fd1498Szrj     };
1193*38fd1498Szrj 
1194*38fd1498Szrj   /// One of the @link memory_adaptors adaptors for member
1195*38fd1498Szrj   /// pointers@endlink.
1196*38fd1498Szrj   template<typename _Ret, typename _Tp>
1197*38fd1498Szrj     class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
1198*38fd1498Szrj     {
1199*38fd1498Szrj     public:
1200*38fd1498Szrj       explicit
1201*38fd1498Szrj       const_mem_fun_t(_Ret (_Tp::*__pf)() const)
1202*38fd1498Szrj       : _M_f(__pf) { }
1203*38fd1498Szrj 
1204*38fd1498Szrj       _Ret
1205*38fd1498Szrj       operator()(const _Tp* __p) const
1206*38fd1498Szrj       { return (__p->*_M_f)(); }
1207*38fd1498Szrj 
1208*38fd1498Szrj     private:
1209*38fd1498Szrj       _Ret (_Tp::*_M_f)() const;
1210*38fd1498Szrj     };
1211*38fd1498Szrj 
1212*38fd1498Szrj   /// One of the @link memory_adaptors adaptors for member
1213*38fd1498Szrj   /// pointers@endlink.
1214*38fd1498Szrj   template<typename _Ret, typename _Tp>
1215*38fd1498Szrj     class mem_fun_ref_t : public unary_function<_Tp, _Ret>
1216*38fd1498Szrj     {
1217*38fd1498Szrj     public:
1218*38fd1498Szrj       explicit
1219*38fd1498Szrj       mem_fun_ref_t(_Ret (_Tp::*__pf)())
1220*38fd1498Szrj       : _M_f(__pf) { }
1221*38fd1498Szrj 
1222*38fd1498Szrj       _Ret
1223*38fd1498Szrj       operator()(_Tp& __r) const
1224*38fd1498Szrj       { return (__r.*_M_f)(); }
1225*38fd1498Szrj 
1226*38fd1498Szrj     private:
1227*38fd1498Szrj       _Ret (_Tp::*_M_f)();
1228*38fd1498Szrj   };
1229*38fd1498Szrj 
1230*38fd1498Szrj   /// One of the @link memory_adaptors adaptors for member
1231*38fd1498Szrj   /// pointers@endlink.
1232*38fd1498Szrj   template<typename _Ret, typename _Tp>
1233*38fd1498Szrj     class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
1234*38fd1498Szrj     {
1235*38fd1498Szrj     public:
1236*38fd1498Szrj       explicit
1237*38fd1498Szrj       const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const)
1238*38fd1498Szrj       : _M_f(__pf) { }
1239*38fd1498Szrj 
1240*38fd1498Szrj       _Ret
1241*38fd1498Szrj       operator()(const _Tp& __r) const
1242*38fd1498Szrj       { return (__r.*_M_f)(); }
1243*38fd1498Szrj 
1244*38fd1498Szrj     private:
1245*38fd1498Szrj       _Ret (_Tp::*_M_f)() const;
1246*38fd1498Szrj     };
1247*38fd1498Szrj 
1248*38fd1498Szrj   /// One of the @link memory_adaptors adaptors for member
1249*38fd1498Szrj   /// pointers@endlink.
1250*38fd1498Szrj   template<typename _Ret, typename _Tp, typename _Arg>
1251*38fd1498Szrj     class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
1252*38fd1498Szrj     {
1253*38fd1498Szrj     public:
1254*38fd1498Szrj       explicit
1255*38fd1498Szrj       mem_fun1_t(_Ret (_Tp::*__pf)(_Arg))
1256*38fd1498Szrj       : _M_f(__pf) { }
1257*38fd1498Szrj 
1258*38fd1498Szrj       _Ret
1259*38fd1498Szrj       operator()(_Tp* __p, _Arg __x) const
1260*38fd1498Szrj       { return (__p->*_M_f)(__x); }
1261*38fd1498Szrj 
1262*38fd1498Szrj     private:
1263*38fd1498Szrj       _Ret (_Tp::*_M_f)(_Arg);
1264*38fd1498Szrj     };
1265*38fd1498Szrj 
1266*38fd1498Szrj   /// One of the @link memory_adaptors adaptors for member
1267*38fd1498Szrj   /// pointers@endlink.
1268*38fd1498Szrj   template<typename _Ret, typename _Tp, typename _Arg>
1269*38fd1498Szrj     class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
1270*38fd1498Szrj     {
1271*38fd1498Szrj     public:
1272*38fd1498Szrj       explicit
1273*38fd1498Szrj       const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const)
1274*38fd1498Szrj       : _M_f(__pf) { }
1275*38fd1498Szrj 
1276*38fd1498Szrj       _Ret
1277*38fd1498Szrj       operator()(const _Tp* __p, _Arg __x) const
1278*38fd1498Szrj       { return (__p->*_M_f)(__x); }
1279*38fd1498Szrj 
1280*38fd1498Szrj     private:
1281*38fd1498Szrj       _Ret (_Tp::*_M_f)(_Arg) const;
1282*38fd1498Szrj     };
1283*38fd1498Szrj 
1284*38fd1498Szrj   /// One of the @link memory_adaptors adaptors for member
1285*38fd1498Szrj   /// pointers@endlink.
1286*38fd1498Szrj   template<typename _Ret, typename _Tp, typename _Arg>
1287*38fd1498Szrj     class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
1288*38fd1498Szrj     {
1289*38fd1498Szrj     public:
1290*38fd1498Szrj       explicit
1291*38fd1498Szrj       mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg))
1292*38fd1498Szrj       : _M_f(__pf) { }
1293*38fd1498Szrj 
1294*38fd1498Szrj       _Ret
1295*38fd1498Szrj       operator()(_Tp& __r, _Arg __x) const
1296*38fd1498Szrj       { return (__r.*_M_f)(__x); }
1297*38fd1498Szrj 
1298*38fd1498Szrj     private:
1299*38fd1498Szrj       _Ret (_Tp::*_M_f)(_Arg);
1300*38fd1498Szrj     };
1301*38fd1498Szrj 
1302*38fd1498Szrj   /// One of the @link memory_adaptors adaptors for member
1303*38fd1498Szrj   /// pointers@endlink.
1304*38fd1498Szrj   template<typename _Ret, typename _Tp, typename _Arg>
1305*38fd1498Szrj     class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
1306*38fd1498Szrj     {
1307*38fd1498Szrj     public:
1308*38fd1498Szrj       explicit
1309*38fd1498Szrj       const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
1310*38fd1498Szrj       : _M_f(__pf) { }
1311*38fd1498Szrj 
1312*38fd1498Szrj       _Ret
1313*38fd1498Szrj       operator()(const _Tp& __r, _Arg __x) const
1314*38fd1498Szrj       { return (__r.*_M_f)(__x); }
1315*38fd1498Szrj 
1316*38fd1498Szrj     private:
1317*38fd1498Szrj       _Ret (_Tp::*_M_f)(_Arg) const;
1318*38fd1498Szrj     };
1319*38fd1498Szrj 
1320*38fd1498Szrj   // Mem_fun adaptor helper functions.  There are only two:
1321*38fd1498Szrj   // mem_fun and mem_fun_ref.
1322*38fd1498Szrj   template<typename _Ret, typename _Tp>
1323*38fd1498Szrj     inline mem_fun_t<_Ret, _Tp>
1324*38fd1498Szrj     mem_fun(_Ret (_Tp::*__f)())
1325*38fd1498Szrj     { return mem_fun_t<_Ret, _Tp>(__f); }
1326*38fd1498Szrj 
1327*38fd1498Szrj   template<typename _Ret, typename _Tp>
1328*38fd1498Szrj     inline const_mem_fun_t<_Ret, _Tp>
1329*38fd1498Szrj     mem_fun(_Ret (_Tp::*__f)() const)
1330*38fd1498Szrj     { return const_mem_fun_t<_Ret, _Tp>(__f); }
1331*38fd1498Szrj 
1332*38fd1498Szrj   template<typename _Ret, typename _Tp>
1333*38fd1498Szrj     inline mem_fun_ref_t<_Ret, _Tp>
1334*38fd1498Szrj     mem_fun_ref(_Ret (_Tp::*__f)())
1335*38fd1498Szrj     { return mem_fun_ref_t<_Ret, _Tp>(__f); }
1336*38fd1498Szrj 
1337*38fd1498Szrj   template<typename _Ret, typename _Tp>
1338*38fd1498Szrj     inline const_mem_fun_ref_t<_Ret, _Tp>
1339*38fd1498Szrj     mem_fun_ref(_Ret (_Tp::*__f)() const)
1340*38fd1498Szrj     { return const_mem_fun_ref_t<_Ret, _Tp>(__f); }
1341*38fd1498Szrj 
1342*38fd1498Szrj   template<typename _Ret, typename _Tp, typename _Arg>
1343*38fd1498Szrj     inline mem_fun1_t<_Ret, _Tp, _Arg>
1344*38fd1498Szrj     mem_fun(_Ret (_Tp::*__f)(_Arg))
1345*38fd1498Szrj     { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
1346*38fd1498Szrj 
1347*38fd1498Szrj   template<typename _Ret, typename _Tp, typename _Arg>
1348*38fd1498Szrj     inline const_mem_fun1_t<_Ret, _Tp, _Arg>
1349*38fd1498Szrj     mem_fun(_Ret (_Tp::*__f)(_Arg) const)
1350*38fd1498Szrj     { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
1351*38fd1498Szrj 
1352*38fd1498Szrj   template<typename _Ret, typename _Tp, typename _Arg>
1353*38fd1498Szrj     inline mem_fun1_ref_t<_Ret, _Tp, _Arg>
1354*38fd1498Szrj     mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
1355*38fd1498Szrj     { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
1356*38fd1498Szrj 
1357*38fd1498Szrj   template<typename _Ret, typename _Tp, typename _Arg>
1358*38fd1498Szrj     inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
1359*38fd1498Szrj     mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
1360*38fd1498Szrj     { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
1361*38fd1498Szrj 
1362*38fd1498Szrj   /** @}  */
1363*38fd1498Szrj 
1364*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
1365*38fd1498Szrj } // namespace
1366*38fd1498Szrj 
1367*38fd1498Szrj #if (__cplusplus < 201103L) || _GLIBCXX_USE_DEPRECATED
1368*38fd1498Szrj # include <backward/binders.h>
1369*38fd1498Szrj #endif
1370*38fd1498Szrj 
1371*38fd1498Szrj #endif /* _STL_FUNCTION_H */
1372