Question

are constrained alias templates allowed?

Checked the three major compilers, they all allow putting constraints on alias templates, for example:

template<class T, std::constructible_from<T> V>
using var_t = std::variant<T, V>;

template<class T, class...Args>
requires(std::constructible_from<T, Args...>)
using tup_t = std::tuple<T, Args...>;

But then cppreference has this to say:

Syntax
Alias declarations are declarations with the following syntax:

using identifier attr (optional) = type-id ;   (1)

template < template-parameter-list >
using identifier attr (optional) = type-id ;    (2)    

Is cpprefrence wrong and constraints are allowed?

 4  83  4
1 Jan 1970

Solution

 4

The cppreference is very good, but not always actual.

Yes, requires-clause is allowed in alias template that is a particular case of template-declaration. See temp.alias.

template-declaration:
    template-head declaration
    template-head concept-definition    

template-head:
    template < template-parameter-list > requires-clause[opt]
2024-07-07
3CxEZiVlQ