claw
1.9.0
Toggle main menu visibility
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 <utility>
34
35
namespace
claw
36
{
41
template
<
class
T1,
class
T2>
42
class
first
43
{
44
public
:
45
using
argument_type = std::pair<T1, T2>&;
46
using
result_type = T1&;
47
48
public
:
49
T1& operator()(std::pair<T1, T2>& p)
const
50
{
51
return
p.first;
52
}
53
};
// class first
54
59
template
<
class
T1,
class
T2>
60
class
const_first
61
{
62
public
:
63
using
argument_type =
const
std::pair<T1, T2>&;
64
using
result_type =
const
T1&;
65
66
public
:
67
const
T1& operator()(
const
std::pair<T1, T2>& p)
const
68
{
69
return
p.first;
70
}
71
72
};
// class const_first
73
80
template
<
class
Pair>
81
class
pair_first
82
:
public
first
<typename Pair::first_type, typename Pair::second_type>
83
{
84
// nothing
85
};
// class pair_first
86
93
template
<
class
Pair>
94
class
const_pair_first
95
:
public
const_first
<typename Pair::first_type, typename Pair::second_type>
96
{
97
// nothing
98
};
// class const_pair_first
99
104
template
<
class
T1,
class
T2>
105
class
second
106
{
107
public
:
108
using
argument_type = std::pair<T1, T2>&;
109
using
result_type = T2&;
110
111
public
:
112
T2& operator()(std::pair<T1, T2>& p)
const
113
{
114
return
p.second;
115
}
116
};
// class second
117
122
template
<
class
T1,
class
T2>
123
class
const_second
124
{
125
public
:
126
using
argument_type =
const
std::pair<T1, T2>&;
127
using
result_type =
const
T2&;
128
129
public
:
130
const
T2& operator()(
const
std::pair<T1, T2>& p)
const
131
{
132
return
p.second;
133
}
134
135
};
// class const_second
136
143
template
<
class
Pair>
144
class
pair_second
145
:
public
second
<typename Pair::first_type, typename Pair::second_type>
146
{
147
// nothing
148
};
// class pair_second
149
156
template
<
class
Pair>
157
class
const_pair_second
158
:
public
const_second
<typename Pair::first_type,
159
typename Pair::second_type>
160
{
161
public
:
162
const_pair_second()
163
{}
164
165
template
<
typename
F,
typename
S>
166
const_pair_second(
const
second<F, S>
&)
167
{}
168
169
};
// class const_pair_second
170
181
template
<
class
T>
182
class
unary_true
183
{
184
public
:
185
using
argument_type =
const
T&;
186
using
result_type = bool;
187
188
public
:
189
bool
operator()(
const
T& t)
const
190
{
191
return
true
;
192
}
193
};
// class unary_true
194
206
template
<
class
T,
class
U>
207
class
binary_true
208
{
209
public
:
210
using
first_argument_type =
const
T&;
211
using
second_argument_type =
const
U&;
212
using
result_type = bool;
213
214
public
:
215
bool
operator()(
const
T& t,
const
U& u)
const
216
{
217
return
true
;
218
}
219
};
// class binary_true
220
232
template
<
typename
F1,
typename
F2>
233
class
unary_compose
234
{
235
public
:
236
using
argument_type =
typename
F2::argument_type;
237
using
result_type =
typename
F1::result_type;
238
239
public
:
240
unary_compose()
241
{}
242
250
template
<
typename
G1,
typename
G2>
251
unary_compose
(
const
unary_compose<G1, G2>& that)
252
{}
253
257
typename
F1::result_type
operator()
(
typename
F2::argument_type& a)
const
258
{
259
return
F1()(F2()(a));
260
}
261
};
// class unary_compose
262
272
template
<
typename
T>
273
class
delete_function
274
{
275
public
:
276
using
argument_type =
const
T&;
277
using
result_type = void;
278
279
public
:
280
void
operator()(
const
T& a)
const
281
{
282
delete
a;
283
}
284
};
// class delete_function
285
295
template
<
typename
T>
296
class
clone
297
{
298
public
:
299
using
argument_type =
const
T*;
300
using
result_type = T*;
301
302
public
:
303
T* operator()(
const
T* a)
const
304
{
305
return
new
T(*a);
306
}
307
};
// class clone
308
317
template
<
typename
T>
318
class
dereference
319
{
320
public
:
321
using
argument_type = T*;
322
using
result_type = T&;
323
324
public
:
325
T& operator()(T* a)
const
326
{
327
return
*a;
328
}
329
330
};
// class dereference
331
340
template
<
typename
T>
341
class
const_dereference
342
{
343
public
:
344
using
argument_type =
const
T*;
345
using
result_type =
const
T&;
346
347
public
:
348
const_dereference()
349
{}
350
const_dereference(
const
dereference<T>
&)
351
{}
352
const_dereference(
const
const_dereference<T>&)
353
{}
354
355
const
T& operator()(
const
T* a)
const
356
{
357
return
*a;
358
}
359
360
};
// class const_dereference
361
}
362
363
#endif
// __CLAW_FUNCTIONAL_HPP__
claw::binary_true
Always true binary predicate.
Definition
functional.hpp:208
claw::clone
Function object that clones a pointer.
Definition
functional.hpp:297
claw::const_first
Fuction object to get the first element of a std::pair.
Definition
functional.hpp:61
claw::const_pair_first
Fuction object to get the first element of a std::pair.
Definition
functional.hpp:96
claw::const_second
Fuction object to get the second element of a std::pair.
Definition
functional.hpp:124
claw::delete_function
Function object that deletes a pointer.
Definition
functional.hpp:274
claw::dereference
Function object that dereferences a pointer.
Definition
functional.hpp:319
claw::first
Fuction object to get the first element of a std::pair.
Definition
functional.hpp:43
claw::pair_first
Fuction object to get the first element of a std::pair.
Definition
functional.hpp:83
claw::pair_second
Fuction object to get the second element of a std::pair.
Definition
functional.hpp:146
claw::second
Fuction object to get the second element of a std::pair.
Definition
functional.hpp:106
claw::unary_compose::unary_compose
unary_compose(const unary_compose< G1, G2 > &that)
Copy constructor.
Definition
functional.hpp:251
claw::unary_compose::operator()
F1::result_type operator()(typename F2::argument_type &a) const
Return (F1 o F2)(a).
Definition
functional.hpp:257
claw::unary_true
Always true unary predicate.
Definition
functional.hpp:183
claw
This is the main namespace.
Definition
application.hpp:50
lib
core
include
claw
functional.hpp
Generated by
1.17.0