dimanche 8 août 2021

What is the difference between normal rvalue reference and template rvalue reference? [duplicate]

A template rvalue reference acts differently than a normal rvalue reference.

void foo1 (int&& i) {}
template<typename T> void foo2 (T&& i) {}

int main ()
{
  int i = 3;
  foo1(i);  // ERROR as expected
  foo2(i);  // OK, but why?
}

Normal rvalue is giving error as expected, but template rvalue silently doesn't give error.
In fact there is a post on how to solve the issue in case of templates: How to make template rvalue reference parameter ONLY bind to rvalue reference?

Why are they different and is there any relevant section in the standard?

Aucun commentaire:

Enregistrer un commentaire