CMemberFunctionTraits.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_ring_CMemberFunctionTraits_h_
#define polybori_ring_CMemberFunctionTraits_h_
// include basic definitions
#include <polybori/pbori_defs.h>
BEGIN_NAMESPACE_PBORI
template<class MemberFuncPtr>
class CMemberFunctionTraits;
template <class Type, class ResultType, class ArgType, class ObjRef>
class CMemberFunctionTraitsBase {
public:
typedef ResultType result_type;
typedef ArgType argument_type;
typedef Type object_type;
typedef ObjRef object_reference;
};
template <class Type, class ResultType>
class CMemberFunctionTraits<ResultType (Type::*)()>:
public CMemberFunctionTraitsBase<Type, ResultType, void, Type&> { };
template <class Type, class ResultType>
class CMemberFunctionTraits<ResultType (Type::*)() const>:
public CMemberFunctionTraitsBase<Type, ResultType, void, const Type&> { };
template <class Type, class ResultType, class ArgType>
class CMemberFunctionTraits<ResultType (Type::*)(ArgType)>:
public CMemberFunctionTraitsBase<Type, ResultType, ArgType, Type&> { };
template <class Type, class ResultType, class ArgType>
class CMemberFunctionTraits<ResultType (Type::*)(ArgType) const>:
public CMemberFunctionTraitsBase<Type, ResultType, ArgType, const Type&> { };
template <class MemberFct>
class MemberFunctionOperator {
typedef CMemberFunctionTraits<MemberFct> traits;
public:
MemberFunctionOperator(MemberFct func): m_func(func) {}
typename traits::result_type operator()(typename traits::object_reference obj,
typename traits::argument_type arg) {
return (obj .* m_func)(arg);
}
private:
MemberFct m_func;
};
template <class MemberFct>
MemberFunctionOperator<MemberFct>
member_function_operator(MemberFct func) {
return MemberFunctionOperator<MemberFct>(func);
}
END_NAMESPACE_PBORI
#endif