mirror of
https://github.com/dlang/phobos.git
synced 2025-05-02 08:00:48 +03:00
Issue 10130 - Fix compile error when calling map on iota with const step.
Also fixed the similar issue for iota with const begin/end/step floats.
This commit is contained in:
parent
23d15e2fcb
commit
ebe93db8c1
2 changed files with 18 additions and 3 deletions
|
@ -599,6 +599,20 @@ unittest
|
||||||
assert(equal(m, [1L, 4L, 9L]));
|
assert(equal(m, [1L, 4L, 9L]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
// Issue #10130 - map of iota with const step.
|
||||||
|
const step = 2;
|
||||||
|
static assert(__traits(compiles, mixin("map!(i => i)(iota(0, 10, step))")));
|
||||||
|
|
||||||
|
// Need these to all by const to repro the float case, due to the
|
||||||
|
// CommonType template used in the float specialization of iota.
|
||||||
|
const floatBegin = 0.0;
|
||||||
|
const floatEnd = 1.0;
|
||||||
|
const floatStep = 0.02;
|
||||||
|
static assert(__traits(compiles, mixin("map!(i => i)(iota(floatBegin, floatEnd, floatStep))")));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
$(D auto reduce(Args...)(Args args)
|
$(D auto reduce(Args...)(Args args)
|
||||||
if (Args.length > 0 && Args.length <= 2 && isIterable!(Args[$ - 1]));)
|
if (Args.length > 0 && Args.length <= 2 && isIterable!(Args[$ - 1]));)
|
||||||
|
|
|
@ -5078,14 +5078,15 @@ if ((isIntegral!(CommonType!(B, E)) || isPointer!(CommonType!(B, E)))
|
||||||
&& isIntegral!S)
|
&& isIntegral!S)
|
||||||
{
|
{
|
||||||
alias CommonType!(Unqual!B, Unqual!E) Value;
|
alias CommonType!(Unqual!B, Unqual!E) Value;
|
||||||
|
alias Unqual!S StepType;
|
||||||
alias typeof(unsigned((end - begin) / step)) IndexType;
|
alias typeof(unsigned((end - begin) / step)) IndexType;
|
||||||
|
|
||||||
static struct Result
|
static struct Result
|
||||||
{
|
{
|
||||||
private Value current, pastLast;
|
private Value current, pastLast;
|
||||||
private S step;
|
private StepType step;
|
||||||
|
|
||||||
this(Value current, Value pastLast, S step)
|
this(Value current, Value pastLast, StepType step)
|
||||||
{
|
{
|
||||||
if ((current < pastLast && step >= 0) ||
|
if ((current < pastLast && step >= 0) ||
|
||||||
(current > pastLast && step <= 0))
|
(current > pastLast && step <= 0))
|
||||||
|
@ -5236,7 +5237,7 @@ auto iota(E)(E end)
|
||||||
auto iota(B, E, S)(B begin, E end, S step)
|
auto iota(B, E, S)(B begin, E end, S step)
|
||||||
if (isFloatingPoint!(CommonType!(B, E, S)))
|
if (isFloatingPoint!(CommonType!(B, E, S)))
|
||||||
{
|
{
|
||||||
alias CommonType!(B, E, S) Value;
|
alias CommonType!(Unqual!B, Unqual!E, Unqual!S) Value;
|
||||||
static struct Result
|
static struct Result
|
||||||
{
|
{
|
||||||
private Value start, step;
|
private Value start, step;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue