#ifndef FUNCTION_H #define FUNCTION_H #include class NullType {}; template struct Function; struct Functor { template R operator()(); template R operator()(T1); template R operator()(T1,T2); virtual ~Functor() {} }; template R Functor::operator()() { Function* self = dynamic_cast*>(this); assert(self != 0); return self->operator()(); } template R Functor::operator ()(T1 t1) { Function* self = dynamic_cast*>(this); assert(self != 0); return self->operator()(t1); } template R Functor::operator ()(T1 t1, T2 t2) { Function* self = dynamic_cast*>(this); assert(self != 0); return self->operator()(t1, t2); } template struct Function : public Functor { private: typedef R (*F)(); public: Function() {} Function(F f) : m_f(f) {} virtual R operator ()() { return m_f(); } private: F m_f; }; template struct Function : public Functor { private: typedef R (*F)(T1); public: Function() {} Function(F f) : m_f(f) {} virtual R operator ()(T1 t1) { return m_f(t1); } private: F m_f; }; template struct Function : public Functor { private: typedef R (*F)(T1,T2); public: Function() {} Function(F f) : m_f(f) {} virtual R operator ()(T1 t1, T2 t2) { return m_f(t1, t2); } private: F m_f; }; template struct Function : public Function { private: typedef R (C::*F)(); public: Function(F f, C c) : m_f(f), m_c(c) {} virtual R operator ()() { return (c.*m_f)(); } private: F m_f; C m_c; }; template struct Function : public Function { private: typedef R (C::*F)() const; public: Function(F f, C c) : m_f(f), m_c(c) {} virtual R operator ()() { return (c.*m_f)(); } private: F m_f; C m_c; }; template struct Function : public Function { private: typedef R (C::*F)(T1); public: Function(F f, C c) : m_f(f), m_c(c) {} virtual R operator ()(T1 t1) { return (c.*m_f)(t1); } private: F m_f; C m_c; }; template struct Function : public Function { private: typedef R (C::*F)(T1) const; public: Function(F f, C c) : m_f(f), m_c(c) {} virtual R operator ()(T1 t1) { return (c.*m_f)(t1); } private: F m_f; C m_c; }; template struct Function : public Function { private: typedef R (C::*F)(T1,T2); public: Function(F f, C c) : m_f(f), m_c(c) {} virtual R operator ()(T1 t1, T2 t2) { return (c.*m_f)(t1, t2); } private: F m_f; C m_c; }; template struct Function : public Function { private: typedef R (C::*F)(T1,T2) const; public: Function(F f, C c) : m_f(f), m_c(c) {} virtual R operator ()(T1 t1, T2 t2) { return (c.*m_f)(t1, t2); } private: F m_f; C m_c; }; #endif // FUNCTION_H