EASY: factor implementations of range length into a mixin template

This commit is contained in:
Andrei Alexandrescu 2020-09-19 12:38:07 -04:00 committed by The Dlang Bot
parent 311f00f8ac
commit 71ff9d79c5
3 changed files with 30 additions and 92 deletions

View file

@ -371,10 +371,7 @@ private struct _Cache(R, bool bidir)
return source.empty;
}
static if (hasLength!R) auto length() @property
{
return source.length;
}
mixin ImplementLength!source;
E front() @property
{
@ -641,15 +638,7 @@ private struct MapResult(alias fun, Range)
}
}
static if (hasLength!R)
{
@property auto length()
{
return _input.length;
}
alias opDollar = length;
}
mixin ImplementLength!_input;
static if (hasSlicing!R)
{
@ -4373,13 +4362,7 @@ if (fun.length >= 1)
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
mixin ImplementLength!source;
}
return Result(range, args);