diff options
| author | 2020-04-26 16:31:31 +0200 | |
|---|---|---|
| committer | 2020-04-26 16:31:31 +0200 | |
| commit | 5f68d8399b771da0f3500a5d037315607e25c78d (patch) | |
| tree | f1600941bde0bfd427f92f8d0bfa7fb97c65d4c6 /validator.cpp | |
| parent | 214945c0cbf14544df5defdfea0bc89c87626274 (diff) | |
| download | OneRoll-5f68d8399b771da0f3500a5d037315607e25c78d.tar.gz OneRoll-5f68d8399b771da0f3500a5d037315607e25c78d.zip | |
Add support for OnEachValue compare method.
Diffstat (limited to 'validator.cpp')
| -rw-r--r-- | validator.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/validator.cpp b/validator.cpp index da6e3a1..201574b 100644 --- a/validator.cpp +++ b/validator.cpp @@ -39,6 +39,20 @@ qint64 Validator::onEach(const std::vector<Die*>& b, bool recursive, bool unligh } template <typename Functor> +qint64 Validator::onEachValue(const std::vector<Die*>& 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 <typename Functor> qint64 Validator::oneOfThem(const std::vector<Die*>& b, bool recursive, bool unlight, Functor functor) const { auto oneOfThem= std::any_of(b.begin(), b.end(), @@ -90,6 +104,9 @@ qint64 Validator::validResult(const std::vector<Die*>& 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; |