When partial_range is used on a container that defines index_type,
define that same index_type on the partial_range. This allows other
callers, such as enumerate(), to maintain the correct index type.
All the affected symbols are templates, so duplicate instantiations will
not cause duplicate definition errors. Removing the anonymous namespace
wrapper will allow equivalent definitions from different source files to
be folded together, reducing the size of the executable.
Push the computation up, so that invocations that differ only in the
length of their expression strings will resolve to the same template.
Rework unchecked_partial_range not to take expression strings if they
will not be used.
- UO -> index_begin_type
- o -> index_begin
- UL -> index_end_type
- l -> index_end
- I -> range_exception
The original names were picked because `l` was the length of the
subrange. Rename these to more closely follow STL's begin/end
nomenclature.
`I` was used variously for an iterator type and for the exception type
thrown on error. Rename the latter to be descriptive.
gr_find_closest_color did not need it. Remove it. For the others,
resetting the count is sufficient. There is no need to reset the
individual elements.
- Add a limiter to let it return early when the result is predictable.
The first caller checks only whether the returned value is above a
threshold. Once the value goes above that threshold, its precise
value will not matter, so stop counting and return early.
- Add comments explaining some of the logic.
Add a helper to deduce the enum type of a value, and use an appropriate
std::underlying_type<T> expression for that enum type. This avoids the
need to repeat the type of the enum at the site of each cast, and moves
the casts into the helper to make the callers easier to read.
In gcc-7, expressions on the false path of `if constexpr` are deleted
before they are considered "used", so a variable that is only used on a
deleted path is reported as an unused variable. Add an alternate path
that casts the variable to void so that it is always used.
Prior to this, an xrange always started at the begin term and
incremented by 1 per step until it reached the end term. There was no
support for a step size other than 1. Add support for custom step size.
It is the caller's responsibility to pick a step size that will
eventually lead to (iter != end) evaluating to false.