new DIP40: Template parameter deduction for constructors
Steven Schveighoffer
schveiguy at yahoo.com
Mon May 13 15:56:40 PDT 2013
On Sun, 12 May 2013 22:37:43 -0400, Timothee Cour
<thelastmammoth at gmail.com> wrote:
> A proposed feature of C++14 is to introduce template parameter
> deduction for constructors, see paper, mentioned here. The idea is to
> deduce template parameters when calling a constructor given the
> arguments given to the constructor, whenever possible. A compile error
> occurs when the deduction is ambiguous. The benefits would be:
> * make the code more DRY
> * make boilerplate of class instantiators unnecessary in most cases
> (they're all over phobos, eg: std.typecons.tuple,
> std.typecons.rebindable etc)
> * make D more consistent: it deduces template parameters for
> functions, so why not for constructors, when this is unambiguous?
> * it won't break any code.
> Note, just as for deduction of normal functions, it should work with 0
> or more template parameters specified (ie the first k>=0 templates may
> be provided).
Definitely need/want this.
I say it is most definitely possible given how IFTI works (it must
partially instantiate the template). It should be noted that conditional
compilation can stop this from working. As a first step, it should have
exactly the same rules as IFTI, assuming the constructor is the eponymous
IFTI function.
BTW, related issue: http://d.puremagic.com/issues/show_bug.cgi?id=6082
with 4 votes so far
Added a link there.
-Steve
More information about the Digitalmars-d
mailing list