File: qualifications.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (23 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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:
        verb(    template<typename Type>
    Type negate(Type const &value)
    {
        return -value;
    }
    int main()
    {
        int x = 5;
        x = negate(x);
    })

Here we see the function template's tt(Type const &value) parameter: a
reference to a tt(const Type). However, the argument isn't a tt(const int),
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).