Thread overview | |||||
---|---|---|---|---|---|
|
November 06, 2014 How to tell how an object/class is declared | ||||
---|---|---|---|---|
| ||||
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? |
November 06, 2014 Re: How to tell how an object/class is declared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | 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? |
November 06, 2014 Re: How to tell how an object/class is declared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | 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 }
|
Copyright © 1999-2021 by the D Language Foundation