new DIP40: Template parameter deduction for constructors
Peter Alexander
peter.alexander.au at gmail.com
Mon May 13 00:49:48 PDT 2013
On Monday, 13 May 2013 at 02:39:22 UTC, timotheecour wrote:
> The link:
> http://wiki.dlang.org/DIP40
> The paper links mentioned in the abstract are given in this DIP.
This DIP is lacking in detail.
struct A(T1)
if(!is(T1==float))
{
this(T2)(T2 a, T1 b){}
this()(T1 b){}
this()(){}
}
struct A(T1)
if(is(T1==float))
{
this()(){}
}
auto a=A(1,1.0); //deduced to A!(double)(1,1.0)
auto a=A(1.0); //deduced to A!(double)(1.0)
auto a=A(); //error: T1 cannot be deduced.
How does the compiler decide which templates to attempt to
instantiate? Does it just ignore conditional compilation
conditions? If so, what would it do with this?
struct A(T)
if (is(T==float) && is(T!=float))
{
this()(T a) {}
}
If the conditions are ignored then it will match this
uninstantiable template. If it doesn't ignore the conditions then
how does it determine T ahead of time to evaluate the conditions?
One possible solution could be to first ignore the conditions,
match the constructor, then check that the condition is okay.
This is an extension on how normal function type deduction works
though, so whatever mechanisms you have in mind need to be part
of the proposal.
More information about the Digitalmars-d
mailing list