+#pragma once
+
+#if defined HAS_CXX11_VARIADIC_TEMPLATES
+
+template<typename ReturnType, typename... Args> class CoreExport Handler : public classbase
+{
+ public:
+ virtual ~Handler() { }
+ virtual ReturnType Call(Args...) = 0;
+};
+
+template<typename ReturnType, typename... Args> class CoreExport Caller
+{
+ public:
+ Handler<ReturnType, Args...>* target;
+
+ Caller(Handler<ReturnType, Args...>* initial) : target(initial) { }
+ virtual ~Caller() { }
+
+ virtual ReturnType operator()(const Args&... params)
+ {
+ return this->target->Call(params...);
+ }
+};
+
+/* Below here is compat with the old API */
+#define HandlerBase0 Handler
+#define HandlerBase1 Handler
+#define HandlerBase2 Handler
+#define HandlerBase3 Handler
+#define HandlerBase4 Handler
+#define HandlerBase5 Handler
+#define HandlerBase6 Handler
+#define HandlerBase7 Handler
+#define HandlerBase8 Handler
+
+#define caller1 Caller
+#define caller2 Caller
+#define caller3 Caller
+#define caller4 Caller
+#define caller5 Caller
+#define caller6 Caller
+#define caller7 Caller
+#define caller8 Caller
+
+#define DEFINE_HANDLER0(NAME, RETURN) \
+ class CoreExport NAME : public Handler<RETURN> { public: NAME() { } virtual RETURN Call(); }
+
+#define DEFINE_HANDLER1(NAME, RETURN, V1) \
+ class CoreExport NAME : public Handler<RETURN, V1> { public: NAME() { } virtual RETURN Call(V1); }
+
+#define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2> { public: NAME() { } virtual RETURN Call(V1, V2); }
+
+#define DEFINE_HANDLER3(NAME, RETURN, V1, V2, V3) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3> { public: NAME() { } virtual RETURN Call(V1, V2, V3); }
+
+#define DEFINE_HANDLER4(NAME, RETURN, V1, V2, V3, V4) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4); }
+
+#define DEFINE_HANDLER5(NAME, RETURN, V1, V2, V3, V4, V5) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5); }
+
+#define DEFINE_HANDLER6(NAME, RETURN, V1, V2, V3, V4, V5, V6) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5, V6> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6); }
+
+#define DEFINE_HANDLER7(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5, V6, V7> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7); }
+
+#define DEFINE_HANDLER8(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7, V8) \
+ class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5, V6, V7, V8> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7, V8); }
+
+#else
+
+/** The templates below can be auto generated by tools/create_templates.pl.
+ * They are used to represent a functor with a given number of parameters and
+ * a specific return type. To prevent passing the wrong number of parameters
+ * and have the compiler detect this error at build-time, each class is numbered
+ * according to the number of parameters it takes, e.g. caller0, caller1, caller2.
+ * These have been generated from zero parameters to eight.
+ *
+ * If you want to declare a functor which takes two parameters, a User and a Channel,
+ * and returns bool, simply create it like this:
+ *
+ * caller2<bool, User*, Channel*> MyFunction;
+ *
+ * and initialize it correctly, when placed into a class you will be able to call it:
+ *
+ * bool n = someclass->MyFunction(someuser, somechan);
+ *
+ * These functor templates work this way so that you can simply and easily allow
+ * for these class methods to be overridden from within a module, e.g. have a module
+ * which completely replaces the code for IsNick, etc. For example, with the example
+ * above:
+ *
+ * MyNewFunction replaceme(ServerInstance);
+ *
+ * someclass->MyFunction = \&replaceme;
+ *
+ * After this point, calls to someclass->MyFunction will call the new code in your
+ * replacement functor.
+ *
+ * This is a very powerful feature which should be considered 'advanced' and not for
+ * beginners. If you do not understand these templates, STAY AWAY from playing with
+ * this until you do, as if you get this wrong, this can generate some pretty long
+ * winded and confusing error messages at compile time.
+ */
+template <typename ReturnType> class CoreExport HandlerBase0 : public classbase