Bug 15236 – std.range.chain cannot chain a std.range.repeat string

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2015-10-22T18:15:00Z
Last change time
2015-10-22T20:44:18Z
Assigned to
nobody
Creator
jack
Blocks
13409

Comments

Comment #0 by jack — 2015-10-22T18:15:17Z
This seems to be a problem in the way the template constraint for chain finds the element types for all of the ranges. It thinks that the element type for Take!(Repeat!string) is string, so it comes up with CommonType!(string, dchar) which is void. ----------------------- import std.range; void main() { string a = "abc"; string b = "xyz"; chain(repeat(a, 2), b); } test.d(8): Error: template std.range.chain cannot deduce function from argument types !()(Take!(Repeat!string), string)
Comment #1 by ag0aep6g — 2015-10-22T19:33:47Z
(In reply to Jack Stouffer from comment #0) > It thinks that the element > type for Take!(Repeat!string) is string, so it comes up with > CommonType!(string, dchar) which is void. But the ElementType really is string. `repeat` "repeats one value". So if you pass a string, the elements of the range are that one string again and again. Then you try to chain a range of dchars (a string) to that range of strings, which fails as expected. You have to either join the range of strings from `repeat` into a range of dchars (std.algorithm.joiner), or turn the single string you want to chain on into a range (std.range.only).