Skip to content

Commit

Permalink
Fix Issue 18092 - Can't combine take and takeExactly
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Dec 18, 2017
1 parent 2ba1aae commit 058fdd8
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions std/range/package.d
Expand Up @@ -2393,9 +2393,9 @@ if (isInputRange!R)
@property size_t length() const { return _n; }
alias opDollar = length;

@property Take!R _takeExactly_Result_asTake()
@property auto _takeExactly_Result_asTake()
{
return typeof(return)(_input, _n);
return take(_input, _n);
}

alias _takeExactly_Result_asTake this;
Expand Down Expand Up @@ -2545,6 +2545,22 @@ pure @safe nothrow unittest
assert(equal(t, te));
}

// https://issues.dlang.org/show_bug.cgi?id=18092
// can't combine take and takeExactly
unittest
{
import std.algorithm.comparison : equal;
import std.internal.test.dummyrange : AllDummyRanges;

static foreach (Range; AllDummyRanges)
{{
Range r;
assert(r.take(6).takeExactly(2).equal([1, 2]));
assert(r.takeExactly(6).takeExactly(2).equal([1, 2]));
assert(r.takeExactly(6).take(2).equal([1, 2]));
}}
}

/**
Returns a range with at most one element; for example, $(D
takeOne([42, 43, 44])) returns a range consisting of the integer $(D
Expand Down

0 comments on commit 058fdd8

Please sign in to comment.