Thread overview
How to tell how an object/class is declared
Nov 06, 2014
Meta
Nov 06, 2014
Meta
Nov 06, 2014
Adam D. Ruppe
November 06, 2014
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
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
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 }