1 // Functor implementations -*- C++ -*-
3 // Copyright (C) 2001-2013 Free Software Foundation, Inc.
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)
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/>.
28 * Hewlett-Packard Company
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
39 * Copyright (c) 1996-1998
40 * Silicon Graphics Computer Systems, Inc.
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
51 /** @file bits/stl_function.h
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{functional}
56 #ifndef _STL_FUNCTION_H
57 #define _STL_FUNCTION_H 1
59 #if __cplusplus > 201103L
60 #include <bits/move.h>
63 namespace std
_GLIBCXX_VISIBILITY(default)
65 _GLIBCXX_BEGIN_NAMESPACE_VERSION
67 // 20.3.1 base classes
68 /** @defgroup functors Function Objects
71 * Function objects, or @e functors, are objects with an @c operator()
72 * defined and accessible. They can be passed as arguments to algorithm
73 * templates and used in place of a function pointer. Not only is the
74 * resulting expressiveness of the library increased, but the generated
75 * code can be more efficient than what you might write by hand. When we
76 * refer to @a functors, then, generally we include function pointers in
77 * the description as well.
79 * Often, functors are only created as temporaries passed to algorithm
80 * calls, rather than being created as named variables.
82 * Two examples taken from the standard itself follow. To perform a
83 * by-element addition of two vectors @c a and @c b containing @c double,
84 * and put the result in @c a, use
86 * transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
88 * To negate every element in @c a, use
90 * transform(a.begin(), a.end(), a.begin(), negate<double>());
92 * The addition and negation functions will be inlined directly.
94 * The standard functors are derived from structs named @c unary_function
95 * and @c binary_function. These two classes contain nothing but typedefs,
96 * to aid in generic (template) programming. If you write your own
97 * functors, you might consider doing the same.
102 * This is one of the @link functors functor base classes@endlink.
104 template<typename _Arg
, typename _Result
>
105 struct unary_function
107 /// @c argument_type is the type of the argument
108 typedef _Arg argument_type
;
110 /// @c result_type is the return type
111 typedef _Result result_type
;
115 * This is one of the @link functors functor base classes@endlink.
117 template<typename _Arg1
, typename _Arg2
, typename _Result
>
118 struct binary_function
120 /// @c first_argument_type is the type of the first argument
121 typedef _Arg1 first_argument_type
;
123 /// @c second_argument_type is the type of the second argument
124 typedef _Arg2 second_argument_type
;
126 /// @c result_type is the return type
127 typedef _Result result_type
;
132 /** @defgroup arithmetic_functors Arithmetic Classes
135 * Because basic math often needs to be done during an algorithm,
136 * the library provides functors for those operations. See the
137 * documentation for @link functors the base classes@endlink
138 * for examples of their use.
143 #if __cplusplus > 201103L
144 struct __is_transparent
; // undefined
146 template<typename _Tp
= void>
149 template<typename _Tp
= void>
152 template<typename _Tp
= void>
155 template<typename _Tp
= void>
158 template<typename _Tp
= void>
161 template<typename _Tp
= void>
165 /// One of the @link arithmetic_functors math functors@endlink.
166 template<typename _Tp
>
167 struct plus
: public binary_function
<_Tp
, _Tp
, _Tp
>
170 operator()(const _Tp
& __x
, const _Tp
& __y
) const
171 { return __x
+ __y
; }
174 /// One of the @link arithmetic_functors math functors@endlink.
175 template<typename _Tp
>
176 struct minus
: public binary_function
<_Tp
, _Tp
, _Tp
>
179 operator()(const _Tp
& __x
, const _Tp
& __y
) const
180 { return __x
- __y
; }
183 /// One of the @link arithmetic_functors math functors@endlink.
184 template<typename _Tp
>
185 struct multiplies
: public binary_function
<_Tp
, _Tp
, _Tp
>
188 operator()(const _Tp
& __x
, const _Tp
& __y
) const
189 { return __x
* __y
; }
192 /// One of the @link arithmetic_functors math functors@endlink.
193 template<typename _Tp
>
194 struct divides
: public binary_function
<_Tp
, _Tp
, _Tp
>
197 operator()(const _Tp
& __x
, const _Tp
& __y
) const
198 { return __x
/ __y
; }
201 /// One of the @link arithmetic_functors math functors@endlink.
202 template<typename _Tp
>
203 struct modulus
: public binary_function
<_Tp
, _Tp
, _Tp
>
206 operator()(const _Tp
& __x
, const _Tp
& __y
) const
207 { return __x
% __y
; }
210 /// One of the @link arithmetic_functors math functors@endlink.
211 template<typename _Tp
>
212 struct negate
: public unary_function
<_Tp
, _Tp
>
215 operator()(const _Tp
& __x
) const
219 #if __cplusplus > 201103L
223 template <typename _Tp
, typename _Up
>
225 operator()(_Tp
&& __t
, _Up
&& __u
) const
226 noexcept(noexcept(std::forward
<_Tp
>(__t
) + std::forward
<_Up
>(__u
)))
227 -> decltype(std::forward
<_Tp
>(__t
) + std::forward
<_Up
>(__u
))
228 { return std::forward
<_Tp
>(__t
) + std::forward
<_Up
>(__u
); }
230 typedef __is_transparent is_transparent
;
233 /// One of the @link arithmetic_functors math functors@endlink.
237 template <typename _Tp
, typename _Up
>
239 operator()(_Tp
&& __t
, _Up
&& __u
) const
240 noexcept(noexcept(std::forward
<_Tp
>(__t
) - std::forward
<_Up
>(__u
)))
241 -> decltype(std::forward
<_Tp
>(__t
) - std::forward
<_Up
>(__u
))
242 { return std::forward
<_Tp
>(__t
) - std::forward
<_Up
>(__u
); }
244 typedef __is_transparent is_transparent
;
247 /// One of the @link arithmetic_functors math functors@endlink.
249 struct multiplies
<void>
251 template <typename _Tp
, typename _Up
>
253 operator()(_Tp
&& __t
, _Up
&& __u
) const
254 noexcept(noexcept(std::forward
<_Tp
>(__t
) * std::forward
<_Up
>(__u
)))
255 -> decltype(std::forward
<_Tp
>(__t
) * std::forward
<_Up
>(__u
))
256 { return std::forward
<_Tp
>(__t
) * std::forward
<_Up
>(__u
); }
258 typedef __is_transparent is_transparent
;
261 /// One of the @link arithmetic_functors math functors@endlink.
265 template <typename _Tp
, typename _Up
>
267 operator()(_Tp
&& __t
, _Up
&& __u
) const
268 noexcept(noexcept(std::forward
<_Tp
>(__t
) / std::forward
<_Up
>(__u
)))
269 -> decltype(std::forward
<_Tp
>(__t
) / std::forward
<_Up
>(__u
))
270 { return std::forward
<_Tp
>(__t
) / std::forward
<_Up
>(__u
); }
272 typedef __is_transparent is_transparent
;
275 /// One of the @link arithmetic_functors math functors@endlink.
279 template <typename _Tp
, typename _Up
>
281 operator()(_Tp
&& __t
, _Up
&& __u
) const
282 noexcept(noexcept(std::forward
<_Tp
>(__t
) % std::forward
<_Up
>(__u
)))
283 -> decltype(std::forward
<_Tp
>(__t
) % std::forward
<_Up
>(__u
))
284 { return std::forward
<_Tp
>(__t
) % std::forward
<_Up
>(__u
); }
286 typedef __is_transparent is_transparent
;
289 /// One of the @link arithmetic_functors math functors@endlink.
293 template <typename _Tp
>
295 operator()(_Tp
&& __t
) const
296 noexcept(noexcept(-std::forward
<_Tp
>(__t
)))
297 -> decltype(-std::forward
<_Tp
>(__t
))
298 { return -std::forward
<_Tp
>(__t
); }
300 typedef __is_transparent is_transparent
;
305 // 20.3.3 comparisons
306 /** @defgroup comparison_functors Comparison Classes
309 * The library provides six wrapper functors for all the basic comparisons
314 #if __cplusplus > 201103L
315 template<typename _Tp
= void>
318 template<typename _Tp
= void>
321 template<typename _Tp
= void>
324 template<typename _Tp
= void>
327 template<typename _Tp
= void>
328 struct greater_equal
;
330 template<typename _Tp
= void>
334 /// One of the @link comparison_functors comparison functors@endlink.
335 template<typename _Tp
>
336 struct equal_to
: public binary_function
<_Tp
, _Tp
, bool>
339 operator()(const _Tp
& __x
, const _Tp
& __y
) const
340 { return __x
== __y
; }
343 /// One of the @link comparison_functors comparison functors@endlink.
344 template<typename _Tp
>
345 struct not_equal_to
: public binary_function
<_Tp
, _Tp
, bool>
348 operator()(const _Tp
& __x
, const _Tp
& __y
) const
349 { return __x
!= __y
; }
352 /// One of the @link comparison_functors comparison functors@endlink.
353 template<typename _Tp
>
354 struct greater
: public binary_function
<_Tp
, _Tp
, bool>
357 operator()(const _Tp
& __x
, const _Tp
& __y
) const
358 { return __x
> __y
; }
361 /// One of the @link comparison_functors comparison functors@endlink.
362 template<typename _Tp
>
363 struct less
: public binary_function
<_Tp
, _Tp
, bool>
366 operator()(const _Tp
& __x
, const _Tp
& __y
) const
367 { return __x
< __y
; }
370 /// One of the @link comparison_functors comparison functors@endlink.
371 template<typename _Tp
>
372 struct greater_equal
: public binary_function
<_Tp
, _Tp
, bool>
375 operator()(const _Tp
& __x
, const _Tp
& __y
) const
376 { return __x
>= __y
; }
379 /// One of the @link comparison_functors comparison functors@endlink.
380 template<typename _Tp
>
381 struct less_equal
: public binary_function
<_Tp
, _Tp
, bool>
384 operator()(const _Tp
& __x
, const _Tp
& __y
) const
385 { return __x
<= __y
; }
388 #if __cplusplus > 201103L
389 /// One of the @link comparison_functors comparison functors@endlink.
391 struct equal_to
<void>
393 template <typename _Tp
, typename _Up
>
395 operator()(_Tp
&& __t
, _Up
&& __u
) const
396 noexcept(noexcept(std::forward
<_Tp
>(__t
) == std::forward
<_Up
>(__u
)))
397 -> decltype(std::forward
<_Tp
>(__t
) == std::forward
<_Up
>(__u
))
398 { return std::forward
<_Tp
>(__t
) == std::forward
<_Up
>(__u
); }
400 typedef __is_transparent is_transparent
;
403 /// One of the @link comparison_functors comparison functors@endlink.
405 struct not_equal_to
<void>
407 template <typename _Tp
, typename _Up
>
409 operator()(_Tp
&& __t
, _Up
&& __u
) const
410 noexcept(noexcept(std::forward
<_Tp
>(__t
) != std::forward
<_Up
>(__u
)))
411 -> decltype(std::forward
<_Tp
>(__t
) != std::forward
<_Up
>(__u
))
412 { return std::forward
<_Tp
>(__t
) != std::forward
<_Up
>(__u
); }
414 typedef __is_transparent is_transparent
;
417 /// One of the @link comparison_functors comparison functors@endlink.
421 template <typename _Tp
, typename _Up
>
423 operator()(_Tp
&& __t
, _Up
&& __u
) const
424 noexcept(noexcept(std::forward
<_Tp
>(__t
) > std::forward
<_Up
>(__u
)))
425 -> decltype(std::forward
<_Tp
>(__t
) > std::forward
<_Up
>(__u
))
426 { return std::forward
<_Tp
>(__t
) > std::forward
<_Up
>(__u
); }
428 typedef __is_transparent is_transparent
;
431 /// One of the @link comparison_functors comparison functors@endlink.
435 template <typename _Tp
, typename _Up
>
437 operator()(_Tp
&& __t
, _Up
&& __u
) const
438 noexcept(noexcept(std::forward
<_Tp
>(__t
) < std::forward
<_Up
>(__u
)))
439 -> decltype(std::forward
<_Tp
>(__t
) < std::forward
<_Up
>(__u
))
440 { return std::forward
<_Tp
>(__t
) < std::forward
<_Up
>(__u
); }
442 typedef __is_transparent is_transparent
;
445 /// One of the @link comparison_functors comparison functors@endlink.
447 struct greater_equal
<void>
449 template <typename _Tp
, typename _Up
>
451 operator()(_Tp
&& __t
, _Up
&& __u
) const
452 noexcept(noexcept(std::forward
<_Tp
>(__t
) >= std::forward
<_Up
>(__u
)))
453 -> decltype(std::forward
<_Tp
>(__t
) >= std::forward
<_Up
>(__u
))
454 { return std::forward
<_Tp
>(__t
) >= std::forward
<_Up
>(__u
); }
456 typedef __is_transparent is_transparent
;
459 /// One of the @link comparison_functors comparison functors@endlink.
461 struct less_equal
<void>
463 template <typename _Tp
, typename _Up
>
465 operator()(_Tp
&& __t
, _Up
&& __u
) const
466 noexcept(noexcept(std::forward
<_Tp
>(__t
) <= std::forward
<_Up
>(__u
)))
467 -> decltype(std::forward
<_Tp
>(__t
) <= std::forward
<_Up
>(__u
))
468 { return std::forward
<_Tp
>(__t
) <= std::forward
<_Up
>(__u
); }
470 typedef __is_transparent is_transparent
;
475 // 20.3.4 logical operations
476 /** @defgroup logical_functors Boolean Operations Classes
479 * Here are wrapper functors for Boolean operations: @c &&, @c ||,
484 #if __cplusplus > 201103L
485 template<typename _Tp
= void>
488 template<typename _Tp
= void>
491 template<typename _Tp
= void>
495 /// One of the @link logical_functors Boolean operations functors@endlink.
496 template<typename _Tp
>
497 struct logical_and
: public binary_function
<_Tp
, _Tp
, bool>
500 operator()(const _Tp
& __x
, const _Tp
& __y
) const
501 { return __x
&& __y
; }
504 /// One of the @link logical_functors Boolean operations functors@endlink.
505 template<typename _Tp
>
506 struct logical_or
: public binary_function
<_Tp
, _Tp
, bool>
509 operator()(const _Tp
& __x
, const _Tp
& __y
) const
510 { return __x
|| __y
; }
513 /// One of the @link logical_functors Boolean operations functors@endlink.
514 template<typename _Tp
>
515 struct logical_not
: public unary_function
<_Tp
, bool>
518 operator()(const _Tp
& __x
) const
522 #if __cplusplus > 201103L
523 /// One of the @link logical_functors Boolean operations functors@endlink.
525 struct logical_and
<void>
527 template <typename _Tp
, typename _Up
>
529 operator()(_Tp
&& __t
, _Up
&& __u
) const
530 noexcept(noexcept(std::forward
<_Tp
>(__t
) && std::forward
<_Up
>(__u
)))
531 -> decltype(std::forward
<_Tp
>(__t
) && std::forward
<_Up
>(__u
))
532 { return std::forward
<_Tp
>(__t
) && std::forward
<_Up
>(__u
); }
534 typedef __is_transparent is_transparent
;
537 /// One of the @link logical_functors Boolean operations functors@endlink.
539 struct logical_or
<void>
541 template <typename _Tp
, typename _Up
>
543 operator()(_Tp
&& __t
, _Up
&& __u
) const
544 noexcept(noexcept(std::forward
<_Tp
>(__t
) || std::forward
<_Up
>(__u
)))
545 -> decltype(std::forward
<_Tp
>(__t
) || std::forward
<_Up
>(__u
))
546 { return std::forward
<_Tp
>(__t
) || std::forward
<_Up
>(__u
); }
548 typedef __is_transparent is_transparent
;
551 /// One of the @link logical_functors Boolean operations functors@endlink.
553 struct logical_not
<void>
555 template <typename _Tp
>
557 operator()(_Tp
&& __t
) const -> decltype(!std::forward
<_Tp
>(__t
))
558 { return !std::forward
<_Tp
>(__t
); }
560 typedef __is_transparent is_transparent
;
565 #if __cplusplus > 201103L
566 template<typename _Tp
= void>
569 template<typename _Tp
= void>
572 template<typename _Tp
= void>
575 template<typename _Tp
= void>
579 // _GLIBCXX_RESOLVE_LIB_DEFECTS
580 // DR 660. Missing Bitwise Operations.
581 template<typename _Tp
>
582 struct bit_and
: public binary_function
<_Tp
, _Tp
, _Tp
>
585 operator()(const _Tp
& __x
, const _Tp
& __y
) const
586 { return __x
& __y
; }
589 template<typename _Tp
>
590 struct bit_or
: public binary_function
<_Tp
, _Tp
, _Tp
>
593 operator()(const _Tp
& __x
, const _Tp
& __y
) const
594 { return __x
| __y
; }
597 template<typename _Tp
>
598 struct bit_xor
: public binary_function
<_Tp
, _Tp
, _Tp
>
601 operator()(const _Tp
& __x
, const _Tp
& __y
) const
602 { return __x
^ __y
; }
605 template<typename _Tp
>
606 struct bit_not
: public unary_function
<_Tp
, _Tp
>
609 operator()(const _Tp
& __x
) const
613 #if __cplusplus > 201103L
617 template <typename _Tp
, typename _Up
>
619 operator()(_Tp
&& __t
, _Up
&& __u
) const
620 noexcept(noexcept(std::forward
<_Tp
>(__t
) & std::forward
<_Up
>(__u
)))
621 -> decltype(std::forward
<_Tp
>(__t
) & std::forward
<_Up
>(__u
))
622 { return std::forward
<_Tp
>(__t
) & std::forward
<_Up
>(__u
); }
624 typedef __is_transparent is_transparent
;
630 template <typename _Tp
, typename _Up
>
632 operator()(_Tp
&& __t
, _Up
&& __u
) const
633 noexcept(noexcept(std::forward
<_Tp
>(__t
) | std::forward
<_Up
>(__u
)))
634 -> decltype(std::forward
<_Tp
>(__t
) | std::forward
<_Up
>(__u
))
635 { return std::forward
<_Tp
>(__t
) | std::forward
<_Up
>(__u
); }
637 typedef __is_transparent is_transparent
;
643 template <typename _Tp
, typename _Up
>
645 operator()(_Tp
&& __t
, _Up
&& __u
) const
646 noexcept(noexcept(std::forward
<_Tp
>(__t
) ^ std::forward
<_Up
>(__u
)))
647 -> decltype(std::forward
<_Tp
>(__t
) ^ std::forward
<_Up
>(__u
))
648 { return std::forward
<_Tp
>(__t
) ^ std::forward
<_Up
>(__u
); }
650 typedef __is_transparent is_transparent
;
656 template <typename _Tp
>
658 operator()(_Tp
&& __t
) const
659 noexcept(noexcept(~std::forward
<_Tp
>(__t
)))
660 -> decltype(~std::forward
<_Tp
>(__t
))
661 { return ~std::forward
<_Tp
>(__t
); }
663 typedef __is_transparent is_transparent
;
668 /** @defgroup negators Negators
671 * The functions @c not1 and @c not2 each take a predicate functor
672 * and return an instance of @c unary_negate or
673 * @c binary_negate, respectively. These classes are functors whose
674 * @c operator() performs the stored predicate function and then returns
675 * the negation of the result.
677 * For example, given a vector of integers and a trivial predicate,
679 * struct IntGreaterThanThree
680 * : public std::unary_function<int, bool>
682 * bool operator() (int x) { return x > 3; }
685 * std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
687 * The call to @c find_if will locate the first index (i) of @c v for which
688 * <code>!(v[i] > 3)</code> is true.
690 * The not1/unary_negate combination works on predicates taking a single
691 * argument. The not2/binary_negate combination works on predicates which
692 * take two arguments.
696 /// One of the @link negators negation functors@endlink.
697 template<typename _Predicate
>
699 : public unary_function
<typename
_Predicate::argument_type
, bool>
706 unary_negate(const _Predicate
& __x
) : _M_pred(__x
) { }
709 operator()(const typename
_Predicate::argument_type
& __x
) const
710 { return !_M_pred(__x
); }
713 /// One of the @link negators negation functors@endlink.
714 template<typename _Predicate
>
715 inline unary_negate
<_Predicate
>
716 not1(const _Predicate
& __pred
)
717 { return unary_negate
<_Predicate
>(__pred
); }
719 /// One of the @link negators negation functors@endlink.
720 template<typename _Predicate
>
722 : public binary_function
<typename
_Predicate::first_argument_type
,
723 typename
_Predicate::second_argument_type
, bool>
730 binary_negate(const _Predicate
& __x
) : _M_pred(__x
) { }
733 operator()(const typename
_Predicate::first_argument_type
& __x
,
734 const typename
_Predicate::second_argument_type
& __y
) const
735 { return !_M_pred(__x
, __y
); }
738 /// One of the @link negators negation functors@endlink.
739 template<typename _Predicate
>
740 inline binary_negate
<_Predicate
>
741 not2(const _Predicate
& __pred
)
742 { return binary_negate
<_Predicate
>(__pred
); }
745 // 20.3.7 adaptors pointers functions
746 /** @defgroup pointer_adaptors Adaptors for pointers to functions
749 * The advantage of function objects over pointers to functions is that
750 * the objects in the standard library declare nested typedefs describing
751 * their argument and result types with uniform names (e.g., @c result_type
752 * from the base classes @c unary_function and @c binary_function).
753 * Sometimes those typedefs are required, not just optional.
755 * Adaptors are provided to turn pointers to unary (single-argument) and
756 * binary (double-argument) functions into function objects. The
757 * long-winded functor @c pointer_to_unary_function is constructed with a
758 * function pointer @c f, and its @c operator() called with argument @c x
759 * returns @c f(x). The functor @c pointer_to_binary_function does the same
760 * thing, but with a double-argument @c f and @c operator().
762 * The function @c ptr_fun takes a pointer-to-function @c f and constructs
763 * an instance of the appropriate functor.
767 /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
768 template<typename _Arg
, typename _Result
>
769 class pointer_to_unary_function
: public unary_function
<_Arg
, _Result
>
772 _Result (*_M_ptr
)(_Arg
);
775 pointer_to_unary_function() { }
778 pointer_to_unary_function(_Result (*__x
)(_Arg
))
782 operator()(_Arg __x
) const
783 { return _M_ptr(__x
); }
786 /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
787 template<typename _Arg
, typename _Result
>
788 inline pointer_to_unary_function
<_Arg
, _Result
>
789 ptr_fun(_Result (*__x
)(_Arg
))
790 { return pointer_to_unary_function
<_Arg
, _Result
>(__x
); }
792 /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
793 template<typename _Arg1
, typename _Arg2
, typename _Result
>
794 class pointer_to_binary_function
795 : public binary_function
<_Arg1
, _Arg2
, _Result
>
798 _Result (*_M_ptr
)(_Arg1
, _Arg2
);
801 pointer_to_binary_function() { }
804 pointer_to_binary_function(_Result (*__x
)(_Arg1
, _Arg2
))
808 operator()(_Arg1 __x
, _Arg2 __y
) const
809 { return _M_ptr(__x
, __y
); }
812 /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
813 template<typename _Arg1
, typename _Arg2
, typename _Result
>
814 inline pointer_to_binary_function
<_Arg1
, _Arg2
, _Result
>
815 ptr_fun(_Result (*__x
)(_Arg1
, _Arg2
))
816 { return pointer_to_binary_function
<_Arg1
, _Arg2
, _Result
>(__x
); }
819 template<typename _Tp
>
821 : public unary_function
<_Tp
,_Tp
>
824 operator()(_Tp
& __x
) const
828 operator()(const _Tp
& __x
) const
832 template<typename _Pair
>
834 : public unary_function
<_Pair
, typename
_Pair::first_type
>
836 typename
_Pair::first_type
&
837 operator()(_Pair
& __x
) const
838 { return __x
.first
; }
840 const typename
_Pair::first_type
&
841 operator()(const _Pair
& __x
) const
842 { return __x
.first
; }
844 #if __cplusplus >= 201103L
845 template<typename _Pair2
>
846 typename
_Pair2::first_type
&
847 operator()(_Pair2
& __x
) const
848 { return __x
.first
; }
850 template<typename _Pair2
>
851 const typename
_Pair2::first_type
&
852 operator()(const _Pair2
& __x
) const
853 { return __x
.first
; }
857 template<typename _Pair
>
859 : public unary_function
<_Pair
, typename
_Pair::second_type
>
861 typename
_Pair::second_type
&
862 operator()(_Pair
& __x
) const
863 { return __x
.second
; }
865 const typename
_Pair::second_type
&
866 operator()(const _Pair
& __x
) const
867 { return __x
.second
; }
870 // 20.3.8 adaptors pointers members
871 /** @defgroup memory_adaptors Adaptors for pointers to members
874 * There are a total of 8 = 2^3 function objects in this family.
875 * (1) Member functions taking no arguments vs member functions taking
877 * (2) Call through pointer vs call through reference.
878 * (3) Const vs non-const member function.
880 * All of this complexity is in the function objects themselves. You can
881 * ignore it by using the helper function mem_fun and mem_fun_ref,
882 * which create whichever type of adaptor is appropriate.
886 /// One of the @link memory_adaptors adaptors for member
887 /// pointers@endlink.
888 template<typename _Ret
, typename _Tp
>
889 class mem_fun_t
: public unary_function
<_Tp
*, _Ret
>
893 mem_fun_t(_Ret (_Tp::*__pf
)())
897 operator()(_Tp
* __p
) const
898 { return (__p
->*_M_f
)(); }
904 /// One of the @link memory_adaptors adaptors for member
905 /// pointers@endlink.
906 template<typename _Ret
, typename _Tp
>
907 class const_mem_fun_t
: public unary_function
<const _Tp
*, _Ret
>
911 const_mem_fun_t(_Ret (_Tp::*__pf
)() const)
915 operator()(const _Tp
* __p
) const
916 { return (__p
->*_M_f
)(); }
919 _Ret (_Tp::*_M_f
)() const;
922 /// One of the @link memory_adaptors adaptors for member
923 /// pointers@endlink.
924 template<typename _Ret
, typename _Tp
>
925 class mem_fun_ref_t
: public unary_function
<_Tp
, _Ret
>
929 mem_fun_ref_t(_Ret (_Tp::*__pf
)())
933 operator()(_Tp
& __r
) const
934 { return (__r
.*_M_f
)(); }
940 /// One of the @link memory_adaptors adaptors for member
941 /// pointers@endlink.
942 template<typename _Ret
, typename _Tp
>
943 class const_mem_fun_ref_t
: public unary_function
<_Tp
, _Ret
>
947 const_mem_fun_ref_t(_Ret (_Tp::*__pf
)() const)
951 operator()(const _Tp
& __r
) const
952 { return (__r
.*_M_f
)(); }
955 _Ret (_Tp::*_M_f
)() const;
958 /// One of the @link memory_adaptors adaptors for member
959 /// pointers@endlink.
960 template<typename _Ret
, typename _Tp
, typename _Arg
>
961 class mem_fun1_t
: public binary_function
<_Tp
*, _Arg
, _Ret
>
965 mem_fun1_t(_Ret (_Tp::*__pf
)(_Arg
))
969 operator()(_Tp
* __p
, _Arg __x
) const
970 { return (__p
->*_M_f
)(__x
); }
973 _Ret (_Tp::*_M_f
)(_Arg
);
976 /// One of the @link memory_adaptors adaptors for member
977 /// pointers@endlink.
978 template<typename _Ret
, typename _Tp
, typename _Arg
>
979 class const_mem_fun1_t
: public binary_function
<const _Tp
*, _Arg
, _Ret
>
983 const_mem_fun1_t(_Ret (_Tp::*__pf
)(_Arg
) const)
987 operator()(const _Tp
* __p
, _Arg __x
) const
988 { return (__p
->*_M_f
)(__x
); }
991 _Ret (_Tp::*_M_f
)(_Arg
) const;
994 /// One of the @link memory_adaptors adaptors for member
995 /// pointers@endlink.
996 template<typename _Ret
, typename _Tp
, typename _Arg
>
997 class mem_fun1_ref_t
: public binary_function
<_Tp
, _Arg
, _Ret
>
1001 mem_fun1_ref_t(_Ret (_Tp::*__pf
)(_Arg
))
1005 operator()(_Tp
& __r
, _Arg __x
) const
1006 { return (__r
.*_M_f
)(__x
); }
1009 _Ret (_Tp::*_M_f
)(_Arg
);
1012 /// One of the @link memory_adaptors adaptors for member
1013 /// pointers@endlink.
1014 template<typename _Ret
, typename _Tp
, typename _Arg
>
1015 class const_mem_fun1_ref_t
: public binary_function
<_Tp
, _Arg
, _Ret
>
1019 const_mem_fun1_ref_t(_Ret (_Tp::*__pf
)(_Arg
) const)
1023 operator()(const _Tp
& __r
, _Arg __x
) const
1024 { return (__r
.*_M_f
)(__x
); }
1027 _Ret (_Tp::*_M_f
)(_Arg
) const;
1030 // Mem_fun adaptor helper functions. There are only two:
1031 // mem_fun and mem_fun_ref.
1032 template<typename _Ret
, typename _Tp
>
1033 inline mem_fun_t
<_Ret
, _Tp
>
1034 mem_fun(_Ret (_Tp::*__f
)())
1035 { return mem_fun_t
<_Ret
, _Tp
>(__f
); }
1037 template<typename _Ret
, typename _Tp
>
1038 inline const_mem_fun_t
<_Ret
, _Tp
>
1039 mem_fun(_Ret (_Tp::*__f
)() const)
1040 { return const_mem_fun_t
<_Ret
, _Tp
>(__f
); }
1042 template<typename _Ret
, typename _Tp
>
1043 inline mem_fun_ref_t
<_Ret
, _Tp
>
1044 mem_fun_ref(_Ret (_Tp::*__f
)())
1045 { return mem_fun_ref_t
<_Ret
, _Tp
>(__f
); }
1047 template<typename _Ret
, typename _Tp
>
1048 inline const_mem_fun_ref_t
<_Ret
, _Tp
>
1049 mem_fun_ref(_Ret (_Tp::*__f
)() const)
1050 { return const_mem_fun_ref_t
<_Ret
, _Tp
>(__f
); }
1052 template<typename _Ret
, typename _Tp
, typename _Arg
>
1053 inline mem_fun1_t
<_Ret
, _Tp
, _Arg
>
1054 mem_fun(_Ret (_Tp::*__f
)(_Arg
))
1055 { return mem_fun1_t
<_Ret
, _Tp
, _Arg
>(__f
); }
1057 template<typename _Ret
, typename _Tp
, typename _Arg
>
1058 inline const_mem_fun1_t
<_Ret
, _Tp
, _Arg
>
1059 mem_fun(_Ret (_Tp::*__f
)(_Arg
) const)
1060 { return const_mem_fun1_t
<_Ret
, _Tp
, _Arg
>(__f
); }
1062 template<typename _Ret
, typename _Tp
, typename _Arg
>
1063 inline mem_fun1_ref_t
<_Ret
, _Tp
, _Arg
>
1064 mem_fun_ref(_Ret (_Tp::*__f
)(_Arg
))
1065 { return mem_fun1_ref_t
<_Ret
, _Tp
, _Arg
>(__f
); }
1067 template<typename _Ret
, typename _Tp
, typename _Arg
>
1068 inline const_mem_fun1_ref_t
<_Ret
, _Tp
, _Arg
>
1069 mem_fun_ref(_Ret (_Tp::*__f
)(_Arg
) const)
1070 { return const_mem_fun1_ref_t
<_Ret
, _Tp
, _Arg
>(__f
); }
1074 _GLIBCXX_END_NAMESPACE_VERSION
1077 #if (__cplusplus < 201103L) || _GLIBCXX_USE_DEPRECATED
1078 # include <backward/binders.h>
1081 #endif /* _STL_FUNCTION_H */