This function works fine:
std::string get_str() {
return std::get<0>( make_tuple(std::string("hi")) );
}
But if you try to do the same thing with a trailing return type defined by decltype, the function returns a dangling rvalue reference:
auto get_str() -> decltype( std::get<0>( make_tuple(std::string("hi")) ) ) {
return std::get<0>( make_tuple(std::string("hi")) );
}
I have a cool application of trailing return type where I’d like to use std::get. Unfortunately, the return type of std::get is an rvalue reference in this case, so decltype is just doing its job…
Do you know of a way to use the trailing return type and decltype but avoid the dangling rvalue reference?
You could remove the reference using the standard
remove_referencetype trait: