Skip to content

Constrained alias templates #39

@asutton

Description

@asutton

A constrained alias templates constraints are not checked when the arguments are dependent. However, the alias is substituted at the point of use, before instantiation.

template<C T> using X = const T;

template<typename T>
void f(T x) {
  X<T> y = x; // Potentially ill-formed
}

There are several ways an implementer might be able to check constraints:

  • Require that constrained alias templates not be substituted on use. This is probably a non-starter.
  • Propagate the constraints as part of the resulting type, basically inventing a new kind of "constrained type" that is valid only if the constraints are satsifed
  • Do not check the constraints

Morally, the alias should not be used if its constraints are not subsumed by the constraints of the surrounding context since instantiation could lead to substitution failures. This is effectively the same as separate checking, which is most definitely not required by concepts lite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions