mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add min/max compare/reduction operators for Tuple2 first()
- min/max ops that only compare the first element
This commit is contained in:
committed by
Andrew Heather
parent
b0c88dff58
commit
e8fa46230a
@ -39,6 +39,7 @@ Description
|
||||
#include "List.H"
|
||||
#include "ListOps.H"
|
||||
#include "ops.H"
|
||||
#include "PstreamCombineReduceOps.H"
|
||||
#include <functional>
|
||||
|
||||
using namespace Foam;
|
||||
@ -121,6 +122,43 @@ int main()
|
||||
|
||||
Info<< "Unsorted tuples:" << nl << list1 << nl;
|
||||
|
||||
// Test minFirst, maxFirst functors
|
||||
{
|
||||
indexedScalar minIndexed(labelMax, Zero);
|
||||
indexedScalar maxIndexed(labelMin, Zero);
|
||||
|
||||
for (const auto& item : list1)
|
||||
{
|
||||
minFirstEqOp<label>()(minIndexed, item);
|
||||
maxFirstEqOp<label>()(maxIndexed, item);
|
||||
}
|
||||
|
||||
Foam::combineReduce(minIndexed, minFirstEqOp<label>());
|
||||
Foam::combineReduce(maxIndexed, maxFirstEqOp<label>());
|
||||
|
||||
Info<< "Min indexed: " << minIndexed << nl
|
||||
<< "Max indexed: " << maxIndexed << nl;
|
||||
}
|
||||
|
||||
// Test minFirst, maxFirst functors
|
||||
{
|
||||
indexedScalar minIndexed(labelMax, Zero);
|
||||
indexedScalar maxIndexed(labelMin, Zero);
|
||||
|
||||
for (const auto& item : list1)
|
||||
{
|
||||
minIndexed = minFirstOp<label>()(minIndexed, item);
|
||||
maxIndexed = maxFirstOp<label>()(maxIndexed, item);
|
||||
}
|
||||
|
||||
Foam::combineReduce(minIndexed, minFirstEqOp<label>());
|
||||
Foam::combineReduce(maxIndexed, maxFirstEqOp<label>());
|
||||
|
||||
Info<< "Min indexed: " << minIndexed << nl
|
||||
<< "Max indexed: " << maxIndexed << nl;
|
||||
}
|
||||
|
||||
|
||||
Foam::sort(list1, std::less<indexedScalar>());
|
||||
|
||||
Info<< "sorted tuples:" << nl << list1 << nl;
|
||||
|
||||
Reference in New Issue
Block a user