On Thu, 25 Dec 2014 03:07:55 +0000
aldanor via Digitalmars-d-learn <[email protected]>
wrote:

> On Thursday, 25 December 2014 at 02:28:47 UTC, ketmar via 
> Digitalmars-d-learn wrote:
> > happy hacking! ;-)
> 
> Thanks once again! I think this mostly solves it. Would it be 
> possible to somehow do the same trick with this()? (I guess due 
> to having to write Type!() when default template arguments are 
> omitted?)

unfortunately, you can have templated constructors, but you can't
instantiate them manually. ;-) i.e.

  class A {
    this(T) () { ... }
  }

can be compiled, but you can't call that constructor. there is simply
no syntax for it. you still can do templated constructors with type
deducing though:

  class A {
    this(T) (T arg) { ... }
  }

  auto n = new A(42); // this will call this!int(42)
  auto n = new A("alice"); // this will call this!string("alice")
  auto n = new A(true); // this will call this!bool(true)

but you can't write:

  auto n = new A!bool(false); // will not compile

the only thing you can do is make constructors private and using
fabric. alas.

Attachment: signature.asc
Description: PGP signature

Reply via email to