claw 1.8.2
 
Loading...
Searching...
No Matches
functional.hpp
Go to the documentation of this file.
1/*
2 CLAW - a C++ Library Absolutely Wonderful
3
4 CLAW is a free library without any particular aim but being useful to
5 anyone.
6
7 Copyright (C) 2005-2011 Julien Jorge
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23 contact: julien.jorge@stuff-o-matic.com
24*/
30#ifndef __CLAW_FUNCTIONAL_HPP__
31#define __CLAW_FUNCTIONAL_HPP__
32
33#include <functional>
34#include <utility>
35
36namespace claw
37{
42 template <class T1, class T2>
43 class first : public std::unary_function<std::pair<T1, T2>, T1&>
44 {
45 public:
46 T1& operator()(std::pair<T1, T2>& p) const
47 {
48 return p.first;
49 }
50 }; // class first
51
56 template <class T1, class T2>
58 : public std::unary_function<const std::pair<T1, T2>, const T1&>
59 {
60 public:
61 const T1& operator()(const std::pair<T1, T2>& p) const
62 {
63 return p.first;
64 }
65
66 }; // class const_first
67
74 template <class Pair>
76 : public first<typename Pair::first_type, typename Pair::second_type>
77 {
78 // nothing
79 }; // class pair_first
80
87 template <class Pair>
89 : public const_first<typename Pair::first_type, typename Pair::second_type>
90 {
91 // nothing
92 }; // class const_pair_first
93
98 template <class T1, class T2>
99 class second : public std::unary_function<std::pair<T1, T2>, T2&>
100 {
101 public:
102 T2& operator()(std::pair<T1, T2>& p) const
103 {
104 return p.second;
105 }
106 }; // class second
107
112 template <class T1, class T2>
114 : public std::unary_function<const std::pair<T1, T2>, const T2&>
115 {
116 public:
117 const T2& operator()(const std::pair<T1, T2>& p) const
118 {
119 return p.second;
120 }
121
122 }; // class const_second
123
130 template <class Pair>
132 : public second<typename Pair::first_type, typename Pair::second_type>
133 {
134 // nothing
135 }; // class pair_second
136
143 template <class Pair>
144 class const_pair_second
145 : public const_second<typename Pair::first_type,
146 typename Pair::second_type>
147 {
148 public:
149 const_pair_second()
150 {}
151
152 template <typename F, typename S>
153 const_pair_second(const second<F, S>&)
154 {}
155
156 }; // class const_pair_second
157
168 template <class T>
169 class unary_true : public std::unary_function<T, bool>
170 {
171 public:
172 bool operator()(const T& t) const
173 {
174 return true;
175 }
176 }; // class unary_true
177
189 template <class T, class U>
190 class binary_true : public std::binary_function<T, U, bool>
191 {
192 public:
193 bool operator()(const T& t, const U& u) const
194 {
195 return true;
196 }
197 }; // class binary_true
198
210 template <typename F1, typename F2>
211 class unary_compose
212 : public std::unary_function<typename F2::argument_type,
213 typename F1::result_type>
214 {
215 public:
216 unary_compose()
217 {}
218
226 template <typename G1, typename G2>
227 unary_compose(const unary_compose<G1, G2>& that)
228 {}
229
233 typename F1::result_type operator()(typename F2::argument_type& a) const
234 {
235 return F1()(F2()(a));
236 }
237 }; // class unary_compose
238
248 template <typename T>
249 class delete_function : public std::unary_function<T, void>
250 {
251 public:
252 void operator()(const T& a) const
253 {
254 delete a;
255 }
256 }; // class delete_function
257
267 template <typename T>
268 class clone : public std::unary_function<T*, T*>
269 {
270 public:
271 T* operator()(const T* a) const
272 {
273 return new T(*a);
274 }
275 }; // class clone
276
285 template <typename T>
286 class dereference : public std::unary_function<T*, T&>
287 {
288 public:
289 T& operator()(T* a) const
290 {
291 return *a;
292 }
293
294 }; // class dereference
295
304 template <typename T>
305 class const_dereference : public std::unary_function<const T*, const T&>
306 {
307 public:
308 const_dereference()
309 {}
310 const_dereference(const dereference<T>&)
311 {}
312 const_dereference(const const_dereference<T>&)
313 {}
314
315 const T& operator()(const T* a) const
316 {
317 return *a;
318 }
319
320 }; // class const_dereference
321}
322
323#endif // __CLAW_FUNCTIONAL_HPP__
Always true binary predicate.
Function object that clones a pointer.
Fuction object to get the first element of a std::pair.
Fuction object to get the first element of a std::pair.
Fuction object to get the second element of a std::pair.
Function object that deletes a pointer.
Function object that dereferences a pointer.
Fuction object to get the first element of a std::pair.
Fuction object to get the first element of a std::pair.
Fuction object to get the second element of a std::pair.
Fuction object to get the second element of a std::pair.
unary_compose(const unary_compose< G1, G2 > &that)
Copy constructor.
F1::result_type operator()(typename F2::argument_type &a) const
Return (F1 o F2)(a).
Always true unary predicate.
This is the main namespace.