1e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// Functor implementations -*- C++ -*-
2e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
3e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
4e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// 2011, 2012
5e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// Free Software Foundation, Inc.
6e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh//
7e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// This file is part of the GNU ISO C++ Library.  This library is free
8e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// software; you can redistribute it and/or modify it under the
9e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// terms of the GNU General Public License as published by the
10e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// Free Software Foundation; either version 3, or (at your option)
11e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// any later version.
12e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
13e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// This library is distributed in the hope that it will be useful,
14e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// but WITHOUT ANY WARRANTY; without even the implied warranty of
15e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// GNU General Public License for more details.
17e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
18e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// Under Section 7 of GPL version 3, you are granted additional
19e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// permissions described in the GCC Runtime Library Exception, version
20e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// 3.1, as published by the Free Software Foundation.
21e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
22e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// You should have received a copy of the GNU General Public License and
23e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// a copy of the GCC Runtime Library Exception along with this program;
24e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
25e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// <http://www.gnu.org/licenses/>.
26e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
27e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh/*
28e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh *
29e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * Copyright (c) 1994
30e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * Hewlett-Packard Company
31e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh *
32e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * Permission to use, copy, modify, distribute and sell this software
33e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * and its documentation for any purpose is hereby granted without fee,
34e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * provided that the above copyright notice appear in all copies and
35e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * that both that copyright notice and this permission notice appear
36e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * in supporting documentation.  Hewlett-Packard Company makes no
37e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * representations about the suitability of this software for any
38e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * purpose.  It is provided "as is" without express or implied warranty.
39e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh *
40e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh *
41e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * Copyright (c) 1996-1998
42e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * Silicon Graphics Computer Systems, Inc.
43e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh *
44e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * Permission to use, copy, modify, distribute and sell this software
45e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * and its documentation for any purpose is hereby granted without fee,
46e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * provided that the above copyright notice appear in all copies and
47e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * that both that copyright notice and this permission notice appear
48e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * in supporting documentation.  Silicon Graphics makes no
49e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * representations about the suitability of this software for any
50e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * purpose.  It is provided "as is" without express or implied warranty.
51e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh */
52e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
53e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh/** @file bits/stl_function.h
54e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh *  This is an internal header file, included by other library headers.
55e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh *  Do not attempt to use it directly. @headername{functional}
56e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh */
57e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
58e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#ifndef _STL_FUNCTION_H
59e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#define _STL_FUNCTION_H 1
60e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
61e7de7d971409d955ca138406d5062499bc554451Andrew Hsiehnamespace std _GLIBCXX_VISIBILITY(default)
62e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh{
63e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh_GLIBCXX_BEGIN_NAMESPACE_VERSION
64e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
65e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  // 20.3.1 base classes
66e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @defgroup functors Function Objects
67e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   * @ingroup utilities
68e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
69e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  Function objects, or @e functors, are objects with an @c operator()
70e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  defined and accessible.  They can be passed as arguments to algorithm
71e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  templates and used in place of a function pointer.  Not only is the
72e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  resulting expressiveness of the library increased, but the generated
73e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  code can be more efficient than what you might write by hand.  When we
74e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  refer to @a functors, then, generally we include function pointers in
75e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  the description as well.
76e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
77e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  Often, functors are only created as temporaries passed to algorithm
78e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  calls, rather than being created as named variables.
79e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
80e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  Two examples taken from the standard itself follow.  To perform a
81e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  by-element addition of two vectors @c a and @c b containing @c double,
82e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  and put the result in @c a, use
83e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  \code
84e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
85e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  \endcode
86e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  To negate every element in @c a, use
87e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  \code
88e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  transform(a.begin(), a.end(), a.begin(), negate<double>());
89e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  \endcode
90e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  The addition and negation functions will be inlined directly.
91e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
92e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  The standard functors are derived from structs named @c unary_function
93e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  and @c binary_function.  These two classes contain nothing but typedefs,
94e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  to aid in generic (template) programming.  If you write your own
95e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  functors, you might consider doing the same.
96e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
97e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  @{
98e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   */
99e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /**
100e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  This is one of the @link functors functor base classes@endlink.
101e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   */
102e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Arg, typename _Result>
103e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct unary_function
104e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
105e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      /// @c argument_type is the type of the argument
106e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      typedef _Arg 	argument_type;
107e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
108e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      /// @c result_type is the return type
109e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      typedef _Result 	result_type;
110e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
111e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
112e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /**
113e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  This is one of the @link functors functor base classes@endlink.
114e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   */
115e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Arg1, typename _Arg2, typename _Result>
116e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct binary_function
117e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
118e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      /// @c first_argument_type is the type of the first argument
119e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      typedef _Arg1 	first_argument_type;
120e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
121e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      /// @c second_argument_type is the type of the second argument
122e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      typedef _Arg2 	second_argument_type;
123e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
124e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      /// @c result_type is the return type
125e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      typedef _Result 	result_type;
126e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
127e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @}  */
128e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
129e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  // 20.3.2 arithmetic
130e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @defgroup arithmetic_functors Arithmetic Classes
131e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   * @ingroup functors
132e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
133e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  Because basic math often needs to be done during an algorithm,
134e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  the library provides functors for those operations.  See the
135e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  documentation for @link functors the base classes@endlink
136e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  for examples of their use.
137e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
138e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  @{
139e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   */
140e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link arithmetic_functors math functors@endlink.
141e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
142e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct plus : public binary_function<_Tp, _Tp, _Tp>
143e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
144e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Tp
145e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
146e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x + __y; }
147e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
148e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
149e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link arithmetic_functors math functors@endlink.
150e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
151e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct minus : public binary_function<_Tp, _Tp, _Tp>
152e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
153e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Tp
154e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
155e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x - __y; }
156e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
157e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
158e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link arithmetic_functors math functors@endlink.
159e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
160e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct multiplies : public binary_function<_Tp, _Tp, _Tp>
161e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
162e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Tp
163e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
164e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x * __y; }
165e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
166e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
167e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link arithmetic_functors math functors@endlink.
168e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
169e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct divides : public binary_function<_Tp, _Tp, _Tp>
170e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
171e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Tp
172e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
173e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x / __y; }
174e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
175e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
176e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link arithmetic_functors math functors@endlink.
177e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
178e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct modulus : public binary_function<_Tp, _Tp, _Tp>
179e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
180e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Tp
181e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
182e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x % __y; }
183e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
184e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
185e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link arithmetic_functors math functors@endlink.
186e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
187e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct negate : public unary_function<_Tp, _Tp>
188e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
189e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Tp
190e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x) const
191e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return -__x; }
192e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
193e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @}  */
194e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
195e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  // 20.3.3 comparisons
196e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @defgroup comparison_functors Comparison Classes
197e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   * @ingroup functors
198e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
199e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  The library provides six wrapper functors for all the basic comparisons
200e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  in C++, like @c <.
201e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
202e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  @{
203e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   */
204e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link comparison_functors comparison functors@endlink.
205e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
206e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct equal_to : public binary_function<_Tp, _Tp, bool>
207e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
208e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      bool
209e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
210e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x == __y; }
211e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
212e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
213e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link comparison_functors comparison functors@endlink.
214e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
215e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct not_equal_to : public binary_function<_Tp, _Tp, bool>
216e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
217e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      bool
218e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
219e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x != __y; }
220e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
221e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
222e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link comparison_functors comparison functors@endlink.
223e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
224e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct greater : public binary_function<_Tp, _Tp, bool>
225e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
226e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      bool
227e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
228e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x > __y; }
229e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
230e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
231e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link comparison_functors comparison functors@endlink.
232e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
233e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct less : public binary_function<_Tp, _Tp, bool>
234e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
235e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      bool
236e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
237e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x < __y; }
238e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
239e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
240e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link comparison_functors comparison functors@endlink.
241e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
242e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct greater_equal : public binary_function<_Tp, _Tp, bool>
243e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
244e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      bool
245e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
246e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x >= __y; }
247e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
248e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
249e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link comparison_functors comparison functors@endlink.
250e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
251e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct less_equal : public binary_function<_Tp, _Tp, bool>
252e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
253e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      bool
254e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
255e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x <= __y; }
256e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
257e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @}  */
258e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
259e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  // 20.3.4 logical operations
260e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @defgroup logical_functors Boolean Operations Classes
261e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   * @ingroup functors
262e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
263e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  Here are wrapper functors for Boolean operations: @c &&, @c ||,
264e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  and @c !.
265e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
266e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  @{
267e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   */
268e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link logical_functors Boolean operations functors@endlink.
269e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
270e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct logical_and : public binary_function<_Tp, _Tp, bool>
271e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
272e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      bool
273e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
274e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x && __y; }
275e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
276e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
277e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link logical_functors Boolean operations functors@endlink.
278e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
279e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct logical_or : public binary_function<_Tp, _Tp, bool>
280e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
281e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      bool
282e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
283e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x || __y; }
284e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
285e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
286e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link logical_functors Boolean operations functors@endlink.
287e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
288e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct logical_not : public unary_function<_Tp, bool>
289e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
290e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      bool
291e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x) const
292e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return !__x; }
293e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
294e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @}  */
295e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
296e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  // _GLIBCXX_RESOLVE_LIB_DEFECTS
297e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  // DR 660. Missing Bitwise Operations.
298e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
299e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct bit_and : public binary_function<_Tp, _Tp, _Tp>
300e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
301e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Tp
302e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
303e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x & __y; }
304e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
305e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
306e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
307e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct bit_or : public binary_function<_Tp, _Tp, _Tp>
308e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
309e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Tp
310e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
311e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x | __y; }
312e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
313e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
314e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
315e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct bit_xor : public binary_function<_Tp, _Tp, _Tp>
316e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
317e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Tp
318e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x, const _Tp& __y) const
319e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x ^ __y; }
320e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
321e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
322e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  // 20.3.5 negators
323e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @defgroup negators Negators
324e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   * @ingroup functors
325e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
326e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  The functions @c not1 and @c not2 each take a predicate functor
327e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  and return an instance of @c unary_negate or
328e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  @c binary_negate, respectively.  These classes are functors whose
329e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  @c operator() performs the stored predicate function and then returns
330e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  the negation of the result.
331e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
332e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  For example, given a vector of integers and a trivial predicate,
333e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  \code
334e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  struct IntGreaterThanThree
335e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *    : public std::unary_function<int, bool>
336e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  {
337e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *      bool operator() (int x) { return x > 3; }
338e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  };
339e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
340e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
341e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  \endcode
342e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  The call to @c find_if will locate the first index (i) of @c v for which
343e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  <code>!(v[i] > 3)</code> is true.
344e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
345e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  The not1/unary_negate combination works on predicates taking a single
346e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  argument.  The not2/binary_negate combination works on predicates which
347e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  take two arguments.
348e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
349e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  @{
350e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   */
351e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link negators negation functors@endlink.
352e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Predicate>
353e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class unary_negate
354e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    : public unary_function<typename _Predicate::argument_type, bool>
355e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
356e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    protected:
357e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Predicate _M_pred;
358e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
359e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
360e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
361e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      unary_negate(const _Predicate& __x) : _M_pred(__x) { }
362e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
363e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      bool
364e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const typename _Predicate::argument_type& __x) const
365e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return !_M_pred(__x); }
366e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
367e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
368e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link negators negation functors@endlink.
369e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Predicate>
370e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline unary_negate<_Predicate>
371e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    not1(const _Predicate& __pred)
372e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return unary_negate<_Predicate>(__pred); }
373e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
374e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link negators negation functors@endlink.
375e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Predicate>
376e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class binary_negate
377e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    : public binary_function<typename _Predicate::first_argument_type,
378e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh			     typename _Predicate::second_argument_type, bool>
379e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
380e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    protected:
381e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Predicate _M_pred;
382e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
383e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
384e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
385e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      binary_negate(const _Predicate& __x) : _M_pred(__x) { }
386e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
387e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      bool
388e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const typename _Predicate::first_argument_type& __x,
389e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh		 const typename _Predicate::second_argument_type& __y) const
390e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return !_M_pred(__x, __y); }
391e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
392e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
393e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link negators negation functors@endlink.
394e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Predicate>
395e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline binary_negate<_Predicate>
396e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    not2(const _Predicate& __pred)
397e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return binary_negate<_Predicate>(__pred); }
398e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @}  */
399e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
400e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  // 20.3.7 adaptors pointers functions
401e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @defgroup pointer_adaptors Adaptors for pointers to functions
402e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   * @ingroup functors
403e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
404e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  The advantage of function objects over pointers to functions is that
405e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  the objects in the standard library declare nested typedefs describing
406e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  their argument and result types with uniform names (e.g., @c result_type
407e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  from the base classes @c unary_function and @c binary_function).
408e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  Sometimes those typedefs are required, not just optional.
409e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
410e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  Adaptors are provided to turn pointers to unary (single-argument) and
411e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  binary (double-argument) functions into function objects.  The
412e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  long-winded functor @c pointer_to_unary_function is constructed with a
413e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  function pointer @c f, and its @c operator() called with argument @c x
414e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  returns @c f(x).  The functor @c pointer_to_binary_function does the same
415e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  thing, but with a double-argument @c f and @c operator().
416e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
417e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  The function @c ptr_fun takes a pointer-to-function @c f and constructs
418e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  an instance of the appropriate functor.
419e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
420e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  @{
421e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   */
422e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
423e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Arg, typename _Result>
424e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class pointer_to_unary_function : public unary_function<_Arg, _Result>
425e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
426e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    protected:
427e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Result (*_M_ptr)(_Arg);
428e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
429e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
430e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      pointer_to_unary_function() { }
431e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
432e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
433e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      pointer_to_unary_function(_Result (*__x)(_Arg))
434e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      : _M_ptr(__x) { }
435e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
436e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Result
437e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(_Arg __x) const
438e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return _M_ptr(__x); }
439e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
440e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
441e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
442e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Arg, typename _Result>
443e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline pointer_to_unary_function<_Arg, _Result>
444e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    ptr_fun(_Result (*__x)(_Arg))
445e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return pointer_to_unary_function<_Arg, _Result>(__x); }
446e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
447e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
448e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Arg1, typename _Arg2, typename _Result>
449e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class pointer_to_binary_function
450e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    : public binary_function<_Arg1, _Arg2, _Result>
451e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
452e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    protected:
453e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Result (*_M_ptr)(_Arg1, _Arg2);
454e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
455e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
456e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      pointer_to_binary_function() { }
457e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
458e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
459e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
460e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      : _M_ptr(__x) { }
461e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
462e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Result
463e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(_Arg1 __x, _Arg2 __y) const
464e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return _M_ptr(__x, __y); }
465e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
466e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
467e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
468e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Arg1, typename _Arg2, typename _Result>
469e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline pointer_to_binary_function<_Arg1, _Arg2, _Result>
470e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    ptr_fun(_Result (*__x)(_Arg1, _Arg2))
471e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x); }
472e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @}  */
473e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
474e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Tp>
475e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct _Identity
476e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#ifndef __GXX_EXPERIMENTAL_CXX0X__
477e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    // unary_function itself is deprecated in C++11 and deriving from
478e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    // it can even be a nuisance (see PR 52942).
479e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    : public unary_function<_Tp,_Tp>
480e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#endif
481e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
482e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Tp&
483e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(_Tp& __x) const
484e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x; }
485e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
486e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      const _Tp&
487e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __x) const
488e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x; }
489e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
490e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
491e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Pair>
492e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct _Select1st
493e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#ifndef __GXX_EXPERIMENTAL_CXX0X__
494e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    : public unary_function<_Pair, typename _Pair::first_type>
495e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#endif
496e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
497e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      typename _Pair::first_type&
498e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(_Pair& __x) const
499e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x.first; }
500e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
501e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      const typename _Pair::first_type&
502e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Pair& __x) const
503e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x.first; }
504e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
505e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#ifdef __GXX_EXPERIMENTAL_CXX0X__
506e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      template<typename _Pair2>
507e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh        typename _Pair2::first_type&
508e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh        operator()(_Pair2& __x) const
509e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh        { return __x.first; }
510e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
511e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      template<typename _Pair2>
512e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh        const typename _Pair2::first_type&
513e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh        operator()(const _Pair2& __x) const
514e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh        { return __x.first; }
515e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#endif
516e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
517e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
518e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Pair>
519e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    struct _Select2nd
520e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#ifndef __GXX_EXPERIMENTAL_CXX0X__
521e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    : public unary_function<_Pair, typename _Pair::second_type>
522e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#endif
523e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
524e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      typename _Pair::second_type&
525e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(_Pair& __x) const
526e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x.second; }
527e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
528e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      const typename _Pair::second_type&
529e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Pair& __x) const
530e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return __x.second; }
531e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
532e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
533e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  // 20.3.8 adaptors pointers members
534e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @defgroup memory_adaptors Adaptors for pointers to members
535e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   * @ingroup functors
536e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
537e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  There are a total of 8 = 2^3 function objects in this family.
538e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *   (1) Member functions taking no arguments vs member functions taking
539e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *        one argument.
540e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *   (2) Call through pointer vs call through reference.
541e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *   (3) Const vs non-const member function.
542e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
543e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  All of this complexity is in the function objects themselves.  You can
544e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *   ignore it by using the helper function mem_fun and mem_fun_ref,
545e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *   which create whichever type of adaptor is appropriate.
546e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *
547e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   *  @{
548e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh   */
549e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link memory_adaptors adaptors for member
550e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// pointers@endlink.
551e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp>
552e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class mem_fun_t : public unary_function<_Tp*, _Ret>
553e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
554e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
555e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
556e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      mem_fun_t(_Ret (_Tp::*__pf)())
557e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      : _M_f(__pf) { }
558e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
559e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret
560e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(_Tp* __p) const
561e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return (__p->*_M_f)(); }
562e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
563e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    private:
564e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret (_Tp::*_M_f)();
565e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
566e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
567e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link memory_adaptors adaptors for member
568e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// pointers@endlink.
569e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp>
570e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
571e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
572e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
573e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
574e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      const_mem_fun_t(_Ret (_Tp::*__pf)() const)
575e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      : _M_f(__pf) { }
576e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
577e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret
578e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp* __p) const
579e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return (__p->*_M_f)(); }
580e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
581e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    private:
582e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret (_Tp::*_M_f)() const;
583e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
584e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
585e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link memory_adaptors adaptors for member
586e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// pointers@endlink.
587e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp>
588e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class mem_fun_ref_t : public unary_function<_Tp, _Ret>
589e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
590e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
591e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
592e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      mem_fun_ref_t(_Ret (_Tp::*__pf)())
593e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      : _M_f(__pf) { }
594e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
595e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret
596e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(_Tp& __r) const
597e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return (__r.*_M_f)(); }
598e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
599e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    private:
600e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret (_Tp::*_M_f)();
601e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  };
602e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
603e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link memory_adaptors adaptors for member
604e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// pointers@endlink.
605e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp>
606e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
607e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
608e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
609e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
610e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const)
611e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      : _M_f(__pf) { }
612e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
613e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret
614e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __r) const
615e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return (__r.*_M_f)(); }
616e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
617e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    private:
618e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret (_Tp::*_M_f)() const;
619e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
620e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
621e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link memory_adaptors adaptors for member
622e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// pointers@endlink.
623e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp, typename _Arg>
624e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
625e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
626e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
627e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
628e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      mem_fun1_t(_Ret (_Tp::*__pf)(_Arg))
629e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      : _M_f(__pf) { }
630e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
631e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret
632e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(_Tp* __p, _Arg __x) const
633e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return (__p->*_M_f)(__x); }
634e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
635e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    private:
636e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret (_Tp::*_M_f)(_Arg);
637e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
638e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
639e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link memory_adaptors adaptors for member
640e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// pointers@endlink.
641e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp, typename _Arg>
642e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
643e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
644e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
645e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
646e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const)
647e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      : _M_f(__pf) { }
648e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
649e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret
650e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp* __p, _Arg __x) const
651e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return (__p->*_M_f)(__x); }
652e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
653e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    private:
654e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret (_Tp::*_M_f)(_Arg) const;
655e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
656e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
657e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link memory_adaptors adaptors for member
658e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// pointers@endlink.
659e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp, typename _Arg>
660e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
661e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
662e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
663e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
664e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg))
665e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      : _M_f(__pf) { }
666e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
667e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret
668e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(_Tp& __r, _Arg __x) const
669e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return (__r.*_M_f)(__x); }
670e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
671e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    private:
672e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret (_Tp::*_M_f)(_Arg);
673e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
674e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
675e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// One of the @link memory_adaptors adaptors for member
676e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /// pointers@endlink.
677e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp, typename _Arg>
678e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
679e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    {
680e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    public:
681e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      explicit
682e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
683e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      : _M_f(__pf) { }
684e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
685e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret
686e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      operator()(const _Tp& __r, _Arg __x) const
687e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      { return (__r.*_M_f)(__x); }
688e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
689e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    private:
690e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh      _Ret (_Tp::*_M_f)(_Arg) const;
691e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    };
692e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
693e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  // Mem_fun adaptor helper functions.  There are only two:
694e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  // mem_fun and mem_fun_ref.
695e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp>
696e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline mem_fun_t<_Ret, _Tp>
697e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    mem_fun(_Ret (_Tp::*__f)())
698e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return mem_fun_t<_Ret, _Tp>(__f); }
699e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
700e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp>
701e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline const_mem_fun_t<_Ret, _Tp>
702e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    mem_fun(_Ret (_Tp::*__f)() const)
703e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return const_mem_fun_t<_Ret, _Tp>(__f); }
704e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
705e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp>
706e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline mem_fun_ref_t<_Ret, _Tp>
707e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    mem_fun_ref(_Ret (_Tp::*__f)())
708e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return mem_fun_ref_t<_Ret, _Tp>(__f); }
709e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
710e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp>
711e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline const_mem_fun_ref_t<_Ret, _Tp>
712e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    mem_fun_ref(_Ret (_Tp::*__f)() const)
713e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return const_mem_fun_ref_t<_Ret, _Tp>(__f); }
714e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
715e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp, typename _Arg>
716e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline mem_fun1_t<_Ret, _Tp, _Arg>
717e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    mem_fun(_Ret (_Tp::*__f)(_Arg))
718e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
719e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
720e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp, typename _Arg>
721e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline const_mem_fun1_t<_Ret, _Tp, _Arg>
722e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    mem_fun(_Ret (_Tp::*__f)(_Arg) const)
723e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
724e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
725e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp, typename _Arg>
726e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline mem_fun1_ref_t<_Ret, _Tp, _Arg>
727e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
728e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
729e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
730e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  template<typename _Ret, typename _Tp, typename _Arg>
731e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
732e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
733e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh    { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
734e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
735e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh  /** @}  */
736e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
737e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh_GLIBCXX_END_NAMESPACE_VERSION
738e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh} // namespace
739e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
740e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#if !defined(__GXX_EXPERIMENTAL_CXX0X__) || _GLIBCXX_USE_DEPRECATED
741e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh# include <backward/binders.h>
742e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#endif
743e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh
744e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh#endif /* _STL_FUNCTION_H */
745