~ubuntu-branches/ubuntu/gutsy/c++-annotations/gutsy

« back to all changes in this revision

Viewing changes to yo/templatefunctions/argumentdeduction.yo

  • Committer: Bazaar Package Importer
  • Author(s): Frank B. Brokken
  • Date: 2007-06-15 19:31:12 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070615193112-i48grmnykrf1ipqf
Tags: 7.0.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
it will only consider the types of the arguments. Neither local variables nor
12
12
the function's return value is considered in this process. This is
13
13
understandable: when a function is called, the compiler will only see the
14
 
template function's arguments with certainty. At the point of the call it will
 
14
function template's arguments with certainty. At the point of the call it will
15
15
definitely not see the types of the function's local variables, and the
16
16
function's return value might not actually be used, or may be assigned to a
17
17
variable of a subrange (or super-range) type of a deduced template type
20
20
template type parameter.
21
21
        verb(
22
22
    template <typename Type>
23
 
    Type fun()              // can never be called
 
23
    Type fun()              // can never be called as `fun()'
24
24
    {
25
25
        return Type();
26
26
    }
27
27
        )
 
28
    Although the compiler won't be able to handle a call to `tt(fun())', it
 
29
em(is) possible to call tt(fun()) using an exmplicit type specification. E.g.,
 
30
tt(fun<int>()) will call tt(fun()), instantiated for tt(int). This, of course
 
31
is em(not) the same as em(compiler) argument deduction.
 
32
 
28
33
    In general, when a function has multiple parameters of identical template
29
34
type parameters, the actual types must be exactly the same. So, whereas
30
35
        centt(void binarg(double x, double y);)
31
36
    may be called using an tt(int) and a tt(double), with the tt(int) argument
32
37
implicitly being converted to a tt(double), the corresponding
33
 
template function cannot be called using an tt(int) and tt(double) argument:
 
38
function template cannot be called using an tt(int) and tt(double) argument:
34
39
the compiler won't itself promote tt(int) to tt(double) and to decide next
35
40
that tt(Type) should be tt(double):
36
41
        verb(
49
54
of
50
55
        hi(template: parameter type transformations)
51
56
    parameter type transformations (and a fourth one to function parameters of
52
 
any fixed type (i.e., of a non-template function parameter type)). If it
 
57
any fixed type (i.e., of a function non-template parameter type)). If it
53
58
cannot deduce the actual types using these transformations, the template
54
59
function will not be considered. These transformations are:
55
60
    itemization(
62
67
was provided in the call.
63
68
    it() Standard transformations for template non-type function
64
69
parameters. This isn't a template parameter type transformation, but it refers
65
 
to any remaining template non-type parameter of template functions. For these
 
70
to any remaining template non-type parameter of function templates. For these
66
71
function parameters the compiler will perform any standard conversion it has
67
72
available (e.g., tt(int) to tt(size_t), tt(int) to tt(double), etc.).
68
73
    )