mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-12-28 03:37:59 +00:00
ENH: new IntRange class, enhancements to labelRange, sliceRange
- add reverse iterators and replace std::iterator
(deprecated in C++17) with full definitions
- simplify construction of iterators
- construct labelRange from a single single parameter.
This creates a (0,len) range.
- make basic constructors forms constexpr.
Remove unused size checks.
- Derive labelRange from new IntRange template class.
Allows reuse of base functionality with different integral sizes.
Deprecations:
- deprecate labelRange::valid() in favour of using
labelRange::empty() or the bool operator.
For example,
if (range) ... vs older if (range.valid()) ...
DEFEATURE: drop labelRange::null, scalarRange::null static variables
- turned out to be not particularly useful.
Can simply use constexpr contructor forms
DEFEATURE: drop labelRange::identity static method
- simply use the single-parameter constructor
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -35,6 +35,19 @@ Description
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
void printInfo(const labelRange& range)
|
||||
{
|
||||
Info<< "first " << range.first() << nl
|
||||
<< "last " << range.last() << nl
|
||||
<< "min " << range.min() << nl
|
||||
<< "max " << range.max() << nl
|
||||
<< "after " << range.after() << nl
|
||||
<< "begin end " << *range.cbegin() << ' ' << *range.cend() << nl;
|
||||
|
||||
// Info<< "rbegin rend " << *range.rbegin() << ' ' << *range.rend() << nl;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
@ -61,9 +74,9 @@ int main(int argc, char *argv[])
|
||||
Info<<"test sorting" << endl;
|
||||
DynamicList<labelRange> list1(10);
|
||||
list1.append(labelRange(25, 8));
|
||||
list1.append(labelRange::identity(8));
|
||||
list1.append(labelRange(8));
|
||||
list1.append(labelRange(15, 5));
|
||||
list1.append(labelRange(50, -10));
|
||||
list1.append(labelRange(50, -10, true));
|
||||
|
||||
sort(list1);
|
||||
Info<<"sorted" << list1 << endl;
|
||||
@ -149,19 +162,13 @@ int main(int argc, char *argv[])
|
||||
range.reset(5, 5);
|
||||
Info<< nl << "Tests on " << range << nl;
|
||||
|
||||
Info<< "first " << range.first() << nl
|
||||
<< "last " << range.last() << nl
|
||||
<< "min " << range.min() << nl
|
||||
<< "max " << range.max() << nl
|
||||
<< "after " << range.after() << nl
|
||||
<< "*begin " << *range.begin() << nl
|
||||
<< "*end " << *range.end() << nl;
|
||||
printInfo(range);
|
||||
|
||||
range += 3;
|
||||
Info<< "increase size " << range << nl;
|
||||
|
||||
range -= 3; // Probably not a great idea
|
||||
Info<< "decrese size " << range << nl;
|
||||
Info<< "decrease size " << range << nl;
|
||||
|
||||
auto iter = range.begin();
|
||||
|
||||
@ -172,6 +179,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
iter += 3;
|
||||
Info<< "iter: " << *iter << nl;
|
||||
|
||||
Info<< nl << "reversed:" << nl;
|
||||
forAllConstReverseIters(range, iter)
|
||||
{
|
||||
Info<< ' ' << *iter;
|
||||
}
|
||||
Info<< nl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user