From 44603ea96d0adf535f2a90bf1f1bafbc1aa80aa5 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 13 Nov 2014 03:48:01 +0100 Subject: [PATCH] WIP: DSL verb token implementation draft the idea ist to build some kind of "smart" enum constants, which allow for double dispatch through a member function pointer, invoking a virtual function on a common handler interface --- tests/library/verb-function-dispatch-test.cpp | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/library/verb-function-dispatch-test.cpp b/tests/library/verb-function-dispatch-test.cpp index 0ec5c1603..8775cfcb3 100644 --- a/tests/library/verb-function-dispatch-test.cpp +++ b/tests/library/verb-function-dispatch-test.cpp @@ -24,9 +24,10 @@ #include "lib/test/run.hpp" //#include "lib/util.hpp" #include "lib/format-string.hpp" - +#include "lib/meta/function.hpp" //#include +#include //#include #include //#include @@ -42,9 +43,42 @@ using util::_Fmt; namespace lib { namespace test{ + template + class VerbToken + { + using Ret = typename lib::meta::_Fun::Ret; + + typedef Ret REC::*Handler (void); + + Handler handler_; + + public: + Ret + applyTo (REC& receiver) + { + return receiver.*handler_(); + } + }; + + class Receiver + { + public: + virtual ~Receiver() { } ///< this is an interface + + virtual string woof() =0; + virtual string honk() =0; + virtual string moo() =0; + virtual string meh() =0; + }; + namespace { const string BEGINNING("silence"); + + using Verb = VerbToken; + using VerbSeq = std::initializer_list; } + + /** * a receiver of verb-tokens, * which renders them verbosely