STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
binders.h
Go to the documentation of this file.
1 // Functor implementations -*- C++ -*-
2 
3 // Copyright (C) 2001-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /*
26  *
27  * Copyright (c) 1994
28  * Hewlett-Packard Company
29  *
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.
37  *
38  *
39  * Copyright (c) 1996-1998
40  * Silicon Graphics Computer Systems, Inc.
41  *
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.
49  */
50 
56 #ifndef _BACKWARD_BINDERS_H
57 #define _BACKWARD_BINDERS_H 1
58 
59 namespace std _GLIBCXX_VISIBILITY(default)
60 {
61 _GLIBCXX_BEGIN_NAMESPACE_VERSION
62 
63  // 20.3.6 binders
102  template<typename _Operation>
104  class binder1st
105  : public unary_function<typename _Operation::second_argument_type,
106  typename _Operation::result_type>
107  {
108  protected:
109  _Operation op;
110  typename _Operation::first_argument_type value;
111 
112  public:
113  binder1st(const _Operation& __x,
114  const typename _Operation::first_argument_type& __y)
115  : op(__x), value(__y) { }
116 
117  typename _Operation::result_type
118  operator()(const typename _Operation::second_argument_type& __x) const
119  { return op(value, __x); }
120 
121  // _GLIBCXX_RESOLVE_LIB_DEFECTS
122  // 109. Missing binders for non-const sequence elements
123  typename _Operation::result_type
124  operator()(typename _Operation::second_argument_type& __x) const
125  { return op(value, __x); }
126  } _GLIBCXX_DEPRECATED;
127 
129  template<typename _Operation, typename _Tp>
130  inline binder1st<_Operation>
131  bind1st(const _Operation& __fn, const _Tp& __x)
132  {
133  typedef typename _Operation::first_argument_type _Arg1_type;
134  return binder1st<_Operation>(__fn, _Arg1_type(__x));
135  }
136 
138  template<typename _Operation>
139  class binder2nd
140  : public unary_function<typename _Operation::first_argument_type,
141  typename _Operation::result_type>
142  {
143  protected:
144  _Operation op;
145  typename _Operation::second_argument_type value;
146 
147  public:
148  binder2nd(const _Operation& __x,
149  const typename _Operation::second_argument_type& __y)
150  : op(__x), value(__y) { }
151 
152  typename _Operation::result_type
153  operator()(const typename _Operation::first_argument_type& __x) const
154  { return op(__x, value); }
155 
156  // _GLIBCXX_RESOLVE_LIB_DEFECTS
157  // 109. Missing binders for non-const sequence elements
158  typename _Operation::result_type
159  operator()(typename _Operation::first_argument_type& __x) const
160  { return op(__x, value); }
161  } _GLIBCXX_DEPRECATED;
162 
164  template<typename _Operation, typename _Tp>
165  inline binder2nd<_Operation>
166  bind2nd(const _Operation& __fn, const _Tp& __x)
167  {
168  typedef typename _Operation::second_argument_type _Arg2_type;
169  return binder2nd<_Operation>(__fn, _Arg2_type(__x));
170  }
173 _GLIBCXX_END_NAMESPACE_VERSION
174 } // namespace
175 
176 #endif /* _BACKWARD_BINDERS_H */
namespace std _GLIBCXX_VISIBILITY(default)
Definition: auto_ptr.h:36