MSVC_CTAD_1428672

Comments on MSVC Alias Template Deduction Issue

I believe Bryce’s example in the linked MSVC Developer Community Issue on mdspan CTAD should work as he intended.

To avoid ambiguity, I’ve slightly modified Bryce’ godbolt to use EltType for the alias and ElementType for the guide (https://godbolt.org/z/aM93PEWcz)

The deduction guide f of basic_mdspan is

template <class ElementType, class... IndexType>
explicit basic_mdspan(ElementType*, IndexType...)
  -> basic_mdspan<ElementType, extents<__make_dynamic_extent<IndexType>()...>>;

According to over.match.class.deduct/2, we deduce the template arguments of basic_mdspan<ElementType, extents<__make_dynamic_extent<IndexType>()...>> from basic_mdspan<EltType, extents<Extents...>>; to deduce EltType for ElementType while IndexType is in a non-deducible context and therefore not deduced.

Again, according to over.match.class.deduct/2, we substitute these deductions into f to get a g with function type

basic_mdspan(EltType*, IndexType...)
  -> basic_mdspan<EltType, extents<__make_dynamic_extent<IndexType>()...>>;

Now we form a guide f' as follows.

Putting these together gives the following guide

template <class EltType, class... IndexType>
explicit basic_mdspan(EltType*, IndexType...)
requires is_mdspan<basic_mdspan<EltType, extents<__make_dynamic_extent<IndexType>()...>>>
  -> basic_mdspan<EltType, extents<__make_dynamic_extent<IndexType>()...>>;

Now line 49 of the godbolt should successfully deduce double for EltType and int, int for IndexType..., which clearly satisfies the constraint.

Please let me know if I’ve missed anything,

Mike