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

Mathias Laurenz Baumann anonym001 at supradigital.org
Thu Aug 26 13:24:57 PDT 2010


Okay, sounds reasonable.

What about many of the phobos functions, like for example from std.regex:

int find(string s, RegExp pattern);

I mean, that function won't store anything, right?

--Marenz


Am 26.08.2010, 22:16 Uhr, schrieb Steven Schveighoffer  
<schveiguy at yahoo.com>:

> 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.
>
> -Steve


More information about the Digitalmars-d mailing list