//////////////////////////////////////////////////////////////////////////////// // The Loki Library // Copyright (c) 2005 Peter Kümmel // Permission to use, copy, modify, distribute and sell this software for any // purpose is hereby granted without fee, provided that the above copyright // notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. // The author makes no representations about the // suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// #define LOKI_ENABLE_FUNCTION #include #include namespace Loki { //////////////////////////////////////////////////////////////////////////////// /// \struct Function /// /// \ingroup FunctorGroup /// Allows a boost/TR1 like usage of Functor. /// /// e.g. Functor becomes Function //////////////////////////////////////////////////////////////////////////////// template struct Function : public Functor { }; template struct Function : public Functor { typedef Functor FBase; Function() : FBase() {} Function(const Function& func) : FBase() { if( !func.empty()) FBase::operator=(func); } // test on emptiness template Function(Function func) : FBase() { if(!func.empty()) FBase::operator=(func); } // clear by '= 0' Function(const int i) : FBase() { if(i==0) FBase::clear(); else throw std::runtime_error("Loki::Function(const int i): i!=0"); } template Function(Func func) : FBase(func) {} template Function(const Host& host, const Func& func) : FBase(host,func) {} }; //////////////////////////////////////////////////////////////////////////////// // macros for the repetitions //////////////////////////////////////////////////////////////////////////////// #define LOKI_FUNCTION_BODY \ \ Function() : FBase() {} \ \ Function(const Function& func) : FBase() \ { \ if( !func.empty()) \ FBase::operator=(func); \ } \ \ Function(const int i) : FBase() \ { \ if(i==0) \ FBase::clear(); \ else \ throw std::runtime_error( \ "Loki::Function(const int i): i!=0"); \ } \ \ template \ Function(Func func) : FBase(func) {} \ \ template \ Function(const Host& host, const Func& func): FBase(host,func) {} #define LOKI_FUNCTION_R2_CTOR_BODY \ \ : FBase() \ { \ if(!func.empty()) \ FBase::operator=(func); \ } //////////////////////////////////////////////////////////////////////////////// // repetitions //////////////////////////////////////////////////////////////////////////////// template struct Function : public Loki::Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor >FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; }// namespace Loki