Template Pointer Package

Why can't a template function with a package of pointer template parameters be created using offsets of the same pointer?

I mean: given this short code, why should I comment on the last two lines?

template <int * ... pt> void f() {}

int n[] = {1, 2, 3};
int m = n[1];

int main()
{
    f<n>();  // this is accepted
    f<n, &m>();  // this is accepted too
    //f<n, n+1>(); // this is not.
    //f<n, &n[1]>(); // this isn't accepted neither
}

Does n+1the same address match &m? Or is there a difference in communication? Or what else?

+6
source share
2 answers

See cppreference.com - Non-type Argument Pattern

  • ( , ) , std:: nullptr_t.

...

, /

  • ( , );
  • ( );

, .

+3

++ 17 [temp.arg.nontype]:

- non-type ( , ):

  • ,
  • [...]

, [intro.object]:

, . - ([class.mem]), ([class.derived]) .

&m - - . n[1], .

, n+1 &n[1] n, n, , , . n+1 &m .


++ 11 ++ 14, , , :

- :

  • [...]
  • ([expr.const]), , function template-ids, , ( ) [...]
  • [...]

m , n[1] - .

+2

All Articles