mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add iterators to VectorSpace (#1265)
- this adds support for various STL operations including
* sorting, filling, find min/max element etc.
* for-range iteration
STYLE: use constexpr for VectorSpace rank
This commit is contained in:
committed by
Andrew Heather
parent
f3670521cd
commit
1c4e32fb6a
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -31,6 +31,7 @@ Description
|
||||
|
||||
#include "vector.H"
|
||||
#include "IOstreams.H"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -74,6 +75,18 @@ void doTest(vector& vec1, vector& vec2)
|
||||
}
|
||||
|
||||
|
||||
template<class VecSpace>
|
||||
void testIterator(const VecSpace& vs)
|
||||
{
|
||||
Info<< "size: " << vs.size() << " for:";
|
||||
for (const auto& val : vs)
|
||||
{
|
||||
Info<< " " << val;
|
||||
}
|
||||
Info<< nl;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
@ -89,8 +102,21 @@ int main(int argc, char *argv[])
|
||||
vector vec2(0.5, 0.51, -0.5);
|
||||
|
||||
doTest(vec1, vec2);
|
||||
|
||||
testIterator(vec1);
|
||||
testIterator(vec2);
|
||||
|
||||
// Use STL algorithm(s)
|
||||
|
||||
std::sort(vec2.begin(), vec2.end());
|
||||
Info<< "sorted: " << vec2 << nl;
|
||||
|
||||
std::random_shuffle(vec2.begin(), vec2.end());
|
||||
Info<< "shuffled: " << vec2 << nl;
|
||||
}
|
||||
|
||||
Info<< "\nEnd\n" << nl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user