GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
functor.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2015 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:
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>
49 {
50 private:
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>
63 func_ptr (RT (*f) (PT))
64 {
65  return functor<RT, PT> (f);
66 }
67 
68 template <typename CT, typename RT, typename PT>
71 {
73 }
74 
75 #endif
functor< RT, PT > func_ptr(RT(*f)(PT))
Definition: functor.h:63
RT operator()(PT arg)
Definition: functor.h:44
functor(fcn_ptr_type p)
Definition: functor.h:42
fcn_ptr_type fptr
Definition: functor.h:38
CT operator()(PT arg)
Definition: functor.h:58
F77_RET_T const double const double * f
fcn_ptr_type fptr
Definition: functor.h:52
fcn_ptr< RT, PT >::TYPE fcn_ptr_type
Definition: functor.h:37
double arg(double x)
Definition: lo-mappers.h:37
functor_with_conversion(fcn_ptr_type p)
Definition: functor.h:56
fcn_ptr< RT, PT >::TYPE fcn_ptr_type
Definition: functor.h:51
functor_with_conversion< CT, RT, PT > func_ptr_with_conversion(RT(*f)(PT))
Definition: functor.h:70
RT(* TYPE)(PT)
Definition: functor.h:30