Bug 4804 – Sequence example alternative

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-09-03T10:05:00Z
Last change time
2011-03-09T11:48:37Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2010-09-03T10:05:39Z
From: http://www.digitalmars.com/d/2.0/phobos/std_range.html#Sequence // a[0] = 1, a[1] = 2, a[n] = a[0] + n * a[1] auto odds = sequence!("a[0] + n * a[1]")(1, 2); This has been reported in bug 3181 for not compiling. But there's a workaround. If I use the "a.field[]" syntax instead of "a[0]", then the original example in the documentation works: auto odds = sequence!("a.field[0] + n * a.field[1]")(1, 2); There are also some weird bugs in the sequence unittest in range.d. Apparently you can't call both Sequence and sequence in the same code. That code is commented out with "@@BUG", but there's no bug number so I guess it wasn't reported yet, or maybe someone is already working on it.. But anyway, here's the gist of it: import std.range; import std.typecons; void main() { alias Sequence!("a.field[0] + n * a.field[1]", Tuple!(int, int)) Gen; auto y = sequence!("a.field[0] + n * a.field[1]")(0, 4); } C:\DMD\dmd2\windows\bin\..\..\src\phobos\std\range.d(2459): Error : this for _cache needs to be type Sequence not type Sequence!("a .field[0] + n * a.field[1]",Tuple!(int,int)) If you uncomment either line, the example compiles.
Comment #1 by andrej.mitrovich — 2011-03-09T11:48:37Z
Both of these have been fixed in a recent release.