Why is Exceptions c'tor this(immutable(char[]) instead of const(char[]) ?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Aug 26 14:23:01 PDT 2010


On 8/26/10 13:16 PDT, Steven Schveighoffer wrote:
> On Thu, 26 Aug 2010 16:05:00 -0400, Mathias Laurenz Baumann
> <anonym001 at supradigital.org> wrote:
>
>> Well, topic says it all. Why is the string parameter for the Exception
>> class in object.di an immutable(char[])?
>>
>> A const(char[]) works for both, immutable(char[]) types and char[]
>> types. why this limitation?
>
> Normally, I'd agree with you, but if the exception gets a
> immutable(char)[], it can store it without duplication, and without
> worry it will change it.
>
> If you passed in a const, then you'd *have* to duplicate it.
>
> If you have a char[] or a const(char)[] that you want to pass in, call
> idup on it.

Better yet: to!string(whatever). Leaves actual immutable stuff 
non-duplicated/

Andrei


More information about the Digitalmars-d mailing list