stlab.adobe.com Adobe Systems Incorporated
operator.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_FUNCTIONAL_OPERATOR_HPP
10 #define ADOBE_FUNCTIONAL_OPERATOR_HPP
11 
12 #include <adobe/config.hpp>
13 
14 #include <functional>
15 #include <typeinfo>
16 
17 #include <adobe/move.hpp>
18 
19 /*************************************************************************************************/
20 
21 namespace adobe {
22 
23 /*************************************************************************************************/
24 
28 struct equal_to
29 {
30  typedef bool result_type;
31 
32  template <typename T> // T models Regular
33  bool operator()(const T& x, const T& y) const { return std::equal_to<T>()(x, y); }
34 };
35 
37 {
38  typedef bool result_type;
39 
40  template <typename T> // T models Regular
41  bool operator()(const T& x, const T& y) const { return std::not_equal_to<T>()(x, y); }
42 };
43 
44 struct greater
45 {
46  typedef bool result_type;
47 
48  template <typename T> // T models Regular
49  bool operator()(const T& x, const T& y) const { return std::greater<T>()(x, y); }
50 };
51 
52 struct less
53 {
54  typedef bool result_type;
55 
56  template <typename T> // T models Regular
57  bool operator()(const T& x, const T& y) const { return typename std::less<T>()(x, y); }
58 
59  bool operator()(const std::type_info& x, const std::type_info& y) { return x.before(y) != 0; }
60 };
61 
63 {
64  typedef bool result_type;
65 
66  template <typename T> // T models Regular
67  bool operator()(const T& x, const T& y) const { return std::greater_equal<T>()(x, y); }
68 };
69 
70 struct less_equal
71 {
72  typedef bool result_type;
73 
74  template <typename T> // T models Regular
75  bool operator()(const T& x, const T& y) const { return std::less_equal<T>()(x, y); }
76 };
77 
79 {
80  typedef bool result_type;
81 
82  template <typename T> // T models Regular
83  bool operator()(const T& x, const T& y) const { return std::logical_and<T>()(x, y); }
84 };
85 
86 struct logical_or
87 {
88  typedef bool result_type;
89 
90  template <typename T> // T models Regular
91  bool operator()(const T& x, const T& y) const { return std::logical_or<T>()(x, y); }
92 };
93 
95 {
96  typedef bool result_type;
97 
98  template <typename T> // T models Regular
99  bool operator()(const T& x) const { return std::logical_not<T>()(x); }
100 };
101 
102 struct assign
103 {
104  typedef void result_type;
105 
106  template <typename T> // T models Regular
107  void operator()(T x, T& r) { r = adobe::move(x); }
108 };
109 
110 /*************************************************************************************************/
111 
112 template <typename T> // T models Regular
114 {
115  typedef T* result_type;
116 
117  T* operator()(T& x) const { return &x; }
118 };
119 
120 /*************************************************************************************************/
121 
122 template <typename T>
123 struct identity
124 {
125  typedef T& result_type;
126 
127  T& operator()(T& x) const { return x; }
128 };
129 
130 /*************************************************************************************************/
131 
139 {
140  typedef void result_type;
141 
142  template <typename T>
143  void operator () (const T* x) const { delete x; }
144 };
145 
153 {
154  typedef void result_type;
155 
156  template <typename T>
157  void operator () (const T* x) const { delete [] x; }
158 };
159 
160 /*************************************************************************************************/
161 
162 template<class T>
164 {
165  typedef T result_type;
166 
167  T operator()() const {
168  return T();
169  }
170 
171  template<class A1>
172  T operator()(const A1& a1) const {
173  return T(a1);
174  }
175 
176  template<class A1, class A2>
177  T operator()(const A1& a1, const A2& a2) const {
178  return T(a1, a2);
179  }
180 
181  template<class A1, class A2, class A3>
182  T operator()(const A1& a1, const A2& a2, const A3& a3) const {
183  return T(a1, a2, a3);
184  }
185 
186  template<class A1, class A2, class A3, class A4>
187  T operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) const {
188  return T(a1, a2, a3, a4);
189  }
190 
191  template<class A1, class A2, class A3, class A4, class A5>
192  T operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) const {
193  return T(a1, a2, a3, a4, a5);
194  }
195 };
196 
197 /*************************************************************************************************/
198 
199 template <typename T> // T models Regular
200 struct indirect
201 {
202  typedef T& result_type;
203 
204  template <typename P> // models TrivialIterator where value_type(P) == T
205  T& operator () (P x) const
206  { return *x; }
207 };
208 
209 /*************************************************************************************************/
210 
211 template <class T>
213  : std::binary_function<T, T, T>
214 {
215  T operator()(const T& x, const T& y) const {return x | y;}
216 };
217 
218 /*************************************************************************************************/
219 
220 template <class T>
222  : std::binary_function<T, T, T>
223 {
224  T operator()(const T& x, const T& y) const {return x & y;}
225 };
226 
227 /*************************************************************************************************/
228 
229 template <class T>
231  : std::binary_function<T, T, T>
232 {
233  T operator()(const T& x, const T& y) const {return x ^ y;}
234 };
235 
236 /*************************************************************************************************/
237 
239 template <typename T1, typename T2>
240 struct plus_asymmetric : public std::binary_function<T1,T2,T1>
241 {
242  T1 operator()(T1 f1, T2 f2) const {
243  return f1+f2;
244  }
245 };
246 
247 /*************************************************************************************************/
248 
250 template <typename T>
251 struct inc : public std::unary_function<T,T>
252 {
253  T operator()(T x) const { return ++x; }
254 };
255 
256 /*************************************************************************************************/
257 
259 template <typename T>
260 struct dec : public std::unary_function<T,T>
261 {
262  T operator()(T x) const { return --x; }
263 };
264 
266 
267 /*************************************************************************************************/
268 
269 } // namespace adobe
270 
271 /*************************************************************************************************/
272 
273 #endif
274 
275 /*************************************************************************************************/
operator() returns x ^ y.
Definition: operator.hpp:230
T * operator()(T &x) const
Definition: operator.hpp:117
T operator()(const T &x, const T &y) const
Definition: operator.hpp:224
void operator()(const T *x) const
Definition: operator.hpp:143
bool operator()(const T &x) const
Definition: operator.hpp:99
bool operator()(const T &x, const T &y) const
Definition: operator.hpp:83
void result_type
Definition: operator.hpp:104
operator++ wrapped in a function object
Definition: operator.hpp:251
T operator()(const T &x, const T &y) const
Definition: operator.hpp:233
T operator()(T x) const
Definition: operator.hpp:253
bool operator()(const T &x, const T &y) const
Definition: operator.hpp:75
T operator()(const A1 &a1) const
Definition: operator.hpp:172
bool result_type
Definition: operator.hpp:46
bool operator()(const T &x, const T &y) const
Definition: operator.hpp:67
T operator()(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) const
Definition: operator.hpp:192
T1 operator()(T1 f1, T2 f2) const
Definition: operator.hpp:242
A function object for type T that invokes delete on a T*.
Definition: operator.hpp:138
bool operator()(const T &x, const T &y) const
Definition: operator.hpp:91
A function object for type T that invokes delete[] on an array of T.
Definition: operator.hpp:152
plus function object whose arguments may be of different type.
Definition: operator.hpp:240
bool operator()(const T &x, const T &y) const
Definition: operator.hpp:41
bool operator()(const T &x, const T &y) const
Definition: operator.hpp:49
bool operator()(const T &x, const T &y) const
Definition: operator.hpp:57
T operator()() const
Definition: operator.hpp:167
operator() returns x & y.
Definition: operator.hpp:221
T operator()(const A1 &a1, const A2 &a2) const
Definition: operator.hpp:177
bool operator()(const std::type_info &x, const std::type_info &y)
Definition: operator.hpp:59
T operator()(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) const
Definition: operator.hpp:187
void operator()(T x, T &r)
Definition: operator.hpp:107
void operator()(const T *x) const
Definition: operator.hpp:157
T & operator()(P x) const
Definition: operator.hpp:205
T operator()(const A1 &a1, const A2 &a2, const A3 &a3) const
Definition: operator.hpp:182
bool result_type
Definition: operator.hpp:54
T operator()(const T &x, const T &y) const
Definition: operator.hpp:215
T & operator()(T &x) const
Definition: operator.hpp:127
operator-- wrapped in a function object
Definition: operator.hpp:260
T operator()(T x) const
Definition: operator.hpp:262
operator() returns x | y.
Definition: operator.hpp:212
bool operator()(const T &x, const T &y) const
Definition: operator.hpp:33

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google