ccgsl 2.7.2
C++wrappersforGnuScientificLibrary
gsl::function_scl Class Reference

Class that extends gsl_function so that it can be constructed from arbitrary function objects. More...

#include <function_scl.hpp>

Inheritance diagram for gsl::function_scl:
Inheritance graph
Collaboration diagram for gsl::function_scl:
Collaboration graph

Public Member Functions

 function_scl ()
 The default constructor is only really useful for assigning to. More...
 
 function_scl (gsl_function &v)
 Could construct from a gsl_function. More...
 
template<typename A >
 function_scl (double(*const f)(A))
 Construct from a function. More...
 
template<typename A >
 function_scl (double const (*const f)(A))
 Construct from a function. More...
 
template<typename T , typename R , typename A >
 function_scl (T &c, R(T::*f)(A))
 Construct from a function object and a suitable non-const member function. More...
 
template<typename T , typename R , typename A >
 function_scl (T &c, R(T::*f)(A) const)
 Construct from a function object and a suitable const member function. More...
 
template<typename T , typename R , typename A >
 function_scl (T &c, R(T::*f)(A) volatile)
 Construct from a function object and a suitable volatile member function. More...
 
template<typename T , typename R , typename A >
 function_scl (T &c, R(T::*f)(A) const volatile)
 Construct from a function object and a suitable const volatile member function. More...
 
 function_scl (function_scl const &v)
 The copy constructor. More...
 
function_scloperator= (function_scl const &v)
 The assignment operator. More...
 
 function_scl (function_scl &&v)
 Move constructor. More...
 
function_scloperator= (function_scl &&v)
 Move operator. More...
 
 ~function_scl ()
 The destructor unshares any shared resource. More...
 

Static Public Member Functions

static double fn (double x, void *params)
 This is the function that gsl_function points to if function_scl is constructed from a function object. More...
 

Private Attributes

base_F * f
 
size_t * count
 The shared reference count. More...
 

Detailed Description

Class that extends gsl_function so that it can be constructed from arbitrary function objects.

The arbitrary function object could be an object of a class containing a member function whose argument and return values are doubles. The member function may be declared const.

To construct an object of this class from a function object t of class T, use, for example,

gsl::function_scl f( t, &T::operator() )
Class that extends gsl_function so that it can be constructed from arbitrary function objects.

where T::operator is a member function whose single argument is a double. To assign, use, for example,

f = make_function_scl( t, &T::operator() )
function_scl make_function_scl(T &c, R(T::*f)(A))
Make a gsl::function_scl from a function object and a suitable non-const member function.

There are multiple forms of the function_scl constructor and make_function_scl(). These should allow you to construct a function_scl object from any reasonable function object and quite a lot of unreasonable ones too. If f is an object of class gsl_function_scl, it is always possible to pass &f to a gsl function that requires a gsl_function* argument.

This class is designed for flexibility rather than efficient copying. So if objects are to be copied frequently, consider using shared pointers or the like. Moving is defined for C++11.

The class extends gsl_function and is called gsl::function_scl to contrast with gsl_function_vec and avoid a name conflict if gsl_function::function were used. If constructed from a function object, gsl_function::params is always the function object and gsl_function::function calls the member function using params to obtain an object to call the member function from.

Here are a couple of examples.

Example 1: A function with no parameters.

// This function computes the square of a double x
double square(double x){ return x*x; }
// As a gsl::function gsl, which can be used whenever gsl_function is needed
gsl::function_scl square_scl { square };

Example 2: A function with one parameter

// This function object adds a constant to x
class Shift {
public:
Shift( double const offset ) : offset {offset} {}
double operator()( double& x ) const {
return x + offset;
}
private:
double const offset;
};
// Specific instance
Shift shift5 {5};
// As a gsl::function gsl, which can be used whenever gsl_function is needed
auto shift_scl = make_function_scl( shift5, &Shift::operator() };
// Last function gets called withing gsl as follows. This will set y = 12.
double y = shift_scl.function( 7, shift_scl.params );

Definition at line 96 of file function_scl.hpp.

Constructor & Destructor Documentation

◆ function_scl() [1/10]

gsl::function_scl::function_scl ( )
inline

The default constructor is only really useful for assigning to.

Definition at line 369 of file function_scl.hpp.

References count, and f.

◆ function_scl() [2/10]

gsl::function_scl::function_scl ( gsl_function &  v)
inlineexplicit

Could construct from a gsl_function.

Parameters
vThe gsl_function

Definition at line 379 of file function_scl.hpp.

References count, and f.

◆ function_scl() [3/10]

template<typename A >
gsl::function_scl::function_scl ( double(*)(A)  f)
inlineexplicit

Construct from a function.

There are multiple different versions of this constructor that allow the argument and return value to be cv-qualified and the argument to be supplied by reference.

Parameters
fThe function.

Definition at line 396 of file function_scl.hpp.

References count, f, and fn().

◆ function_scl() [4/10]

template<typename A >
gsl::function_scl::function_scl ( double const (*)(A)  f)
inlineexplicit

Construct from a function.

There are multiple different versions of this constructor that allow the argument and return value to be cv-qualified and the argument to be supplied by reference.

Parameters
fThe function.

Definition at line 411 of file function_scl.hpp.

References count, f, and fn().

◆ function_scl() [5/10]

template<typename T , typename R , typename A >
gsl::function_scl::function_scl ( T &  c,
R(T::*)(A)  f 
)
inline

Construct from a function object and a suitable non-const member function.

Parameters
cThe function object.
fThe member function.

Definition at line 424 of file function_scl.hpp.

References count, f, and fn().

◆ function_scl() [6/10]

template<typename T , typename R , typename A >
gsl::function_scl::function_scl ( T &  c,
R(T::*)(A) const  f 
)
inline

Construct from a function object and a suitable const member function.

Parameters
cThe function object.
fThe member function.

Definition at line 437 of file function_scl.hpp.

References count, f, and fn().

◆ function_scl() [7/10]

template<typename T , typename R , typename A >
gsl::function_scl::function_scl ( T &  c,
R(T::*)(A) volatile  f 
)
inline

Construct from a function object and a suitable volatile member function.

Parameters
cThe function object.
fThe member function.

Definition at line 450 of file function_scl.hpp.

References count, f, and fn().

◆ function_scl() [8/10]

template<typename T , typename R , typename A >
gsl::function_scl::function_scl ( T &  c,
R(T::*)(A) const volatile  f 
)
inline

Construct from a function object and a suitable const volatile member function.

Parameters
cThe function object.
fThe member function.

Definition at line 463 of file function_scl.hpp.

References count, f, and fn().

◆ function_scl() [9/10]

gsl::function_scl::function_scl ( function_scl const &  v)
inline

The copy constructor.

This shares f.

Parameters
vThe function_scl to copy.

Definition at line 478 of file function_scl.hpp.

References count.

◆ function_scl() [10/10]

gsl::function_scl::function_scl ( function_scl &&  v)
inline

Move constructor.

Parameters
vThe function_scl to move.

Definition at line 507 of file function_scl.hpp.

References count.

◆ ~function_scl()

gsl::function_scl::~function_scl ( )
inline

The destructor unshares any shared resource.

Definition at line 529 of file function_scl.hpp.

References count, and f.

Member Function Documentation

◆ fn()

static double gsl::function_scl::fn ( double  x,
void *  params 
)
inlinestatic

This is the function that gsl_function points to if function_scl is constructed from a function object.

Parameters
xA double.
paramsThe parameters, which are always set to be a pointer to the function object.
Returns
the function object function evaluated at x.

Definition at line 544 of file function_scl.hpp.

References gsl::sf::mathieu::b().

Referenced by function_scl().

◆ operator=() [1/2]

function_scl & gsl::function_scl::operator= ( function_scl &&  v)
inline

Move operator.

Parameters
vThe function_scl to move.
Returns
A reference to f in this.

Definition at line 518 of file function_scl.hpp.

References count, and f.

◆ operator=() [2/2]

function_scl & gsl::function_scl::operator= ( function_scl const &  v)
inline

The assignment operator.

This makes a shared copy.

Parameters
vThe function_scl to copy

Definition at line 488 of file function_scl.hpp.

References count, and f.

Member Data Documentation

◆ count

size_t* gsl::function_scl::count
private

The shared reference count.

Definition at line 364 of file function_scl.hpp.

Referenced by function_scl(), operator=(), and ~function_scl().

◆ f

base_F* gsl::function_scl::f
private

Definition at line 360 of file function_scl.hpp.

Referenced by function_scl(), operator=(), and ~function_scl().


The documentation for this class was generated from the following file: