$extrastylesheet
Olena
User documentation 2.1
An Image Processing Platform
Milena
Getting started
API Reference Manual
All Classes
Examples
Demos
Publications
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
bind.hh
1
// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE).
2
//
3
// This file is part of Olena.
4
//
5
// Olena is free software: you can redistribute it and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, version 2 of the License.
8
//
9
// Olena is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
16
//
17
// As a special exception, you may use this file as part of a free
18
// software project without restriction. Specifically, if other files
19
// instantiate templates or use macros or inline functions from this
20
// file, or you compile this file and link it with other files to produce
21
// an executable, this file does not by itself cause the resulting
22
// executable to be covered by the GNU General Public License. This
23
// exception does not however invalidate any other reasons why the
24
// executable file might be covered by the GNU General Public License.
25
26
#ifndef MLN_PW_BIND_HH
27
# define MLN_PW_BIND_HH
28
31
32
# include <mln/core/concept/function.hh>
33
# include <mln/fun/internal/selector.hh>
34
35
36
namespace
mln
37
{
38
39
namespace
pw
40
{
41
42
/*-------------------------.
43
| Unary function binding. |
44
`-------------------------*/
45
52
template
<
typename
F,
typename
PW>
53
struct
unary_bound_fun_
54
:
fun::internal::selector_from_result_
< typename F::result,
55
unary_bound_fun_<F, PW> >
::ret
56
{
57
typedef
typename
F::result
result
;
58
59
unary_bound_fun_
(
const
Function_v2v<F>
& f,
const
Function_v2v<PW>
& pw);
60
61
template
<
typename
P>
62
result
operator()
(
const
P&
p
)
const
;
63
64
protected
:
66
const
F
f_
;
68
const
PW
pw_
;
69
};
70
71
74
template
<
typename
F,
typename
PW>
75
unary_bound_fun_<F, PW>
76
bind
(
const
Function_v2v<F>
& f,
const
Function_v2v<PW>
& pw);
77
78
79
80
/*--------------------------.
81
| Binary function binding. |
82
`--------------------------*/
83
90
template
<
typename
F,
typename
PW1,
typename
PW2>
91
struct
binary_bound_fun_
92
:
fun::internal::selector_from_result_
< typename F::result,
93
binary_bound_fun_<F,
94
PW1,
95
PW2> >
::ret
96
{
97
typedef
typename
F::result
result
;
98
99
binary_bound_fun_
(
const
Function_vv2v<F>
& f,
100
const
Function_v2v<PW1>
& pw1,
101
const
Function_v2v<PW2>
& pw2);
102
103
template
<
typename
P>
104
result
operator()
(
const
P&
p
)
const
;
105
106
protected
:
108
const
F
f_
;
110
const
PW1
pw1_
;
112
const
PW2
pw2_
;
113
};
114
115
118
template
<
typename
F,
typename
PW1,
typename
PW2>
119
binary_bound_fun_<F, PW1, PW2>
120
bind
(
const
Function_vv2v<F>
& f,
121
const
Function_v2v<PW1>
& pw1,
const
Function_v2v<PW2>
& pw2);
122
123
124
125
# ifndef MLN_INCLUDE_ONLY
126
127
// pw::unary_bound_fun_<F, PW>.
128
129
template
<
typename
F,
typename
PW>
130
inline
131
unary_bound_fun_<F, PW>::unary_bound_fun_
(
const
Function_v2v<F>
& f,
132
const
Function_v2v<PW>
& pw)
133
: f_(
exact
(f)),
134
pw_(
exact
(pw))
135
{
136
}
137
138
template
<
typename
F,
typename
PW>
139
template
<
typename
P>
140
inline
141
typename
F::result
142
unary_bound_fun_<F, PW>::operator()
(
const
P&
p
)
const
143
{
144
return
f_(pw_(p));
145
}
146
147
148
// pw::bind(f, pw).
149
150
template
<
typename
F,
typename
PW>
151
inline
152
unary_bound_fun_<F, PW>
153
bind
(
const
Function_v2v<F>& f,
const
Function_v2v<PW>& pw)
154
{
155
return
unary_bound_fun_<F, PW>(f, pw);
156
}
157
158
159
160
// pw::binary_bound_fun_<F, PW1, PW2>.
161
162
template
<
typename
F,
typename
PW1,
typename
PW2>
163
inline
164
binary_bound_fun_<F, PW1, PW2>::binary_bound_fun_
(
const
Function_vv2v<F>& f,
165
const
Function_v2v<PW1>& pw1,
166
const
Function_v2v<PW2>& pw2)
167
: f_(
exact
(f)),
168
pw1_(
exact
(pw1)),
169
pw2_(
exact
(pw2))
170
{
171
}
172
173
template
<
typename
F,
typename
PW1,
typename
PW2>
174
template
<
typename
P>
175
inline
176
typename
F::result
177
binary_bound_fun_<F, PW1, PW2>::operator()
(
const
P& p)
const
178
{
179
return
f_(pw1_(p), pw2_(p));
180
}
181
182
183
// pw::bind(f, pw1, pw2).
184
185
template
<
typename
F,
typename
PW1,
typename
PW2>
186
inline
187
binary_bound_fun_<F, PW1, PW2>
188
bind
(
const
Function_vv2v<F>& f,
189
const
Function_v2v<PW1>& pw1,
const
Function_v2v<PW2>& pw2)
190
{
191
return
binary_bound_fun_<F, PW1, PW2>(f, pw1, pw2);
192
}
193
194
# endif // ! MLN_INCLUDE_ONLY
195
196
}
// end of namespace mln::pw
197
198
}
// end of namespace mln
199
200
201
#endif // ! MLN_PW_BIND_HH
mln
pw
bind.hh
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)