digitalmars.D - Why is Exceptions c'tor this(immutable(char[]) instead of
- Mathias Laurenz Baumann (5/5) Aug 26 2010 Well, topic says it all. Why is the string parameter for the Exception
- Steven Schveighoffer (9/13) Aug 26 2010 Normally, I'd agree with you, but if the exception gets a
- Mathias Laurenz Baumann (7/21) Aug 26 2010 Okay, sounds reasonable.
- Steven Schveighoffer (5/9) Aug 26 2010 This is where I normally agree with you ;) From what I understand, ther...
- Andrei Alexandrescu (5/9) Aug 26 2010 Good point. I think Regexp does actually store slices of its input
- Andrei Alexandrescu (4/17) Aug 26 2010 Better yet: to!string(whatever). Leaves actual immutable stuff
- Andrei Alexandrescu (4/9) Aug 26 2010 The string is stored inside the Exception object. If it's immutable then...
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? --Marenz
Aug 26 2010
On Thu, 26 Aug 2010 16:05:00 -0400, Mathias Laurenz Baumann <anonym001 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
Aug 26 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 yahoo.com>:On Thu, 26 Aug 2010 16:05:00 -0400, Mathias Laurenz Baumann <anonym001 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
Aug 26 2010
On Thu, 26 Aug 2010 16:24:57 -0400, Mathias Laurenz Baumann <anonym001 supradigital.org> wrote: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?This is where I normally agree with you ;) From what I understand, there are quite a few phobos modules that need some TLC. -Steve
Aug 26 2010
On 8/26/10 13:24 PDT, Mathias Laurenz Baumann wrote: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?Good point. I think Regexp does actually store slices of its input string, but that artifact is not visible in the interface. I will look into it. Andrei
Aug 26 2010
On 8/26/10 13:16 PDT, Steven Schveighoffer wrote:On Thu, 26 Aug 2010 16:05:00 -0400, Mathias Laurenz Baumann <anonym001 supradigital.org> wrote:Better yet: to!string(whatever). Leaves actual immutable stuff non-duplicated/ AndreiWell, 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.
Aug 26 2010
On 8/26/10 13:05 PDT, Mathias Laurenz Baumann 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? --MarenzThe string is stored inside the Exception object. If it's immutable then there's a guarantee it will last forever. Andrei
Aug 26 2010