12 #ifndef ECL_UTILITIES_FUNCTION_OBJECTS_HPP_ 13 #define ECL_UTILITIES_FUNCTION_OBJECTS_HPP_ 19 #include <ecl/concepts/nullary_function.hpp> 20 #include "../utilities/references.hpp" 45 template <
typename R =
void>
68 template <
typename A,
typename R =
void>
72 typedef A argument_type;
77 virtual result_type
operator()(argument_type arg) = 0;
78 virtual ~UnaryFunction() {};
96 template <
typename A1,
typename A2,
typename R =
void>
97 class BinaryFunction {
100 typedef A1 first_argument_type;
101 typedef A2 second_argument_type;
109 virtual result_type
operator()(first_argument_type arg1, second_argument_type arg2) = 0;
110 virtual ~BinaryFunction() {};
125 template <
typename R =
void>
136 NullaryFreeFunction( R (*
function)() ) : free_function(function) {}
137 virtual ~NullaryFreeFunction() {};
149 R (*free_function)();
170 NullaryFreeFunction(
void (*
function)() ) : free_function(function) {}
172 virtual ~NullaryFreeFunction() {};
184 void (*free_function)();
199 template <
typename A,
typename R =
void>
200 class UnaryFreeFunction :
public UnaryFunction<A,R>
211 UnaryFreeFunction( R (*
function)(A) ) : free_function(function) {}
213 virtual ~UnaryFreeFunction() {};
222 R
operator()(A a) {
return free_function(a); }
225 R (*free_function)(A);
237 template <
typename A>
238 class UnaryFreeFunction<A,void> :
public UnaryFunction<A,void>
249 UnaryFreeFunction(
void (*
function)(A) ) : free_function(function) {}
251 virtual ~UnaryFreeFunction() {};
262 void (*free_function)(A);
291 template <
typename A,
typename R =
void>
303 BoundUnaryFreeFunction( R (*
function)(A), A a ) : free_function(function), argument(a) {}
304 virtual ~BoundUnaryFreeFunction() {};
312 R
operator()() {
return free_function(argument); }
315 R (*free_function)(A);
328 template <
typename A>
340 BoundUnaryFreeFunction(
void (*
function)(A), A a ) : free_function(function), argument(a) {}
341 virtual ~BoundUnaryFreeFunction() {};
349 void operator()() { free_function(argument); }
352 void (*free_function)(A);
390 template <
typename C,
typename R =
void>
391 class NullaryMemberFunction :
public UnaryFunction<C&,R> {
401 NullaryMemberFunction( R (C::*
function)()) : member_function(function) {}
402 virtual ~NullaryMemberFunction() {};
415 return (class_object.*member_function)();
418 R (C::*member_function)();
431 template <
typename C>
432 class NullaryMemberFunction<C,void> :
public UnaryFunction<C&,void> {
442 NullaryMemberFunction(
void (C::*
function)()) : member_function(function) {}
443 virtual ~NullaryMemberFunction() {};
454 (class_object.*member_function)();
457 void (C::*member_function)();
486 template <
typename C,
typename A,
typename R =
void>
487 class UnaryMemberFunction :
public BinaryFunction<C&,A,R> {
497 UnaryMemberFunction( R (C::*
function)(A)) : member_function(function) {}
498 virtual ~UnaryMemberFunction() {};
510 return (class_object.*member_function)(a);
513 R (C::*member_function)(A);
526 template <
typename C,
typename A>
527 class UnaryMemberFunction<C,A,void> :
public BinaryFunction<C&,A,void> {
537 UnaryMemberFunction(
void (C::*
function)(A)) : member_function(function) {}
538 virtual ~UnaryMemberFunction() {};
550 (class_object.*member_function)(a);
553 void (C::*member_function)(A);
585 template <
typename C,
typename R =
void>
596 BoundNullaryMemberFunction( R (C::*
function)(), C &class_object) :
597 member_class(class_object),
598 member_function(function)
600 virtual ~BoundNullaryMemberFunction() {};
609 R
operator()() {
return (member_class.*member_function)(); }
613 R (C::*member_function)();
627 template <
typename C>
628 class BoundNullaryMemberFunction<C,void> :
public NullaryFunction<void> {
638 BoundNullaryMemberFunction(
void (C::*
function)(), C &class_object) :
639 member_class(class_object),
640 member_function(function)
643 virtual ~BoundNullaryMemberFunction() {};
649 void operator()() { (member_class.*member_function)(); }
653 void (C::*member_function)();
684 template <
typename C,
typename A,
typename R =
void>
685 class PartiallyBoundUnaryMemberFunction :
public UnaryFunction<A,R> {
695 PartiallyBoundUnaryMemberFunction( R (C::*
function)(A), C &class_object) :
696 member_class(class_object),
697 member_function(function)
699 virtual ~PartiallyBoundUnaryMemberFunction() {};
709 return (member_class.*member_function)(a);
713 void (C::*member_function)(A);
743 template <
typename C,
typename A,
typename R =
void>
755 BoundUnaryMemberFunction( R (C::*
function)(A), C &class_object, A a) :
756 member_class(class_object),
757 member_function(function),
760 virtual ~BoundUnaryMemberFunction() {};
769 return (member_class.*member_function)(argument);
773 void (C::*member_function)(A);
806 template <
typename C,
typename A,
typename B,
typename R =
void>
807 class PartiallyBoundBinaryMemberFunction :
public BinaryFunction<A,B,R> {
817 PartiallyBoundBinaryMemberFunction( R (C::*
function)(A, B), C &class_object) :
818 member_class(class_object),
819 member_function(function)
821 virtual ~PartiallyBoundBinaryMemberFunction() {};
832 return (member_class.*member_function)(a, b);
836 void (C::*member_function)(A, B);
854 template <
typename FunctionObject,
typename Result =
void>
866 NullaryFunctionCopy(
const FunctionObject &f_o ) : function_object(f_o) {
869 virtual ~NullaryFunctionCopy() {};
878 Result
operator()() {
return function_object(); }
881 FunctionObject function_object;
893 template <
typename FunctionObject>
894 class NullaryFunctionCopy<FunctionObject,void> :
public NullaryFunction<void>
905 explicit NullaryFunctionCopy(
const FunctionObject &f_o ) : function_object(f_o) {
908 virtual ~NullaryFunctionCopy() {};
918 FunctionObject function_object;
934 template <
typename FunctionObject,
typename Result =
void>
945 explicit NullaryFunctionReference(
const ReferenceWrapper<FunctionObject> &wrapper ) : function_object(wrapper.reference()) {
948 virtual ~NullaryFunctionReference() {};
957 Result
operator()() {
return function_object(); }
960 FunctionObject &function_object;
974 template <
typename FunctionObject>
975 class NullaryFunctionReference< FunctionObject, void > :
public NullaryFunction<void>
985 explicit NullaryFunctionReference(
const ReferenceWrapper<FunctionObject> &wrapper ) : function_object(wrapper.reference()) {
988 virtual ~NullaryFunctionReference() {};
998 FunctionObject &function_object;
1015 template <
typename FunctionObject,
typename T,
typename Result =
void>
1016 class UnaryFunctionCopy :
public UnaryFunction<T, Result>
1027 UnaryFunctionCopy(
const FunctionObject &f_o ) : function_object(f_o) {
1030 virtual ~UnaryFunctionCopy() {};
1039 Result
operator()(T t) {
return function_object(t); }
1042 FunctionObject function_object;
1054 template <
typename FunctionObject,
typename T>
1055 class UnaryFunctionCopy<FunctionObject,T,void> :
public UnaryFunction<T, void>
1066 explicit UnaryFunctionCopy(
const FunctionObject &f_o ) : function_object(f_o) {
1069 virtual ~UnaryFunctionCopy() {};
1079 FunctionObject function_object;
1095 template <
typename FunctionObject,
typename T,
typename Result =
void>
1096 class UnaryFunctionReference :
public UnaryFunction<T, Result>
1106 explicit UnaryFunctionReference(
const ReferenceWrapper<FunctionObject> &wrapper ) : function_object(wrapper.reference()) {
1110 virtual ~UnaryFunctionReference() {};
1118 Result
operator()(T t) {
return function_object(t); }
1121 FunctionObject &function_object;
1135 template <
typename ReferenceWrapper,
typename T>
1136 class UnaryFunctionReference< ReferenceWrapper, T, void > :
public UnaryFunction<T,void>
1147 explicit UnaryFunctionReference(
const ReferenceWrapper &wrapper ) : function_object(wrapper.reference()) {
1150 virtual ~UnaryFunctionReference() {};
1160 FunctionObject &function_object;
1179 template <
typename R>
1197 template <
typename A,
typename R>
1217 template <
typename A,
typename R,
typename I>
1238 template <
typename A,
typename R,
typename I>
1256 template <
typename C,
typename R>
1275 template <
typename C,
typename R>
1294 template <
typename C,
typename A,
typename R>
1316 template <
typename C,
typename A,
typename R>
1338 template <
typename C,
typename A,
typename R,
typename I>
1365 template <
typename C,
typename A,
typename R,
typename I>
Nullary function object for bound unary global/static functions.
Binary function object for unary member functions.
virtual result_type operator()()=0
Unary function object for partially bound unary member functions.
Unary function object for member functions without arguments.
Nullary function object for bound nullary member functions.
BoundUnaryFreeFunction< A, R > generateFunctionObject(R(*function)(A), I &a)
Generate a nullary function object from a bound unary global/static function.
virtual ~NullaryFunction()
Nullary function object for bound unary member functions.
Unary function object for global/static functions.
#define ecl_compile_time_concept_check(Model)
Compile time concept checking assertion.
Nullary function object for void global/static functions.