Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't C++ have a const universal reference?

Scott Meyers says (for parameters to function templates):

Universal references can only occur in the form "T&&"! Even the simple addition of a const qualifier is enough to disable the interpretation of "&&" as a universal reference.

Why doesn't C++ have a const universal reference? Any technical reason?

like image 381
Sadeq Avatar asked Jul 15 '14 16:07

Sadeq


Video Answer


1 Answers

What would a const universal reference be? It would be a reference that can not be modified. And moving from an rvalue-reference is a modification. Therefore, if there is such a thing as a const universal reference, it is simply const T&.

like image 146
Daniel Frey Avatar answered Sep 22 '22 04:09

Daniel Frey