Bug 5342 – std.array does not respect immutable/const string qualifiers using front/back/etc

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-12-11T01:05:00Z
Last change time
2014-05-11T19:02:15Z
Assigned to
nobody
Creator
sandford

Comments

Comment #0 by sandford — 2010-12-11T01:05:42Z
Essentially, the ElementType! of all strings is a mutable dchar, even if the string itself is immutable. This means that generic code, like isAssignable!(ElementType!string, ElementType!string) passes when it shouldn't. Here is a simple template make fixing this a whole lot less painful. /// Apply the const-ness of Src to type Dst template Requal(Src,Dst) { static if(is( Unqual!Src == Src)) alias Dst Requal; static if(is(const Unqual!Src == Src)) alias const( Dst) Requal; static if(is(immutable Unqual!Src == Src)) alias immutable( Dst) Requal; static if(is(shared Unqual!Src == Src)) alias shared( Dst) Requal; static if(is(shared(const Unqual!Src) == Src)) alias shared(const Dst) Requal; } // example Requal!(typeof(A.init[0]), dchar) front(A)(A a) if (is(typeof(A[0])) && isNarrowString!A)
Comment #1 by peter.alexander.au — 2014-01-25T13:56:06Z
(In reply to comment #0) > Essentially, the ElementType! of all strings is a mutable dchar, even if the > string itself is immutable. This means that generic code, like > isAssignable!(ElementType!string, ElementType!string) passes when it shouldn't. I don't believe this is an issue. The element type of a string *is* dchar, and that type *is* assignable. If you want to know if a range's elements can be assigned to then "hasAssignableElements!R" can be used.
Comment #2 by peter.alexander.au — 2014-02-16T02:34:47Z
Also, what's the point of returning a `const dchar` from `front`? `dchar` has value semantics so the `const` qualifier is meaningless when returned by value. It would matter if it were returned by ref, but it can't because the dchar does not refer to anything -- it is a decoding of the first code units in the string. I propose we close this as WONTFIX.
Comment #3 by peter.alexander.au — 2014-05-11T19:02:15Z
Resolving as WONTFIX. I don't believe this is an issue, and original author is unresponsive.