For the following:
// Manual typing - explicit and clear
const int& manual_ref = some_value;
int manual_copy = some_value;
// auto typing - convenient but potentially misleading
auto auto_ref = some_value; // int (not const int&!)
auto auto_copy = some_value; // int
// The problem: auto_ref and manual_ref are different types!
static_assert(std::is_same_v<decltype(manual_ref), const int&>, “manual_ref is const int&”);
static_assert(std::is_same_v<decltype(auto_ref), int>, “auto_ref is int”);
Instead of
auto auto_ref = some_value; // int (not const int&!)
auto auto_copy = some_value; // int
It should be
auto auto_ref = manual_ref; // int (not const int&!)
auto auto_copy = manual_copy; // int