digitalmars.D.bugs - [Issue 5342] New: std.array does not respect immutable/const string qualifiers using front/back/etc
- d-bugmail puremagic.com (37/37) Dec 11 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5342
http://d.puremagic.com/issues/show_bug.cgi?id=5342
Summary: std.array does not respect immutable/const string
qualifiers using front/back/etc
Product: D
Version: D2
Platform: Other
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody puremagic.com
ReportedBy: sandford jhu.edu
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)
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 11 2010








d-bugmail puremagic.com