May 13, 2013 Re: how to instantiate explicitly template parameters in struct A(T1){this(T2)(){...}} | ||||
---|---|---|---|---|
| ||||
On Monday, May 13, 2013 13:27:44 Timothee Cour 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.
I don't believe that you can _ever_ give explicit template arguments to a constructor whether the type is templated or not. Note that this code doesn't compile:
struct S
{
this(T)(T val)
{
}
}
void main()
{
auto s = S!float(5);
}
and gives this error:
q.d(10): Error: template instance S!(float) S is not a template declaration, it
is a struct
q.d(10): Error: template instance S!(float) S is not a template declaration, it
is a struct
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation