Thread overview
idea for static class construction order
Jan 22, 2005
Matthew
Jan 24, 2005
Matthew
Jan 24, 2005
Russ Lewis
December 30, 2004
Was just thinking about it.  Why not just add it into the module's static
this()?

class A
{
public:
    static this() { ... }
}

class B
{
public:
    static this() { ... }
}

static this()
{
    static B.this();
    static A.this();
}

Are there any parsing / lex problems with this construct?  I'm just wondering, as the order of static constructors has been undefined for a while, and it'd kind of be nice to see it implemented.  :)


January 22, 2005
I kind of like this idea. Maybe the compiler could use the explicit order, if provided, otherwise it would determine as it currently does.

"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:cqvr91$2a4c$1@digitaldaemon.com...
> Was just thinking about it.  Why not just add it into the module's static
> this()?
>
> class A
> {
> public:
>    static this() { ... }
> }
>
> class B
> {
> public:
>    static this() { ... }
> }
>
> static this()
> {
>    static B.this();
>    static A.this();
> }
>
> Are there any parsing / lex problems with this construct?  I'm just wondering, as the order of static constructors has been undefined for a while, and it'd kind of be nice to see it implemented.  :)
>
> 


January 24, 2005
Wow, nice to see someone finally saw it :)


January 24, 2005
I'm on a gradual trawl through all the entries since the 3rd August. ;)

"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:ct21v3$2pt2$1@digitaldaemon.com...
> Wow, nice to see someone finally saw it :)
>
> 


January 24, 2005
Matthew wrote:
> I kind of like this idea. Maybe the compiler could use the explicit order, if provided, otherwise it would determine as it currently does.

I agree that it would be a cool feature (though maybe I'm missing some unintended side effect).  You can, of course, do it already; rather than declaring static constructors for the classes, simply define static functions which are called by the module constructor.

I don't know how the ordering of module constructor and any (remaining) static class constructors interact, however.  I guess it would be a good idea to explicitly state the order for all classes in a module where you care.