In cppreference add_const
it is said we may implement it as:
template< class T> struct add_const { typedef const T type; };
When I try a reference type, like std::add_const<int&>
, it is int&
.
My question is why it can work without a specific version for reference, since int& const
is illegal?
In [dcl.ref]p1 of the C++11 standard, you can find:
Cv-qualified references are ill-formed except when the cv-qualifiers are introduced through the use of a typedef (7.1.3) or of a template type argument (14.3), in which case the cv-qualifiers are ignored.
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.