I just read the updated interface for C++17 for std::tuple::get on cppreference http://en.cppreference.com/w/cpp/utility/tuple/get and the new overloads return const Type&& from the get<>() functions. Why would you want to return a const Type&& over just a regular const Type&? You can't move from instances of either type..
For reference these are the function declarations I am referring to
template< class T, class... Types >
constexpr const T&& get(const tuple<Types...>&& t);
and
template< std::size_t I, class... Types >
constexpr std::tuple_element_t<I, tuple<Types...> >const&&
get( const tuple<Types...>&& t );
A google search turned up Issue 2485, which pointed to a flaw like this:
#include <functional>
#include <string>
#include <tuple>
using namespace std;
string str1() { return "one"; }
const string str2() { return "two"; }
tuple<string> tup3() { return make_tuple("three"); }
const tuple<string> tup4() { return make_tuple("four"); }
int main() {
// cref(str1()); // BAD, properly rejected
// cref(str2()); // BAD, properly rejected
// cref(get<0>(tup3())); // BAD, properly rejected
cref(get<0>(tup4())); // BAD, but improperly accepted!
}
In this particular case, cref has a deleted overload for const T&&, but passing it through get is obscuring that the tuple, and its member, is a temporary.
You can move from mutable data from a const&&. It is relatively obscure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With