From 5f68d8399b771da0f3500a5d037315607e25c78d Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 26 Apr 2020 16:31:31 +0200 Subject: Add support for OnEachValue compare method. --- validator.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'validator.cpp') diff --git a/validator.cpp b/validator.cpp index da6e3a1..201574b 100644 --- a/validator.cpp +++ b/validator.cpp @@ -38,6 +38,20 @@ qint64 Validator::onEach(const std::vector& b, bool recursive, bool unligh return result; } +template +qint64 Validator::onEachValue(const std::vector& b, bool recursive, bool unlight, Functor functor) const +{ + qint64 result= 0; + std::for_each(b.begin(), b.end(), [this, recursive, unlight, functor, &result](Die* die) { + if(hasValid(die, recursive, unlight)) + { + ++result; + functor(die, recursive, unlight); + } + }); + return result; +} + template qint64 Validator::oneOfThem(const std::vector& b, bool recursive, bool unlight, Functor functor) const { @@ -90,6 +104,9 @@ qint64 Validator::validResult(const std::vector& b, bool recursive, bool u case Dice::OnEach: result= onEach(b, recursive, unlight, functor); break; + case Dice::OnEachValue: + result= onEachValue(b, recursive, unlight, functor); + break; case Dice::OneOfThem: result= oneOfThem(b, recursive, unlight, functor); break; -- cgit v1.2.3-70-g09d2