Questions tagged [reference-collapsing]

Refers to the reference collapsing rules in C++ which specify how the type of template or auto variables should be deduced from the incoming types.

2 questions
2
votes
1 answer

What are the rules of rvalue(&&) lvalue(&) reference binding in templates with regard to reference collapsing?

Consider these cases: int i{}; int& ir{i}; class A{ public: int& i; A(int&& pi):i(pi){} }; A a1{i}; // Error // case 1 A a2{int(1)}; // OK // case 2 class B{ public: int& i; template B(TYPE&& pi):i(pi){} }; B…
AKL
  • 1,367
  • 7
  • 20
0
votes
1 answer

Type deduction and reference collapsing in CTAD

Seems like I don't understand something fundamental about the type deduction /reference collapsing rules of C++. Say I have an object entity which takes by rvalue reference in the constructor and has a data member of the same type. I was fine with…
glades
  • 3,778
  • 1
  • 12
  • 34