Strange rbtree behaviour

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 7 07:55:04 PDT 2016


On Thursday, July 07, 2016 05:13:56 Ali Çehreli via Digitalmars-d-learn wrote:
> On 07/07/2016 02:57 AM, Jonathan M Davis via Digitalmars-d-learn wrote:
>  > then you should probably use a factory function. e.g.
>
> And name that function "opCall" and you have a non-constructor that
> supports the default-constructor syntax. :p
>
>      static B opCall()
>      {
>          // ...
>      }
>
>      auto b = B();

That only works as long as there are no constructors. As soon as you have a
constructor, a struct can't have a static opCall with no parameters. So,
while it might be visually appealing, I'm not sure that it's actually a good
idea to do it. Even if you didn't need a constructor now, so it worked, if
you needed to add one later, you couldn't without breaking code. So, it's
probably better to use an explicit factory function rather than a static
opCall.

- Jonathan M Davis




More information about the Digitalmars-d-learn mailing list