C++ Logo

std-proposals

Advanced search

Re: Explicit alias template specialization

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Fri, 19 Nov 2021 11:13:22 -0500
On Fri, Nov 19, 2021 at 10:58 AM Nicolas Weidmann <n.weidmann_at_[hidden]>
wrote:

> All I am saying is that alias templates are not as transparent to type
> deduction as written in your first response.
>

Yes, they are.
Dependent member types are (always?) non-transparent "firewalls" against
deduction, but *aliases* are never(!) firewalls.

  template<class T> using A1 = T*;
  template<class T> using A2 = std::vector<T>&;
  template<class T> using A3 = std::vector<T>::iterator;
  template<class T> using A4 = std::identity<T>::type;

  template<class T> void a1(A1<T>); // transparently equivalent to `a1(T*)`
  template<class T> void a2(A2<T>); // transparently equivalent to
`a2(std::vector<T>&)`
  template<class T> void a3(A3<T>); // transparently equivalent to
`a3(std::vector<T>::iterator)`
  template<class T> void a4(A4<T>); // transparently equivalent to
`a4(std::identity<T>::type)`

In a1 and a2 (no matter which syntax you use to write them), the function
parameter contributes to deduction of T.
In a3 and a4 (no matter which syntax you use to write them), the function
parameter won't contribute to deduction of T, because there's a "firewall"
dependent member type involved.

HTH,
Arthur

>

Received on 2021-11-19 10:13:35