Commit graph

21 commits

Author SHA1 Message Date
Kp a56ceca502 Use distinct sentinel type on zip<> 2022-12-31 16:21:47 +00:00
Kp 4071cd0cbf Replace range_owns_iterated_storage with ranges::borrowed_range
The standard type imposes some additional requirements that are not
necessary here, but using this concept allows standard containers to be
classified correctly without specific overrides.
2022-12-31 16:21:47 +00:00
Kp 8decd6ec99 Simplify DXX_ALWAYS_ERROR_FUNCTION
Since this should never be invoked, simplify the definition.  The new
version is slightly less informative in case a logic error causes it to
be called, but is far shorter and easier to understand.
2022-12-10 18:09:54 +00:00
Kp bb0711001f Make xrange_endpoint value mutable
The concept std::ranges::range<T> requires that std::ranges::end(T) be
well-formed.  An input with a `const` qualified member fails this test,
and causes std::ranges::range<T> to reject an otherwise satisfiable
range.
2022-10-09 23:15:20 +00:00
Kp dded433d2b Return sentinel type from xrange::end() 2022-10-09 23:15:20 +00:00
Kp b5775f1680 Use std::ranges::begin/end for partial_range
Remove custom adl_begin and rely on std::ranges.
2022-10-09 23:15:20 +00:00
Kp c1a8a3b8e3 Explicitly default xrange_iterator::operator==
Replace operator!= with an implicitly defaulted definition, which will
use the new explicitly defaulted operator==.
2022-10-09 23:15:19 +00:00
Kp dc674eafe8 Replace various uses of std::enable_if with C++20 requires()
Compiler error messages are generally better when reporting a misuse
that fails a requires() versus reporting a misuse that fails a
std::enable_if.  In some cases, this also makes the code clearer, and
avoids the need for dummy template parameters as a place to invoke
std::enable_if.
2022-07-30 17:42:59 +00:00
Kp 21aae1a352 Tighten symbol visibility for xrange
Switch to using protected inheritance, and expose the two base fields
that are needed outside the class.
2022-03-05 17:23:51 +00:00
Kp dc59b0b2cb Split out xrange init_begin ascending/descending paths
AlumiuN reports that mingw32-w64-gcc-8.1.0 incorrectly reports
`ascending` as unused-but-set.  This is clearly not true.  Reorder the
code to avoid saving `ascending`, and instead use the result of
`detail::get_xrange_ascending` directly.  This also improves the error
message in the DXX_ALWAYS_ERROR_FUNCTION path.

Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/626>
2022-03-05 17:23:51 +00:00
Kp 9e58992296 Flatten constant_xrange hierarchy 2022-02-27 14:23:53 +00:00
Kp 0f53ce0f06 Factor out get_xrange_direction
clang chokes on use of a `constexpr bool` that is initialized separately
from its definition.  gcc allows this.  Move the value computation into
a constexpr helper function, so that the variable can be defined and
initialized in the same statement.
2022-01-09 15:25:42 +00:00
Kp 078a9affa0 Make MAX_SIDES_PER_SEGMENT an iterable range
Iterating over it returns each side number in turn.  This allows
converting many loops of the form:

```
	for (int i = 0; i < MAX_SIDES_PER_SEGMENT; ++i)
```

to the compact form:

```
	for (const auto i : MAX_SIDES_PER_SEGMENT)
```

The compact form brings the usual benefit of range-based for: delegating
iteration to the compiler prevents the loop body from skipping a step,
and makes clear in the code that this is the case.
2022-01-09 15:25:42 +00:00
Kp d748e7bbfc Add support for xrange steps other than +1
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.
2021-08-26 03:13:45 +00:00
Kp 15f9b3d43f Enable use of some STL algorithms on zip_iterator
std::find_if needs common iterator traits.  Add the relevant type
definitions to zip_iterator.

Also add them to d_range, to avoid errors when a range is zipped.
2020-12-27 22:03:09 +00:00
Kp 9081b2f071 Rename xrange_extent to xrange
This is handled separately to split out the churn of the renaming from
the logic changes that made this possible.
2020-07-16 02:31:04 +00:00
Kp 92ec624e47 Replace xrange helper function with class template argument deduction 2020-07-16 02:31:04 +00:00
Kp 250713d932 Use if constexpr to simplify xrange_extent::init_begin
Switch from tag-based overload dispatching to use `if constexpr`.
2020-07-16 02:31:04 +00:00
Kp 40726aa580 Mark xrange as returning unowned storage
It returns integers by value, not by reference.
2020-02-26 05:07:34 +00:00
Kp 5ea591af18 Fix gcc-9 build of d_range.h
gcc-9 rejects `std::enable_if<false,
std::integral_constant<std::integral_constant, 1> 0>::type` before it
notices that the whole expression is eliminated due to SFINAE.  Use
`std::common_type` to coerce the inner integral_constant to an
appropriate integer type, which allows the expression to be well-formed
enough to reach the SFINAE check from enable_if, then be silently
removed from the overload resolution set.
2019-05-06 00:36:16 +00:00
Kp 15ac8a5ac6 Add utility xrange for range-based loops with precomputed bounds
Utility xrange, inspired by the Python2 feature of the same name,
provides an object that returns successive values from [start, end).  It
is useful when the end index is known in advance, and is particularly
helpful when that index is expensive to recompute.
2019-05-04 18:27:36 +00:00