Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading