From 83669e284fab7d8cb1280e8d93e8d5934c122b96 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 14 May 2017 14:39:17 +0200 Subject: [PATCH] ENH: improvements to labelRange const_iterator - inherit from std::iterator to obtain the full STL typedefs, meaning that std::distance works and the following is now possible: labelRange range(100, 1500); scalarList list(range.begin(), range.end()); -- Note that this does not work (mismatched data-types): scalarList list = identity(12345); But this does, since the *iter promotes label to scalar: labelList ident = identity(12345); scalarList list(ident.begin(), ident.end()); It is however more than slightly wasteful to create a labelList just for initializing a scalarList. An alternative could be a a labelRange for the same purpose. labelRange ident = labelRange::identity(12345); scalarList list(ident.begin(), ident.end()); Or this scalarList list ( labelRange::null.begin(), labelRange::identity(12345).end() ); --- applications/test/List/Test-List.C | 40 ++++++++++++++++- .../test/labelRanges/Test-labelRanges.C | 2 +- .../primitives/ranges/labelRange/labelRange.C | 2 + .../primitives/ranges/labelRange/labelRange.H | 45 ++++++++++++++----- .../ranges/labelRange/labelRangeI.H | 25 ++++++++--- 5 files changed, 96 insertions(+), 18 deletions(-) diff --git a/applications/test/List/Test-List.C b/applications/test/List/Test-List.C index 9ab2732c2e..d68bc4d7ba 100644 --- a/applications/test/List/Test-List.C +++ b/applications/test/List/Test-List.C @@ -42,6 +42,7 @@ See also #include "vector.H" #include "labelRange.H" +#include "scalarList.H" #include "ListOps.H" #include "SubList.H" @@ -144,6 +145,18 @@ int main(int argc, char *argv[]) labelList longLabelList = identity(15); + // This does not work: + // scalarList slist = identity(15); + // + // More writing, but does work: + scalarList slist + ( + labelRange::null.begin(), + labelRange::identity(15).end() + ); + + Info<<"scalar identity:" << flatOutput(slist) << endl; + Info<< "labels (contiguous=" << contiguous