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.
This commit is contained in:
parent
de3726c856
commit
4c59e16f06
1 changed files with 18 additions and 2 deletions
|
|
@ -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<bool>::template ValueAcceptInterface<const TY>;
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue