From 98ccb7df6b9ada14cf320b79afc9c5b5b272c69c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 5 Nov 2023 15:17:35 +0100 Subject: [PATCH] ENH: extend VectorSpace traits to include pTraits_cmptType - The pTraits_cmptType returns the data type of 'cmptType' (for arithmetic and VectorSpace types) or is simply a pass-through. This can be combined with the pTraits_nComponents for casting. For example, function ( reinterpret_cast::type*>(buf.data()), (buf.size()/pTraits_nComponents::value) ); ENH: extend Foam::identityOp so support array indexing (pass-through) --- applications/test/UList/Test-UList.C | 15 +++++++++++++ applications/test/pTraits/Test-pTraits.C | 18 +++++++++++++-- src/OpenFOAM/include/stdFoam.H | 15 +++++++++---- .../primitives/Vector/bools/boolVector.H | 22 +++++++++++++++++++ src/OpenFOAM/primitives/complex/complex.H | 16 +++++++++++++- src/OpenFOAM/primitives/traits/pTraits.H | 17 +++++++++++++- 6 files changed, 95 insertions(+), 8 deletions(-) diff --git a/applications/test/UList/Test-UList.C b/applications/test/UList/Test-UList.C index 667e624529..cbb35472fc 100644 --- a/applications/test/UList/Test-UList.C +++ b/applications/test/UList/Test-UList.C @@ -115,7 +115,22 @@ int main(int argc, char *argv[]) Info<<"UList: "; print(ulist); } + { + Foam::identityOp ident; + + Info<< nl << "identityOp as functor or array/map" << nl; + + for (const label val : labelRange(5)) + { + Info<< "value:" << val + << " () = " << ident(val) + << " [] = " << ident[val] << nl; + } + } + + Info<< "\nEnd\n" << nl; return 0; } + // ************************************************************************* // diff --git a/applications/test/pTraits/Test-pTraits.C b/applications/test/pTraits/Test-pTraits.C index 6b4c4a5a54..78494ab6a9 100644 --- a/applications/test/pTraits/Test-pTraits.C +++ b/applications/test/pTraits/Test-pTraits.C @@ -34,6 +34,7 @@ Description #include "boolVector.H" // A FixedList pretending to be a vector #include "vector.H" #include "tensor.H" +#include "complex.H" #include "uLabel.H" #include "Switch.H" @@ -110,6 +111,7 @@ void printTraits() << " vector-space=" << Switch::name(is_vectorspace::value) << " is_label=" << Switch::name(is_contiguous_label::value) << " is_scalar=" << Switch::name(is_contiguous_scalar::value) + << " cmptType=" << typeid(typename pTraits_cmptType::type).name() << endl; } @@ -120,6 +122,12 @@ void printTraits(const pTraits& p) Info<< p.typeName << " == " << p << endl; } +template +void printDecltype() +{ + Info<< "cmptType : " << typeid(T).name() << nl; +} + #pragma GCC diagnostic warning "-Wmaybe-uninitialized" #pragma GCC diagnostic warning "-Wuninitialized" @@ -129,12 +137,16 @@ int main() printTraits(); printTraits