I had a code like:
std::tie(info.amount, info.price) = GetAmountAndPrice();
and the GetAmountAndPrice
was returning std::pair
so it worked.
But there was a code review suggesting to change the return type to struct so it's clear what the returned values represent, I think it's quite common point.
But with changing the return type from std::pair
to some struct, I can't use the std::tie
to set the members of info
.
(And I obviously don't want to create a temporary instance of the returned struct to load the values.)
What is a neat modern way to solve this? We use C++17, but I am curious even for C++20, if it improved.