digitalmars.D - Typeinfo
- Andrei Alexandrescu (8/8) Apr 02 2015 Hey folks, is there any way to figure out whether a type is immutable or...
- Adam D. Ruppe (12/14) Apr 02 2015 Yes: if it is an instance of TypeInfo_Invariant or
- Rikki Cattermole (3/11) Apr 02 2015 Small question, how exactly are you getting the TypeInfo without knowing...
- Andrei Alexandrescu (2/4) Apr 02 2015 I just use it at construction, when the type is known. -- Andrei
- Rikki Cattermole (16/20) Apr 02 2015 Ugh:
- Andrei Alexandrescu (2/23) Apr 02 2015 Loosely related: https://issues.dlang.org/show_bug.cgi?id=14401 -- Andre...
- Steven Schveighoffer (6/12) Apr 03 2015 I use this technique in lifetime.d:
- Andrei Alexandrescu (3/15) Apr 03 2015 Thanks Adam and Steve. Guess I should have asked this in the learn forum...
Hey folks, is there any way to figure out whether a type is immutable or shared given its typeinfo? I see there's only the flags() method that doesn't tell that. I'm thinking we'd do good to extend that. This is needed for allocators. I'm thinking an allocator might be interested at creation time to use different allocation strategies for qualified types, especially shared ones. Thanks, Andrei
Apr 02 2015
On Friday, 3 April 2015 at 00:21:47 UTC, Andrei Alexandrescu wrote:Hey folks, is there any way to figure out whether a type is immutable or shared given its typeinfo?Yes: if it is an instance of TypeInfo_Invariant or TypeInfo_Shared. void main() { string s; char[] c; assert(cast(TypeInfo_Invariant) typeid(s).next !is null); assert(cast(TypeInfo_Invariant) typeid(c).next is null); } The next is there because the array itself isn't immutable, so we look at the type inside.
Apr 02 2015
On 3/04/2015 1:21 p.m., Andrei Alexandrescu wrote:Hey folks, is there any way to figure out whether a type is immutable or shared given its typeinfo? I see there's only the flags() method that doesn't tell that. I'm thinking we'd do good to extend that. This is needed for allocators. I'm thinking an allocator might be interested at creation time to use different allocation strategies for qualified types, especially shared ones. Thanks, AndreiSmall question, how exactly are you getting the TypeInfo without knowing its exact type at CT?
Apr 02 2015
On 4/2/15 5:52 PM, Rikki Cattermole wrote:Small question, how exactly are you getting the TypeInfo without knowing its exact type at CT?I just use it at construction, when the type is known. -- Andrei
Apr 02 2015
On 3/04/2015 5:34 p.m., Andrei Alexandrescu wrote:On 4/2/15 5:52 PM, Rikki Cattermole wrote:Ugh: void main() { alias TYPE = immutable(ubyte[]); auto TYPEV2 = cast(immutable)TYPE.init; alias TYPE2 = typeof(TYPEV2); pragma(msg, TYPE); pragma(msg, TYPE2); static if (is(TYPE2 == TYPE)) { pragma(msg, "immutable"); } else { pragma(msg, "mutable"); } } cast() should be clearing away the immutable, but for some reason it is not working the way I would expect.Small question, how exactly are you getting the TypeInfo without knowing its exact type at CT?I just use it at construction, when the type is known. -- Andrei
Apr 02 2015
On 4/2/15 9:58 PM, Rikki Cattermole wrote:On 3/04/2015 5:34 p.m., Andrei Alexandrescu wrote:Loosely related: https://issues.dlang.org/show_bug.cgi?id=14401 -- AndreiOn 4/2/15 5:52 PM, Rikki Cattermole wrote:Ugh: void main() { alias TYPE = immutable(ubyte[]); auto TYPEV2 = cast(immutable)TYPE.init; alias TYPE2 = typeof(TYPEV2); pragma(msg, TYPE); pragma(msg, TYPE2); static if (is(TYPE2 == TYPE)) { pragma(msg, "immutable"); } else { pragma(msg, "mutable"); } } cast() should be clearing away the immutable, but for some reason it is not working the way I would expect.Small question, how exactly are you getting the TypeInfo without knowing its exact type at CT?I just use it at construction, when the type is known. -- Andrei
Apr 02 2015
On 4/2/15 8:21 PM, Andrei Alexandrescu wrote:Hey folks, is there any way to figure out whether a type is immutable or shared given its typeinfo? I see there's only the flags() method that doesn't tell that. I'm thinking we'd do good to extend that. This is needed for allocators. I'm thinking an allocator might be interested at creation time to use different allocation strategies for qualified types, especially shared ones.I use this technique in lifetime.d: // typeof(ti) is TypeInfo auto isshared = typeid(ti) is typeid(TypeInfo_Shared); https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L640 -Steve
Apr 03 2015
On 4/3/15 4:53 AM, Steven Schveighoffer wrote:On 4/2/15 8:21 PM, Andrei Alexandrescu wrote:Thanks Adam and Steve. Guess I should have asked this in the learn forum :o). -- AndreiHey folks, is there any way to figure out whether a type is immutable or shared given its typeinfo? I see there's only the flags() method that doesn't tell that. I'm thinking we'd do good to extend that. This is needed for allocators. I'm thinking an allocator might be interested at creation time to use different allocation strategies for qualified types, especially shared ones.I use this technique in lifetime.d: // typeof(ti) is TypeInfo auto isshared = typeid(ti) is typeid(TypeInfo_Shared); https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L640
Apr 03 2015
On Friday, 3 April 2015 at 17:51:33 UTC, Andrei Alexandrescu wrote:Thanks Adam and Steve. Guess I should have asked this in the learn forum :o). -- AndreiYeah, I have totally expected some revolutionary proposal for RTTI improvement in D from you when opening the topic :( You have broken my heart!
Apr 03 2015
On Friday, 3 April 2015 at 17:58:27 UTC, Dicebot wrote:On Friday, 3 April 2015 at 17:51:33 UTC, Andrei Alexandrescu wrote:+1Thanks Adam and Steve. Guess I should have asked this in the learn forum :o). -- AndreiYeah, I have totally expected some revolutionary proposal for RTTI improvement in D from you when opening the topic :( You have broken my heart!
Apr 03 2015