GNU Octave  4.2.1
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-2017 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 #include "octave-config.h"
27 
28 template <typename RT, typename PT>
29 class fcn_ptr
30 {
31 public:
32  typedef RT (*TYPE) (PT);
33 };
34 
35 template <typename RT, typename PT>
36 class functor
37 {
38 private:
40  fcn_ptr_type fptr;
41 
42 public:
43 
44  functor (fcn_ptr_type p) : fptr (p) { }
45 
46  RT operator () (PT arg) { return fptr (arg); }
47 };
48 
49 template <typename CT, typename RT, typename PT>
51 {
52 private:
54  fcn_ptr_type fptr;
55 
56 public:
57 
58  functor_with_conversion (fcn_ptr_type p) : fptr (p) { }
59 
60  CT operator () (PT arg) { return CT (fptr (arg)); }
61 };
62 
63 template <typename RT, typename PT>
65 func_ptr (RT (*f) (PT))
66 {
67  return functor<RT, PT> (f);
68 }
69 
70 template <typename CT, typename RT, typename PT>
73 {
75 }
76 
77 #endif
functor< RT, PT > func_ptr(RT(*f)(PT))
Definition: functor.h:65
RT operator()(PT arg)
Definition: functor.h:46
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
functor(fcn_ptr_type p)
Definition: functor.h:44
octave_value arg
Definition: pr-output.cc:3440
fcn_ptr_type fptr
Definition: functor.h:40
CT operator()(PT arg)
Definition: functor.h:60
fcn_ptr_type fptr
Definition: functor.h:54
fcn_ptr< RT, PT >::TYPE fcn_ptr_type
Definition: functor.h:39
p
Definition: lu.cc:138
functor_with_conversion(fcn_ptr_type p)
Definition: functor.h:58
fcn_ptr< RT, PT >::TYPE fcn_ptr_type
Definition: functor.h:53
functor_with_conversion< CT, RT, PT > func_ptr_with_conversion(RT(*f)(PT))
Definition: functor.h:72
RT(* TYPE)(PT)
Definition: functor.h:32