This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
std::get not returning const rvalue reference from const rvalue reference of tuple
- From: Tim <tolez_xuninada at hotmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 9 May 2018 16:10:34 -0500 (CDT)
- Subject: std::get not returning const rvalue reference from const rvalue reference of tuple
Consider the following test.cpp:
#include<iostream>
#include <utility>
#include <tuple>
#include <boost/type_index.hpp>
#include <typeinfo>
using namespace std;
struct A {
tuple<int,double> a_;
A() {};
auto& foo() & { cout << "&" << endl; return a_; }
auto&& foo() && { cout << "&&" << endl; return std::move(a_); }
const auto& foo() const & { cout << "const &" << endl; return a_; }
const auto&& foo() const && { cout << "const &&" << endl; return
std::move(a_); }
};
using ConstA = const A;
int main(int argc, char* argv[]) {
cout <<
boost::typeindex::type_id_with_cvr<decltype(A{}.foo())>().pretty_name() <<
endl;
cout <<
boost::typeindex::type_id_with_cvr<decltype(ConstA{}.foo())>().pretty_name()
<< endl;
cout <<
boost::typeindex::type_id_with_cvr<decltype(std::get<0>(A{}.foo()))>().pretty_name()
<< endl;
cout <<
boost::typeindex::type_id_with_cvr<decltype(std::get<0>(ConstA{}.foo()))>().pretty_name()
<< endl;
cout <<
boost::typeindex::type_id_with_cvr<decltype(std::get<1>(A{}.foo()))>().pretty_name()
<< endl;
cout <<
boost::typeindex::type_id_with_cvr<decltype(std::get<1>(ConstA{}.foo()))>().pretty_name()
<< endl;
}
This outputs:
std::tuple<int, double>&&
std::tuple<int, double> const&&
int&&
int const&
double&&
double const&
but I was expecting the last line of output to be "double const&&" because
the following overload of std::get:
template< std::size_t I, class... Types >
constexpr std::tuple_element_t<I, tuple<Types...> >const&&
get( const tuple<Types...>&& t ) noexcept;
What am I missing here? I'm using gcc 7.3.0 and the above code is compiled
using "-std=c++17"
--
Sent from: http://gcc.1065356.n8.nabble.com/gcc-Help-f629689.html