const className& f();
If I have a function that return const ref. And use it's value to assign to a variable using auto
auto v1 = className();
auto& v2 = className();
const auto& v3 = className();
decltype(auto) v4 = className();
As far as I understand all those three option will be same. But should I still prefer to write like for v3 to be explicit in my code that it's const ref? Or maybe in C++14/C++17/C++20 now there is some other preferrable way?
Or am I wrong and they are actually different? UPDATE: so seems I was wrong. And only decltype(auto) and const auto& will make variable const ref?
Aucun commentaire:
Enregistrer un commentaire