ENH: add min/max compare/reduction operators for Tuple2 first()

- min/max ops that only compare the first element
This commit is contained in:
Mark Olesen
2019-11-05 13:08:21 +01:00
committed by Andrew Heather
parent b0c88dff58
commit e8fa46230a
2 changed files with 120 additions and 2 deletions

View File

@ -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;