how to instantiate explicitly template parameters in struct A(T1){this(T2)(){...}}
Timothee Cour
thelastmammoth at gmail.com
Mon May 13 16:04:39 PDT 2013
Thanks!
should that be considered as a limitation, and therefore be fixed?
(for example by documenting the __ctor syntax)?
The static make trick is boilerplate and shouldn't be considered the best way.
On Mon, May 13, 2013 at 3:06 PM, Steven Schveighoffer
<schveiguy at yahoo.com> wrote:
> On Mon, 13 May 2013 16:27:44 -0400, Timothee Cour <thelastmammoth at gmail.com>
> wrote:
>
>> While writing DIP40, I came upon the following question:
>> how to instantiate explicitly template parameters for both the
>> class/struct AND the constructor?
>> for example: struct A(T1){this(T2)(){...}} ? (T2 could be used
>> somehow inside the ctor body for example)
>> // auto a=A!double!int(); // CT error
>> The example is a bit contrived but there could be less contrived ones
>> where both A and ctor need explicit instantiations.
>
>
> Since you can't call the ctor directly [1], this isn't possible in any case,
> even without a templated struct.
>
> What you CAN do is specify a constructing function:
>
> struct A(T1) {
> static A make(T2)(){...}
> }
>
> auto a = A!double.make!int();
>
> -Steve
>
> ==================
> [1] This does work, but is not documented/official AFAIK:
>
> struct S
> {
> this(T)(int i) {}
> }
> void main()
> {
> S s;
> s.__ctor!double(1);
> }
More information about the Digitalmars-d-learn
mailing list