Reputation: 2038
Like below, why "vv" here is not an rvalue-reference? Here the type of "v" is rvalue-reference, and according to the inference rule of decltype
, the decltype
of an rvalue-reference (not a prvalue) should be the type of rvalue-reference, right?
int main(int argc, char **argv) {
int x{};
const auto [v] = std::make_tuple<int&&>(std::move(x)); // v -> const int &&;
decltype(v) vv = 10; // vv -> const int;
return 0;
}
Upvotes: 2
Views: 484
Reputation: 3383
Happens because std::make_tuple<int&&>
returns std::tuple<int>
. From cppreference:
template<class... Types>
tuple<VTypes...> make_tuple( Types&&... args );
For each
Ti
inTypes...
, the corresponding typeVi
inVTypes...
isstd::decay<Ti>::type
unless application ofstd::decay
results instd::reference_wrapper<X>
for some typeX
, in which case the deduced type isX&
.
If you use std::tuple
instead of std::make_tuple
-- it works as you expect it to.
Here is code to play.
Upvotes: 2