From 1476de89ee36a712c71b923fd541ec0f2bbcc6f1 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 20 Oct 2023 10:31:57 +0200 Subject: [PATCH] ENH: add unary functor for Foam::zero - acts somewhat like an identity op that 'swallows' its parameter and maps back to zero. --- .../test/predicates/Test-predicates.C | 23 +++++++------ src/OpenFOAM/primitives/traits/one.H | 20 +++--------- src/OpenFOAM/primitives/traits/zero.H | 32 +++++++------------ 3 files changed, 29 insertions(+), 46 deletions(-) diff --git a/applications/test/predicates/Test-predicates.C b/applications/test/predicates/Test-predicates.C index 246e6fcceb..1766923ca3 100644 --- a/applications/test/predicates/Test-predicates.C +++ b/applications/test/predicates/Test-predicates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -81,32 +81,35 @@ int main(int argc, char *argv[]) labelList values(identity(40, -10)); - Info<<"words: " << flatOutput(words) << endl; - Info<<"values: " << flatOutput(values) << endl; + Info<< "words: " << flatOutput(words) << endl; + Info<< "values: " << flatOutput(values) << endl; regExp matcher(".*_.*"); - Info<<"With '_': "; + Info<< "With '_': "; printMatching(words, matcher); - Info<<"All: "; + Info<< "All: "; printMatching(words, predicates::always()); - Info<<"None: "; + Info<< "None: "; printMatching(words, predicates::never()); - Info<<"Neg values: "; + Info<< "Neg values: "; printMatching(values, [](const label v) { return v < 0; }); - Info<<"Even values: "; + Info<< "Even values: "; printMatching(values, [](const label v) { return !(v % 2); }); - Info<<"All: "; + Info<< "All: "; printMatching(values, predicates::always()); - Info<<"None: "; + Info<< "None: "; printMatching(values, predicates::never()); + Info<< "zero:"; + Info<< static_cast