mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: consistent reverse iterator definitions for UList and FixedList
- consistent with C++ STL conventions, the reverse iterators should use operator++ to transit the list from rbegin() to rend(). The previous implementation used raw pointers, which meant that they had the opposite behaviour: operator-- to transit from rbegin() to rend(). The updated version only has operator++ defined, thus the compiler should catch any possible instances where people were using the old (incorrect) versions. - updated forAllReverseIters() and forAllConstReverseIters() macros to be consistent with new implementation and with C++ STL conventions.
This commit is contained in:
@ -38,6 +38,7 @@ See also
|
||||
#include "List.H"
|
||||
#include "IPstream.H"
|
||||
#include "OPstream.H"
|
||||
#include <numeric>
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -48,6 +49,63 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
argList args(argc, argv);
|
||||
|
||||
if (false)
|
||||
{
|
||||
FixedList<string, 1> ident;
|
||||
|
||||
auto iter = ident.begin();
|
||||
|
||||
Info << iter->size() << endl;
|
||||
|
||||
auto riter = ident.rbegin();
|
||||
Info << riter->size() << endl;
|
||||
|
||||
auto iter2 = ident.rbegin();
|
||||
|
||||
iter2 = iter;
|
||||
}
|
||||
|
||||
{
|
||||
FixedList<label, 15> ident;
|
||||
std::iota(ident.begin(), ident.end(), 0);
|
||||
|
||||
// auto iter = ident.begin();
|
||||
//
|
||||
// iter += 5;
|
||||
// Info << *iter << "< " << endl;
|
||||
// iter -= 2;
|
||||
// Info << *iter << "< " << endl;
|
||||
|
||||
// Don't yet bother with making reverse iterators random access
|
||||
// auto riter = ident.crbegin();
|
||||
|
||||
// riter += 5;
|
||||
// Info << *riter << "< " << endl;
|
||||
// riter += 2;
|
||||
// Info << *riter << "< " << endl;
|
||||
|
||||
Info<<"Ident:";
|
||||
forAllConstIters(ident, iter)
|
||||
{
|
||||
Info<<" " << *iter;
|
||||
}
|
||||
Info<< nl;
|
||||
|
||||
Info<<"reverse:";
|
||||
forAllReverseIters(ident, iter)
|
||||
{
|
||||
Info<<" " << *iter;
|
||||
}
|
||||
Info<< nl;
|
||||
|
||||
Info<<"const reverse:";
|
||||
forAllConstReverseIters(ident, iter)
|
||||
{
|
||||
Info<<" " << *iter;
|
||||
}
|
||||
Info<< nl;
|
||||
}
|
||||
|
||||
{
|
||||
FixedList<label, 4> list1{1, 2, 3, 4};
|
||||
|
||||
|
||||
@ -47,6 +47,7 @@ See also
|
||||
#include "SubList.H"
|
||||
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -79,6 +80,33 @@ int main(int argc, char *argv[])
|
||||
|
||||
#include "setRootCase.H"
|
||||
|
||||
{
|
||||
List<label> ident(15);
|
||||
std::iota(ident.begin(), ident.end(), 0);
|
||||
|
||||
Info<<"Ident:";
|
||||
forAllConstIters(ident, iter)
|
||||
{
|
||||
Info<<" " << *iter;
|
||||
}
|
||||
Info<< nl;
|
||||
|
||||
Info<<"reverse:";
|
||||
forAllReverseIters(ident, iter)
|
||||
{
|
||||
Info<<" " << *iter;
|
||||
}
|
||||
Info<< nl;
|
||||
|
||||
Info<<"const reverse:";
|
||||
forAllConstReverseIters(ident, iter)
|
||||
{
|
||||
Info<<" " << *iter;
|
||||
}
|
||||
Info<< nl;
|
||||
}
|
||||
|
||||
|
||||
if (false)
|
||||
{
|
||||
labelList intlist(IStringStream("(0 1 2)")());
|
||||
@ -109,15 +137,15 @@ int main(int argc, char *argv[])
|
||||
forAllConstIters(list2, iter) { Info<< " " << *iter; }
|
||||
Info<< endl;
|
||||
|
||||
Info<< "forAllReverseConstIters(list2): ";
|
||||
forAllReverseConstIters(list2, iter) { Info<< " " << *iter; }
|
||||
Info<< "forAllConstReverseIters(list2): ";
|
||||
forAllConstReverseIters(list2, iter) { Info<< " " << *iter; }
|
||||
Info<< endl;
|
||||
|
||||
Info<< "forAllConstIters(list2): ";
|
||||
forAllIters(list2, iter) { *iter *= 2; Info<< " " << *iter; }
|
||||
Info<< endl;
|
||||
|
||||
Info<< "forAllReverseConstIters(list2): ";
|
||||
Info<< "forAllReverseIters(list2): ";
|
||||
forAllReverseIters(list2, iter) { *iter *= 0.5; Info<< " " << *iter; }
|
||||
Info<< endl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user