Issue 2485: get() should be overloaded for const tuple&& (original) (raw)

This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.

Section: 22.4.8 [tuple.elem] Status: C++17 Submitter: Stephan T. Lavavej Opened: 2015-03-27 Last modified: 2017-07-30

const rvalues are weird, but they're part of the type system. Consider the following code:

#include #include #include

using namespace std;

string str1() { return "one"; } const string str2() { return "two"; } tuple tup3() { return make_tuple("three"); } const tuple 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! }

As tuple is a fundamental building block (and the only convenient way to have variadic data members), it should not open a hole in the type system. get() should imitate 7.6.1.5 [expr.ref]'s rules for accessing data members. (This is especially true for pair, where both get<0>() and .first are available.)

While we're in the neighborhood, we can dramatically simplify the wording here. All we need to do is follow 22.4.8 [tuple.elem]/9's example of saying "Returns: A reference to STUFF", and allow implementers to figure out how to achieve that with the given return types.

TP: for the existing overloads there's no change to the code, just descriptions?
STL: right.
JW: I love it
MC: in favor of moving to Ready and bringing up for vote on Friday
7 in favor, none opposed

This wording is relative to N4296.