Merge remote-tracking branch 'retro-retro'

This commit is contained in:
Eugen Wissner 2018-11-06 16:45:40 +01:00
commit ee8b7ef719
1 changed files with 114 additions and 107 deletions

View File

@ -408,22 +408,8 @@ if (isInputRange!R)
}
}
/**
* Iterates a bidirectional range backwards.
*
* If $(D_PARAM Range) is a random-access range as well, the resulting range
* is a random-access range too.
*
* Params:
* Range = Bidirectional range type.
* range = Bidirectional range.
*
* Returns: Bidirectional range with the elements order reversed.
*/
auto retro(Range)(Range range)
if (isBidirectionalRange!Range)
{
static struct Retro
// Reverse-access-order range returned by `retro`.
private struct Retro(Range)
{
Range source;
@ -526,9 +512,30 @@ if (isBidirectionalRange!Range)
}
}
}
version (unittest) static assert(isBidirectionalRange!Retro);
}
return Retro(range);
/**
* Iterates a bidirectional range backwards.
*
* If $(D_PARAM Range) is a random-access range as well, the resulting range
* is a random-access range too.
*
* Params:
* Range = Bidirectional range type.
* range = Bidirectional range.
*
* Returns: Bidirectional range with the elements order reversed.
*/
auto retro(Range)(return Range range)
if (isBidirectionalRange!Range)
{
// Special case: retro(retro(range)) is range
static if (is(Range == Retro!RRange, RRange))
return range.source;
else
return Retro!Range(range);
}
///