From 4c59e16f06bece310f7d628b9dab6ef530eab3ac Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 29 Aug 2015 18:56:19 +0200 Subject: [PATCH] add the visitor-predicate as a second option contrary to the Visitor, accepting a Predicate is const, and -- of course -- the Predicate invocation returns bool. This can be used to implement comparison operators or search functions on Variant based data structures. --- src/lib/variant.hpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/variant.hpp b/src/lib/variant.hpp index 5884134fd..d675e233f 100644 --- a/src/lib/variant.hpp +++ b/src/lib/variant.hpp @@ -224,8 +224,9 @@ namespace lib { virtual ~Buffer() {} ///< this is an ABC with VTable - virtual void dispatch (Visitor&) =0; - virtual operator string() const =0; + virtual void dispatch (Visitor&) =0; + virtual bool dispatch (Predicate&) const =0; + virtual operator string() const =0; }; @@ -317,6 +318,15 @@ namespace lib { typeDispatcher.handle (this->access()); } + bool + dispatch (Predicate& visitor) const + { + using Dispatcher = VFunc::template ValueAcceptInterface; + + Dispatcher& typeDispatcher = visitor; + return typeDispatcher.handle (this->access()); + } + /** diagnostic helper */ operator string() const; }; @@ -452,6 +462,12 @@ namespace lib { { buffer().dispatch (visitor); } + + bool + accept (Predicate& visitor) const + { + return buffer().dispatch (visitor); + } };