- 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()
);
- add increment/decrement, repositioning. Simplify const_iterator.
- this makes is much easier to use labelRange for constructing ranges of
sub-lists. For symmetry with setSize() it has a setStart() instead of
simply assigning to start() directly. This would also provide the
future possibility to imbue the labelRange with a particular policy
(eg, no negative starts, max size etc) and ensure that they are
enforced.
A simple use case:
// initialize each to zero...
List<labelRange> subListRanges = ...;
// scan and categorize
if (condition)
subListRanges[categoryI]++; // increment size for that category
// finally, set the starting points
start = 0;
for (labelRange& range : subListRanges)
{
range.setStart(start);
start += range.size();
}