Boost Overload Terminology
Callable entities, functors, function objects are all terms used in C++ literature, however they are fuzzy because there is no shared definition: everyone uses these terms with a more strict or larger meaning. From this thought rises the need to formulate a clear and sensible definition for terms used in the boost overload documentation.
Function Objects
A type F is a model of
class type function if F is a class that exposes a public function call operator. An instance of F is referred to as a
function object.
A type F is a model of
class type overloaded function if it is a model of class type function that owns two or more overloads of the function call operator. An instance of F is referred to as an
overloaded function object.
A type F is a model of
class type template function if it is a model of class type function that implements a template function call operator. An instance of F is referred to as a
template function object.
A type F is a model of
class type multi-signature function if it is a model of class type overloaded function or class type template function or both. An instance of F is referred to as a
multi-signature function object.
Callable Entities and Signatures
We'll say that
f is
a callable entity if we can find an integer N >= 0 and N types A
1, ..., A
N such that the expression
f(a
1, ..., a
N) is a correct expression for an ISO-compliant C++ compiler for any N-tuple (a
1, ..., a
N) where the object a
i is of type A
i for i = 1,...,N. The expression
f(a
1, ..., a
N) is referred to as a
call to
f. The type
R (A1, ..., AN) is a supported
signature of
f, where, in case the expression
f(a
1, ..., a
N) evaluates to an object r, R is the type of r, or if it doesn't evaluate to anything, R is the
void type.
Given a signature S := R (A1, ..., AN) with N >= 0, the type Ai is said the i-th argument type of S and the type R is the return type of S, finally N is the arity of S.
If a callable entity supports only one signature these naming conventions extend naturally to the callable entity.
Examples of callable entities are:
- free functions
- function objects
- the result of applying the unary operator * to a pointer to function
- the result of applying the binary operators . or -> being the right operand a member function of any class T and the left operand an object of type T or (const) T* respectively
- the result of applying the binary operators .* or ->* being the right
operand a pointer to member function of any class T and the left operand an object
of type T or (const) T* respectively.
Argument Binding
It is a technique to make up a new callable entity by binding one of the arguments of another callable entity to a fixed object.
Given an integer i > 0, an integer N >= i and a callable entity
f with a supported signature
R (A1, ..., AN) , once fixed an object
t of type
Ai we can define a new callable entity
g that supports a signature
R (A1, ..., ^Ai, ..., AN) with arity N-1 by setting
g(a
1, ..., ^a
i, ..., a
N) :=
f(a
1, ...,
t, ..., a
N) for any (N-1)-tuple (a
1, ..., ^a
i, ..., a
N) where
t is placed at the i-th position and where the object a
k is of type A
k for k = 1,..., ^i, ..., N. For the new callable entity produced by the binding will be used the notation
g := (
f|i:
t) .
( The notation x
1, ..., ^x
i, ..., x
N is used to denote that the i-th term x
i is erased from the list. )
Call Forwarding
Well' say that a callable entity
f performs a forwarding call to a callable entity
g if a call to
f is equivalent to a call to
g when the passed arguments are the same. In particular
f has to return the same result returned by
g and their return types have to be the same. If
g doesn't return anything,
f has to return nothing, too.
We'll say that a member function
f of a class T performs a forwarding call to a callable entity
g if for any object
t of type T the callable entity
t.
f performs a forwarding call to
g.
We'll say that a type T has access to a callable entity if it owns a method that performs a forwarding call to the given callable entity.
Member Functions
SignatureGeneralizing we'll say that a member function
f of a class T
supports a signature S if given any object
t of type T the callable
entity
t.
f supports the signature S.
Explicit SignatureGiven a non-const qualified member function
f of a class T and that supports a signature
R (A1, ..., AN) with N >= 0, we'll call an
explicit signature of
f the following signature:
Given a const qualified member function
f of a class T and that supports a signature
R (A1, ..., AN) with N >= 0, we'll call an
explicit signature of
f the following signature:
- R ( const T*, A1, ..., AN)
Call ForwardingWe'll say that a callable entity
g performs a forwarding call to a non-const qualified member function
f of a class T if the first argument type of
g is T* and if for any object
p of type T* the callable entity obtained by binding
p to the first argument of
g performs a forwarding call to the callable entity
p->
f.
We'll say that a callable entity
g performs a forwarding call to a const qualified member function
f
of a class T if the first argument type of
g is const T* and if for any object
p of type T* or of type const T* the
callable entity obtained binding
p to the first argument of
g performs a forwarding call to the callable entity
p->
f.
We'll say that a member function
g of a class T performs a forwarding call to a member function
f if for any object
t of type T the callable entity
t.
g performs a forwarding call to
f.
We'll say that a type T has access to a member function if it owns a method that is able to perform a forwarding call to the given member function.
Functors
A callable entity is said a
functor if the variable entities that occur in its definition are objects.
Examples of functors are:
- function objects
- callable entities involving a pointer to a function
- callable entities involving a pointer to member function.
Dynamic Function Concept
A type F is a model of Dynamic Function with signature S if we have that :
The template class boost::function is a family of models of Dynamic Function.
Any instantiation of the template class overload that support one and only one signature is a model of Dynamic Function.
Dynamic Overloaded Function Concept
A type F is a model of
Dynamic Overloaded Function supporting the signatures S
1, ..., S
N with N >= 2 if for each integer i s.t. 1 <= i <= N we have that :
- F is a model of class type overloaded function;
- F is able to achieve access at run-time to callable entities that supports the signature Si
and/or to member functions having Si as an explicit signature;
the current accessible callable entity or member function related to Si will be called the callable target tied to Si;
if there is no accessible callable entity or member function related to Si the callable target tied to Si is said empty;
- F owns an overloaded operator() that performs a forwarding call to the callable target tied to Si;
- F provides a method to set/replace the callable target tied to Si;
- F provides a method to check if the callable target tied to Si is empty
or it provides by design that all the callable targets are never empty.
Any instantiation of the template class overload that support more than one signature is a model of Dynamic Overloaded Function.
Acknowledgements
Prepared by Marco Cecchetti
(
mrcekets@gmail.com)
Kindly revised by Dean Michael Berris (
mikhailberis@gmail.com)
Released under the Boost Software License version 1.0
(
http://boost.org/LICENSE_1_0.txt)
Date: November 5, 2007