Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
operator.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_FUNCTIONAL_OPERATOR_HPP
9#define ADOBE_FUNCTIONAL_OPERATOR_HPP
10
11#include <adobe/config.hpp>
12
13#include <functional>
14#include <typeinfo>
15
16/**************************************************************************************************/
17
18namespace adobe {
19
20/**************************************************************************************************/
21
25struct equal_to {
26 typedef bool result_type;
27
28 template <typename T> // T models Regular
29 bool operator()(const T& x, const T& y) const {
30 return std::equal_to<T>()(x, y);
31 }
32};
33
35 typedef bool result_type;
36
37 template <typename T> // T models Regular
38 bool operator()(const T& x, const T& y) const {
39 return std::not_equal_to<T>()(x, y);
40 }
41};
42
43struct greater {
44 typedef bool result_type;
45
46 template <typename T> // T models Regular
47 bool operator()(const T& x, const T& y) const {
48 return std::greater<T>()(x, y);
49 }
50};
51
52struct less {
53 typedef bool result_type;
54
55 template <typename T> // T models Regular
56 bool operator()(const T& x, const T& y) const {
57 return typename std::less<T>()(x, y);
58 }
59
60 template <typename T, typename U> // T models Regular
61 bool operator()(const T& x, const U& y) const {
62 return x < y;
63 }
64
65 bool operator()(const std::type_info& x, const std::type_info& y) const {
66 return x.before(y) != 0;
67 }
68};
69
71 typedef bool result_type;
72
73 template <typename T> // T models Regular
74 bool operator()(const T& x, const T& y) const {
75 return std::greater_equal<T>()(x, y);
76 }
77};
78
79struct less_equal {
80 typedef bool result_type;
81
82 template <typename T> // T models Regular
83 bool operator()(const T& x, const T& y) const {
84 return std::less_equal<T>()(x, y);
85 }
86};
87
89 typedef bool result_type;
90
91 template <typename T> // T models Regular
92 bool operator()(const T& x, const T& y) const {
93 return std::logical_and<T>()(x, y);
94 }
95};
96
97struct logical_or {
98 typedef bool result_type;
99
100 template <typename T> // T models Regular
101 bool operator()(const T& x, const T& y) const {
102 return std::logical_or<T>()(x, y);
103 }
104};
105
107 typedef bool result_type;
108
109 template <typename T> // T models Regular
110 bool operator()(const T& x) const {
111 return std::logical_not<T>()(x);
112 }
113};
114
115// `assign` is a function object type for the assignment operator.
116// `assign{}(x, r)` is equivalent to `(void)(r = x)`
117struct assign {
118 typedef void result_type;
119
120 template <class T, class U>
121 void operator()(T&& x, U& r) {
122 r = std::forward<T>(x);
123 }
124};
125
126/**************************************************************************************************/
127
128template <typename T> // T models Regular
130 typedef T* result_type;
131
132 T* operator()(T& x) const { return &x; }
133};
134
135/**************************************************************************************************/
136
137template <typename T = void>
138struct identity {
139 typedef T& result_type;
140
141 T& operator()(T& x) const { return x; }
142};
143
144template <>
145struct identity<void> {
146 template <class T>
147 auto operator()(T&& x) const noexcept {
148 return std::forward<T>(x);
149 }
150};
151
152/**************************************************************************************************/
153
159
161 typedef void result_type;
162
163 template <typename T>
164 void operator()(const T* x) const {
165 delete x;
166 }
167};
168
174
176 typedef void result_type;
177
178 template <typename T>
179 void operator()(const T* x) const {
180 delete[] x;
181 }
182};
183
184/**************************************************************************************************/
185
186template <class T>
188 typedef T result_type;
189
190 T operator()() const { return T(); }
191
192 template <class A1>
193 T operator()(const A1& a1) const {
194 return T(a1);
195 }
196
197 template <class A1, class A2>
198 T operator()(const A1& a1, const A2& a2) const {
199 return T(a1, a2);
200 }
201
202 template <class A1, class A2, class A3>
203 T operator()(const A1& a1, const A2& a2, const A3& a3) const {
204 return T(a1, a2, a3);
205 }
206
207 template <class A1, class A2, class A3, class A4>
208 T operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) const {
209 return T(a1, a2, a3, a4);
210 }
211
212 template <class A1, class A2, class A3, class A4, class A5>
213 T operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) const {
214 return T(a1, a2, a3, a4, a5);
215 }
216};
217
218/**************************************************************************************************/
219
220template <typename T> // T models Regular
221struct indirect {
222 typedef T& result_type;
223
224 template <typename P> // models TrivialIterator where value_type(P) == T
225 T& operator()(P x) const {
226 return *x;
227 }
228};
229
230/**************************************************************************************************/
231
232template <class T>
234 T operator()(const T& x, const T& y) const { return x | y; }
235};
236
237/**************************************************************************************************/
238
239template <class T>
241 T operator()(const T& x, const T& y) const { return x & y; }
242};
243
244/**************************************************************************************************/
245
246template <class T>
248 T operator()(const T& x, const T& y) const { return x ^ y; }
249};
250
251/**************************************************************************************************/
252
254template <typename T1, typename T2>
256 T1 operator()(T1 f1, T2 f2) const { return f1 + f2; }
257};
258
259/**************************************************************************************************/
260
262template <typename T>
263struct inc {
264 T operator()(T x) const { return ++x; }
265};
266
267/**************************************************************************************************/
268
270template <typename T>
271struct dec {
272 T operator()(T x) const { return --x; }
273};
274
275/**************************************************************************************************/
276
278struct typeid_ {
279 typedef std::type_info result_type;
280
281 template <typename T>
282 const result_type& operator()(T) const {
283 return typeid(T);
284 }
285};
286
288
289/**************************************************************************************************/
290
291} // namespace adobe
292
293/**************************************************************************************************/
294
295#endif
296
297/**************************************************************************************************/
void operator()(T &&x, U &r)
Definition operator.hpp:121
T operator()(const T &x, const T &y) const
Definition operator.hpp:241
T operator()(const T &x, const T &y) const
Definition operator.hpp:234
T operator()(const T &x, const T &y) const
Definition operator.hpp:248
T operator()(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) const
Definition operator.hpp:213
T operator()(const A1 &a1, const A2 &a2) const
Definition operator.hpp:198
T operator()() const
Definition operator.hpp:190
T operator()(const A1 &a1, const A2 &a2, const A3 &a3) const
Definition operator.hpp:203
T operator()(const A1 &a1) const
Definition operator.hpp:193
T operator()(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) const
Definition operator.hpp:208
operator-- wrapped in a function object
Definition operator.hpp:271
T operator()(T x) const
Definition operator.hpp:272
A function object for type T that invokes delete[] on an array of T.
Definition operator.hpp:175
void operator()(const T *x) const
Definition operator.hpp:179
A function object for type T that invokes delete on a T*.
Definition operator.hpp:160
void operator()(const T *x) const
Definition operator.hpp:164
bool operator()(const T &x, const T &y) const
Definition operator.hpp:29
bool operator()(const T &x, const T &y) const
Definition operator.hpp:74
bool operator()(const T &x, const T &y) const
Definition operator.hpp:47
auto operator()(T &&x) const noexcept
Definition operator.hpp:147
T & operator()(T &x) const
Definition operator.hpp:141
operator++ wrapped in a function object
Definition operator.hpp:263
T operator()(T x) const
Definition operator.hpp:264
T & operator()(P x) const
Definition operator.hpp:225
bool operator()(const T &x, const T &y) const
Definition operator.hpp:83
bool operator()(const T &x, const U &y) const
Definition operator.hpp:61
bool result_type
Definition operator.hpp:53
bool operator()(const std::type_info &x, const std::type_info &y) const
Definition operator.hpp:65
bool operator()(const T &x, const T &y) const
Definition operator.hpp:56
bool operator()(const T &x, const T &y) const
Definition operator.hpp:92
bool operator()(const T &x) const
Definition operator.hpp:110
bool operator()(const T &x, const T &y) const
Definition operator.hpp:101
bool operator()(const T &x, const T &y) const
Definition operator.hpp:38
plus function object whose arguments may be of different type.
Definition operator.hpp:255
T1 operator()(T1 f1, T2 f2) const
Definition operator.hpp:256
T * operator()(T &x) const
Definition operator.hpp:132
typeid(x) wrapped in a function object
Definition operator.hpp:278
std::type_info result_type
Definition operator.hpp:279
const result_type & operator()(T) const
Definition operator.hpp:282