GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
liboctave
util
functor.h
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 2008-2013 John W. Eaton
4
5
This file is part of Octave.
6
7
Octave is free software; you can redistribute it and/or modify it
8
under the terms of the GNU General Public License as published by the
9
Free Software Foundation; either version 3 of the License, or (at your
10
option) any later version.
11
12
Octave is distributed in the hope that it will be useful, but WITHOUT
13
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15
for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with Octave; see the file COPYING. If not, see
19
<http://www.gnu.org/licenses/>.
20
21
*/
22
23
#if !defined (octave_functor_h)
24
#define octave_functor_h 1
25
26
template
<
typename
RT,
typename
PT>
27
class
fcn_ptr
28
{
29
public
:
30
typedef
RT (*
TYPE
) (PT);
31
};
32
33
template
<
typename
RT,
typename
PT>
34
class
functor
35
{
36
private
:
37
typedef
typename
fcn_ptr<RT, PT>::TYPE
fcn_ptr_type
;
38
fcn_ptr_type
fptr
;
39
40
public
:
41
42
functor
(
fcn_ptr_type
p) :
fptr
(p) { }
43
44
RT
operator ()
(PT
arg
) {
return
fptr
(arg); }
45
};
46
47
template
<
typename
CT,
typename
RT,
typename
PT>
48
class
functor_with_conversion
49
{
50
private
:
51
typedef
typename
fcn_ptr<RT, PT>::TYPE
fcn_ptr_type
;
52
fcn_ptr_type
fptr
;
53
54
public
:
55
56
functor_with_conversion
(
fcn_ptr_type
p) :
fptr
(p) { }
57
58
CT
operator ()
(PT
arg
) {
return
CT (
fptr
(arg)); }
59
};
60
61
template
<
typename
RT,
typename
PT>
62
functor<RT, PT>
63
func_ptr
(RT (*
f
) (PT))
64
{
65
return
functor<RT, PT>
(
f
);
66
}
67
68
template
<
typename
CT,
typename
RT,
typename
PT>
69
functor_with_conversion<CT, RT, PT>
70
func_ptr_with_conversion
(RT (*
f
) (PT))
71
{
72
return
functor_with_conversion<CT, RT, PT>
(
f
);
73
}
74
75
#endif
Generated on Mon Dec 30 2013 03:04:54 for GNU Octave by
1.8.1.2