This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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&lt;0>(A{}.foo()))>().pretty_name()
<< endl;
  cout <<
boost::typeindex::type_id_with_cvr<decltype(std::get&lt;0>(ConstA{}.foo()))>().pretty_name()
<< endl;

  cout <<
boost::typeindex::type_id_with_cvr<decltype(std::get&lt;1>(A{}.foo()))>().pretty_name()
<< endl;
  cout <<
boost::typeindex::type_id_with_cvr<decltype(std::get&lt;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&lt;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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]