mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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<pTraits_cmptType<Type>::type*>(buf.data()),
(buf.size()/pTraits_nComponents<Type>::value)
);
ENH: extend Foam::identityOp so support array indexing (pass-through)
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -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<T>::value)
|
||||
<< " is_label=" << Switch::name(is_contiguous_label<T>::value)
|
||||
<< " is_scalar=" << Switch::name(is_contiguous_scalar<T>::value)
|
||||
<< " cmptType=" << typeid(typename pTraits_cmptType<T>::type).name()
|
||||
<< endl;
|
||||
}
|
||||
|
||||
@ -120,6 +122,12 @@ void printTraits(const pTraits<T>& p)
|
||||
Info<< p.typeName << " == " << p << endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
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<bool>();
|
||||
printTraits<label>();
|
||||
printTraits<scalar>();
|
||||
printTraits<vector>();
|
||||
printTraits<complex>(); // Uses specialized pTraits_...
|
||||
printTraits<floatVector>();
|
||||
printTraits<doubleVector>();
|
||||
printTraits<tensor>();
|
||||
printTraits<boolVector>();
|
||||
printTraits<boolVector>(); // Uses specialized pTraits_...
|
||||
printTraits<word>();
|
||||
printTraits<std::string>();
|
||||
|
||||
Info<< nl;
|
||||
|
||||
{
|
||||
pTraits<bool> b(true);
|
||||
printTraits(b);
|
||||
@ -147,6 +159,8 @@ int main()
|
||||
|
||||
printTraits(pTraits<scalar>(3.14159));
|
||||
|
||||
Info<< nl;
|
||||
|
||||
label abc;
|
||||
Info<< "uninitialized primitive:"<< abc << endl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user