Title
tuple get API should respect rvalues
Status
c++11
Section
[tuple.elem]
Submitter
Alisdair Meredith

Created on 2009-08-18.00:00:00 last changed 162 months ago

Messages

Date: 2010-11-23.13:22:14

Proposed resolution:

Add the following signature to p2 [tuple.general]


template <size_t I, class ... Types>
typename tuple_element<I, tuple<Types...> >::type&& get(tuple<Types...> &&);

And again to [tuple.elem].


template <size_t I, class ... Types>
typename tuple_element<I, tuple<Types...> >::type&& get(tuple<Types...>&& t);

Effects: Equivalent to return std::forward<typename tuple_element<I, tuple<Types...> >::type&&>(get<I>(t));

[Note: If a T in Types is some reference type X&, the return type is X&, not X&&. However, if the element type is non-reference type T, the return type is T&&. — end note]

Add the following signature to p1 [utility]


template <size_t I, class T1, class T2>
typename tuple_element<I, pair<T1,T2> >::type&& get(pair<T1, T2>&&);

And to p5 [pair.astuple]


template <size_t I, class T1, class T2>
typename tuple_element<I, pair<T1,T2> >::type&& get(pair<T1, T2>&& p);

Returns: If I == 0 returns std::forward<T1&&>(p.first); if I == 1 returns std::forward<T2&&>(p.second); otherwise the program is ill-formed.

Throws: Nothing.

Add the following signature to [sequences] <array> synopsis

template <size_t I, class T, size_t N>
T&& get(array<T,N> &&);

And after p8 [array.tuple]

template <size_t I, class T, size_t N>
T&& get(array<T,N> && a);

Effects: Equivalent to return std::move(get<I>(a));

Date: 2010-11-23.13:22:14

[ Adopted at 2010-11 Batavia ]

Date: 2010-10-21.19:00:35

[ 2010 Rapperswil: ]

Note that wording has been provided, and this issue becomes more important now that we have added a function to support forwarding argument lists as tuples. Move to Tentatively Ready.

Date: 2009-10-30.00:00:00

[ 2009-10-30 Alisdair adds: ]

The issue of rvalue overloads of get for tuple-like types was briefly discussed in Santa Cruz.

The feedback was this would be welcome, but we need full wording for the other types (pair and array) before advancing.

I suggest the issue moves to Open from New as it has been considered, feedback given, and it has not (yet) been rejected as NAD.

Date: 2009-08-18.00:00:00

The tuple get API should respect rvalues. This would allow for moving a single element out of a tuple-like type.

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-11-23 13:22:14adminsetmessages: + msg5398
2010-11-14 13:10:57adminsetstatus: voting -> wp
2010-11-08 14:14:39adminsetstatus: ready -> voting
2010-10-21 19:00:35adminsetmessages: + msg4752
2010-10-21 19:00:35adminsetstatus: open -> ready
2010-10-21 18:28:33adminsetmessages: + msg1080
2010-10-21 18:28:33adminsetmessages: + msg1079
2009-08-18 00:00:00admincreate