On Tue, Jul 26, 2016 at 6:59 PM, Nicol Bolas <
jmck...@gmail.com> wrote:
> Template deduction for constructors allows us to declare a deduction guide
> that maps from potential usage to the actual template type. These deduction
> guides do not prevent a type from being an aggregate. So with a guide, this
> will work:
>
>
> template<typename T1, typename T2>
> struct new_pair
> {
> T1 t1;
> T2 t2;
> };
>
> template<typename T1, typename T2>
> new_pair(T1, T2) -> new_pair<T1, T2>;
>
> new_pair{12.3f, 90}; //T1 = float, T2 = int.
>
Yes.
> Does that mean that it is possible to make this work with `std::array`:
>
Yes.
> auto arr = std::array{2, 3, 1, 4, 44, 23}; //type is deduced as int, size is
> deduced as 6.
>
> I'm thinking of a guide like this:
>
> template<typename T>
> std::array(T ...ts) -> std::array<T, sizeof...(ts);
>
> Or if not that, what about:
>
> template<typename Ts...>
> std::array(Ts ...ts) -> std::array<std::common_type_t<T...>, sizeof...(ts)>;
>
Yes, that should work (modulo syntax bug regarding ellipsis placement
in your template parameter pack).
> If the current syntax doesn't allow a way to deduce the number of
> parameters... is there a way to make it work with some small change to the
> functionality?
>
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
std-proposal...@isocpp.org.
> To post to this group, send email to
std-pr...@isocpp.org.
> To view this discussion on the web visit
>
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7db3740d-f9cf-45ad-a8c6-c61c3b1f9e8f%40isocpp.org.