Reference:
e.g.
Non-Template Deduction Guides
Deduction Guides versus Constructors
Deduction guides compete with the constructors of a class.Class template argument deduction uses the constructor/guide that has the highest priority according to overload resolution.
If a constructor and a deduction guide match equally well, the deduction guide is preferred.
Explicit Deduction Guides
Deduction Guides for Aggregates
Note that (as usual for aggregate initialization) you still need curly braces.Otherwise, type T is successfully deduced but the initialization is an error:
In any case, for a type with complicated constructors such as std::vector<> and other STL containers, it is highly recommended not to use class template argument deduction and instead, to specify the element type(s) explicitly.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.