Surprise in replacing template parameters?

N3690, paragraph 14.8.2 of paragraph 3 has this rather breathtaking example:

template <class Z> void h(Z, Z*);
// #5: function type is h(int, const int*)
h<const int>(1,0);

Question: why is it not h(const int, const int*)?

How is it known, Z = const inttherefore, each appearance Zin the template declaration can be read as const int, or am I missing something? Why is the pointer different? I remember that when a parameter has T&or T*, it saves cv-qualifiers T, but I see no way to apply it here.

+6
source share
3 answers

You need to see [dcl.fct] / 5 for a reason:

; ( 13). , - . . ( ) decl-specifier-seq declarator. " " " " " " " " . , cv-, , . - parameter-type-list. [. . , int() (const int p, decltype (p)) int() (int, const int) . -end note]

const type* const const .

+10

:

[dcl.fct/5]

; . , -. . ( ) --seq . " " , " T". cv- , , , . - . [ : . , int() (const int p, decltype (p)) int() (int, const int) . - ]

, , cv-; , . , const .

Cv- ( ).

+10

cv- -POD-.

++ 11 § 8.3.5 Functions (. 181):

5

; ( 13). type parametertype-list. . ( ) decl-specifier-seq declarator. , " T" " T" " T" " " T ", . cv- , , , . - . [: . , int() (const int p, decltype (p)) int() (int, const int) . -end note]

There was a similar question for cv qualifiers with basic non-POD types.

+2
source

Source: https://habr.com/ru/post/1017270/


All Articles