digitalmars.D.learn - How to tell how an object/class is declared
- Meta (28/28) Nov 06 2014 Say I have the following struct and object definitions:
- Meta (5/5) Nov 06 2014 One other thing. I know about `template this`, but I'm not sure
- Adam D. Ruppe (4/7) Nov 06 2014 You can't do that, but you can overload on const
Say I have the following struct and object definitions: struct Test1(T) { static if (???) { void doSomething() { writeln(typeof(this).stringof); } } T t; } class Test2(T) { static if (???) { void doSomething() { writeln(typeof(this).stringof); } } T t; } const(Test1!int) t1i; shared(Test2!int) t2s; How can I tell at the points marked in the above code if the class or struct instance was declared as const, shared, etc.? Is this possible?
Nov 06 2014
One other thing. I know about `template this`, but I'm not sure if that's a tenable solution or not in my case. In addition to templating the struct or class, would I not also have to template the constructor so it could pick up the type of `this` at the declaration site?
Nov 06 2014
On Thursday, 6 November 2014 at 23:43:19 UTC, Meta wrote:How can I tell at the points marked in the above code if the class or struct instance was declared as const, shared, etc.? Is this possible?You can't do that, but you can overload on const void doSomething() const { called on const instance } void doSomething() { called on mutable }
Nov 06 2014