Bug 4803 – std.range.chain with const string arguments

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-09-03T09:53:00Z
Last change time
2012-04-21T15:39:19Z
Assigned to
andrei
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-09-03T09:53:22Z
A problem found by Pelle Mansson: import std.range: chain; void main() { const string s = "hello"; auto r = chain(s, s); } Compiled with dmd 2.048: ...\dmd\src\phobos\std\range.d(1162): Error: can only initialize const member _field_field_0 inside constructor ...\dmd\src\phobos\std\range.d(1162): Error: can only initialize const member _field_field_1 inside constructor I think a chain() has to work with const strings too (the items need to be const if one of the iterables given to chain has const items).
Comment #1 by andrej.mitrovich — 2010-09-03T10:29:52Z
What exactly is the purpose of a constant string type? That type evaluates to const(immutable(char)[]), which wouldn't make much sense to me. Note that this will work: import std.range: chain; void main() { const (char)[] s = "hello"; auto r = chain(s, s); } But I'm not sure if that's what you were after.
Comment #2 by andrej.mitrovich — 2010-09-03T10:35:43Z
(In reply to comment #1) > What exactly is the purpose of a constant string type? > > That type evaluates to const(immutable(char)[]), which wouldn't make much sense > to me. > > Note that this will work: > > import std.range: chain; > void main() { > const (char)[] s = "hello"; > auto r = chain(s, s); > } > > But I'm not sure if that's what you were after. Woops, my bad. A string is still appendable, and a const one would not be. I think I understand now.
Comment #3 by lovelydear — 2012-04-21T15:34:49Z
Compiles on 2.059
Comment #4 by andrej.mitrovich — 2012-04-21T15:39:19Z
(In reply to comment #3) > Compiles on 2.059 Thanks for testing.