diff --git a/applications/test/token/Test-token.cxx b/applications/test/token/Test-token.cxx index 055833fbbb..52b2eb7571 100644 --- a/applications/test/token/Test-token.cxx +++ b/applications/test/token/Test-token.cxx @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2017-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,6 +35,9 @@ Description #include "labelList.H" #include "scalarList.H" #include "DynamicList.H" +#include "labelField.H" +#include "scalarField.H" +#include "SubField.H" #include "SpanStream.H" #include "formattingEntry.H" @@ -90,7 +93,7 @@ int main(int argc, char *argv[]) { // This also works, but not actually using the autoPtr directly - autoPtr> ptr + autoPtr ptr ( new token::Compound(identity(10, -9)) ); @@ -131,44 +134,50 @@ int main(int argc, char *argv[]) Info<< "resized: " << ctok1.info() << nl << ctok1 << endl; - const scalarList* listptr = ctok1.compoundToken().isA(); - if (listptr) { - for (scalar& val : const_cast(*listptr)) + // Using isA<> on compoundToken() + const auto* listptr = ctok1.compoundToken().isA(); + if (listptr) { - val *= 5; - } + // sneaky, SubField bypasses const! + scalarField::subField fld(*listptr); + fld *= 5; - Info<< "multiplied List: " - << ctok1.info() << nl << ctok1 << endl; + Info<< "multiplied List: " + << ctok1.info() << nl << ctok1 << endl; + } } - listptr = ctok1.isCompound(); - if (listptr) { - for (scalar& val : const_cast(*listptr)) - { - val /= 2; - } + // Using isCompound<...> - combined check - Info<< "divided List: " - << ctok1.info() << nl << ctok1 << endl; + const auto* listptr = ctok1.isCompound(); + if (listptr) + { + scalarField::subField fld(*listptr); + fld /= 2; + + Info<< "divided List: " + << ctok1.info() << nl << ctok1 << endl; + } } - const labelList* listptr2 = ctok1.isCompound(); - if (listptr2) { - for (label& val : const_cast(*listptr2)) - { - val /= 2; - } + // Using isCompound<...> - combined check - Info<< "divided List