I'm learning structured binding, I'm confused with the type of identifier about "tuple-like" binding protocol, for example:
int a = 3;
double b = 2.1;
tuple<int, double&> tpl(a, b);
auto [a1, b1] = tpl;
auto& [a2, b2] = tpl;
auto&& [a3, b3] = tpl;
const auto& [a4, b4] = tpl;
using Ta1 = decltype(a1); // this is 'int',
using Tb1 = decltype(b1); // 'double&'
using Ta2 = decltype(a2); // 'int'
using Tb2 = decltype(b2); // 'double&'
using Ta3 = decltype(a3); // 'int'
using Tb3 = decltype(b3); // 'double&'
using Ta4 = decltype(a4); // 'const int'
using Tb4 = decltype(b4); // 'double &'
first, why Tb4
is double&
, but not const double&
?
second, is there any difference between auto&
and auto&&
? when should I use &
or &&
?
Thanks for your answer!