From 92b779c6b82ef4bdfa1e1e278aa294012ba4b803 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 29 Aug 2015 17:31:42 +0200 Subject: [PATCH] Design: extend the Variant::Visitor (2) extend to arbitrary return values --- research/try.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/research/try.cpp b/research/try.cpp index 56beeb48b..4dbbc0b0f 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -58,17 +58,22 @@ using std::string; using std::cout; using std::endl; - - + +template +struct VFunc + { + template struct ValueAcceptInterface { - virtual void handle(VAL&) { /* NOP */ }; + virtual RET handle(VAL&) { /* do nothing */ return RET(); }; }; template using VisitorInterface = lib::meta::InstantiateForEach; + + }; template @@ -78,15 +83,18 @@ struct Var B b; using TYPES = lib::meta::Types; - using Visitor = VisitorInterface; - void - accept (Visitor& visitor) + template + using Visitor = typename VFunc::template VisitorInterface; + + template + RET + accept (Visitor& visitor) { - ValueAcceptInterface& visA = visitor; - ValueAcceptInterface& visB = visitor; + typename VFunc::template ValueAcceptInterface& visA = visitor; + typename VFunc::template ValueAcceptInterface& visB = visitor; visA.handle (a); - visB.handle (b); + return visB.handle (b); } @@ -102,7 +110,7 @@ struct Var class Visi - : public Var::Visitor + : public Var::Visitor { virtual void handle(int& i) { ++i; } @@ -119,7 +127,7 @@ main (int, char**) cout << string(var)<(visi); cout << string(var)<