mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add ListOps::equal() function
- tests for list equality with different but compatible data types. Eg, when comparing lists of int32 and int64 values. STYLE: pass UList instead of List references into ListOps functors
This commit is contained in:
@ -51,6 +51,7 @@ See also
|
||||
#include "IndirectList.H"
|
||||
#include "SubList.H"
|
||||
#include "SliceList.H"
|
||||
#include "SubField.H"
|
||||
#include "ListPolicy.H"
|
||||
|
||||
#include <list>
|
||||
@ -281,6 +282,33 @@ int main(int argc, char *argv[])
|
||||
};
|
||||
Info<< "list4: " << list4 << endl;
|
||||
|
||||
{
|
||||
List<scalar> list4Mag = ListOps::create<scalar>
|
||||
(
|
||||
list4,
|
||||
[](const auto& a){ return a.mag(); }
|
||||
);
|
||||
|
||||
const auto equalMag = [](const auto& a, const auto& b)
|
||||
{
|
||||
return (Foam::mag(a) == Foam::mag(b));
|
||||
};
|
||||
|
||||
Info<< "list4 (mag): " << list4Mag << endl;
|
||||
|
||||
bool same = ListOps::equal(list4, list4Mag, equalMag);
|
||||
Info<< "mag(list4) == list4(mag): " << same << nl;
|
||||
|
||||
SubField<scalar>(list4Mag) *= -1;
|
||||
same = ListOps::equal(list4, list4Mag, equalMag);
|
||||
Info<< "mag(list4) == list4(mag): " << same << nl;
|
||||
|
||||
SubField<scalar>(list4Mag) *= 1.1;
|
||||
same = ListOps::equal(list4, list4Mag, equalMag);
|
||||
Info<< "mag(list4) == list4(mag): " << same << nl;
|
||||
}
|
||||
|
||||
|
||||
List<vector> list5
|
||||
{
|
||||
{5, 3, 1},
|
||||
|
||||
Reference in New Issue
Block a user