Bug 14910 – Take!R does not offer length for char[]

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-12T08:39:00Z
Last change time
2015-08-12T09:17:50Z
Assigned to
nobody
Creator
schneider.cedric

Comments

Comment #0 by schneider.cedric — 2015-08-12T08:39:57Z
unittest { char[] chars = ['h', 'e', 'l', 'l', 'o']; assert(chars.take(2).length == 2); } This unittest fails to compile, complaining that Take!char[] does not have a length, despite Take!R claiming to offer a length property if the input range does.
Comment #1 by petar.p.kirov — 2015-08-12T09:14:46Z
See http://dlang.org/phobos/std_range_primitives#hasLength. Take provides a length property only if for its argument hasLength return true. If you know that you're only dealing with ASCII, you can cast the string to ubyte[], see: http://dpaste.dzfl.pl/fe93a68a3945.