Title
Equivalence of alias templates
Status
drafting
Section
13.7.8 [temp.alias]
Submitter
Gabriel Dos Reis

Created on 2011-04-03.00:00:00 last changed 107 months ago

Messages

Date: 2015-05-15.00:00:00

Notes from the May, 2015 meeting:

See also issue 1979, which CWG is suggesting to be resolved by defining a “simple” alias, one in which the SFINAE conditions are the same as the referenced template and that uses all template parameters.

Date: 2014-11-24.00:00:00

Additional note, November, 2014:

Concern has been expressed over the proposed resolution with regard to its handling of default template arguments that differ between the template and its alias, e.g.,

   template<typename T, typename U = int> struct A {};
   template<typename T, typename U = char> using B = A<T, U>;
   template<template<typename...> typename C> struct X { C<int> c; };
Date: 2012-09-15.00:00:00

Proposed resolution (September, 2012):

  1. Add the following as a new paragraph following 13.7.8 [temp.alias] paragraph 2:

  2. When the type-id in the declaration of alias template (call it A) consists of a simple-template-id in which the template-argument-list consists of a list of identifiers naming each template-parameter of A exactly once in the same order in which they appear in A's template-parameter-list, the alias template is equivalent to the template named in the simple-template-id (call it T) if A and T have the same number of template-parameters. [Footnote: This rule is transitive: if an alias template A is equivalent to another alias template B that is equivalent to a class template C, then A is also equivalent to C, and A and B are also equivalent to each other. —end footnote] [Example:

      template<typename T, U = T> struct A;
    
      template<typename V, typename W>
        using B = A<V, W>;                // equivalent to A
    
      template<typename V, typename W>
        using C = A<V>;                   // not equivalent to A:
                                          // not all parameters used
    
      template<typename V>
        using D = A<V>;                   // not equivalent to A:
                                          // different number of parameters
    
      template<typename V, typename W>
        using E = A<W, V>;                // not equivalent to A:
                                          // template-arguments in wrong order
    
      template<typename V, typename W = int>
        using F = A<V, W>;                // equivalent to A:
                                          // default arguments not considered
    
      template<typename V, typename W>
        using G = A<V, W>;                // equivalent to A and B
    
      template<typename V, typename W>
        using H = E<V, W>;                // equivalent to E
    
      template<typename V, typename W>
        using I = A<V, typename W::type>; // not equivalent to A:
                                          // argument not identifier
    
    

    end example]

  3. Change 13.6 [temp.type] paragraph 1 as follows:

  4. Two template-ids refer to the same class or function if

    • ...

    • their corresponding template template-arguments refer to the same or equivalent (13.7.8 [temp.alias]) templates.

    [Example:

    ...declares x2 and x3 to be of the same type. Their type differs from the types of x1 and x4.

      template<class T template<class> class TT> struct X { };
      template<class> struct Y { };
      template<class T> using Z = Y<T>;
      X<Y<int> Y> y;
      X<Z<int> Z> z;
    

    declares y and z to be of the same type. —end example]

Date: 2012-09-24.00:00:00

Issue 1244 was resolved by changing the example in 13.6 [temp.type] paragraph 1 from

  template<template<class> class TT> struct X { };
  template<class> struct Y { };
  template<class T> using Z = Y<T>;
  X<Y> y;
  X<Z> z;

to

  template<class T> struct X { };
  template<class> struct Y { };
  template<class T> using Z = Y<T>;
  X<Y<int> > y;
  X<Z<int> > z;

In fact, the original intent was that the example should have been correct as written; however, the normative wording to make it so was missing. The current wording of 13.7.8 [temp.alias] deals only with the equivalence of a specialization of an alias template with the type-id after substitution. Wording needs to be added specifying under what circumstances an alias template itself is equivalent to a class template.

History
Date User Action Args
2015-05-25 00:00:00adminsetmessages: + msg5523
2014-11-24 00:00:00adminsetmessages: + msg5222
2012-11-03 00:00:00adminsetstatus: review -> drafting
2012-09-24 00:00:00adminsetmessages: + msg3893
2012-09-24 00:00:00adminsetstatus: drafting -> review
2012-02-27 00:00:00adminsetstatus: open -> drafting
2011-04-03 00:00:00admincreate