简体   繁体   中英

Which rule in the C++11 Standard does describe the matching mentioned below?

std::remove_reference uses the following implementations:

template< class T > struct remove_reference      {typedef T type;};
template< class T > struct remove_reference<T&>  {typedef T type;};
template< class T > struct remove_reference<T&&> {typedef T type;};

Thus, if one does std::remove_reference<int&> the type int& will match the T& specialization. If we use std::remove_reference<int&&> the type int&& matches the T&& specialization.

I'd like to know which rule in the Standard describes this matching process.

§14.5.5.1/1

When a class template is used in a context that requires an instantiation of the class, it is necessary to determine whether the instantiation is to be generated using the primary template or one of the partial specializations. This is done by matching the template arguments of the class template specialization with the template argument lists of the partial specializations.

— If exactly one matching specialization is found, the instantiation is generated from that specialization.

— If more than one matching specialization is found, the partial order rules (14.5.5.2) are used to determine whether one of the specializations is more specialized than the others. If none of the specializations is more specialized than all of the other matching specializations, then the use of the class template is ambiguous and the program is ill-formed.

— If no matches are found, the instantiation is generated from the primary template.

Matching occurs by a process similar to function template parameter deduction. §14.5.5.1/2:

A partial specialization matches a given actual template argument list if the template arguments of the partial specialization can be deduced from the actual template argument list (14.8.2). ...

For std::remove_reference<int&> only the T& partial specialization matches, so it is selected. For std::remove_reference<int&&> only the T&& partial specialization matches, so it is selected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM