2010-01-29 15:32:15 +01:00
|
|
|
A emi(qualification transformation) adds ti(const) or ti(volatile)
|
|
|
|
qualifications to em(pointers). This transformation is applied when the
|
|
|
|
function template's type parameter explicitly specifies tt(const) (or
|
|
|
|
tt(volatile)) but the function's argument isn't a tt(const) or tt(volatile)
|
|
|
|
entity. In that case tt(const) or tt(volatile) is provided by the compiler.
|
|
|
|
Subsequently the compiler deduces the template's type parameter. For example:
|
2006-09-04 10:26:34 +02:00
|
|
|
verb(
|
|
|
|
template<typename Type>
|
|
|
|
Type negate(Type const &value)
|
|
|
|
{
|
|
|
|
return -value;
|
|
|
|
}
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int x = 5;
|
|
|
|
x = negate(x);
|
|
|
|
}
|
|
|
|
)
|
2007-04-11 14:30:22 +02:00
|
|
|
Here we see the function template's tt(Type const &value) parameter: a
|
2006-09-04 10:26:34 +02:00
|
|
|
reference to a tt(const Type). However, the argument isn't a tt(const int),
|
2010-01-29 15:32:15 +01:00
|
|
|
but an tt(int) that can be modified. Applying a qualification transformation,
|
|
|
|
the compiler adds tt(const) to tt(x)'s type, and so it matches tt(int const
|
|
|
|
x). This is then matched against tt(Type const &value) allowing the compiler
|
|
|
|
to deduce that tt(Type) must be tt(int).
|