Title
Explicit tuple constructors for more than one parameter
Status
resolved
Section
[tuple.tuple] [tuple.cnstr]
Submitter
Ville Voutilainen

Created on 2011-05-01.00:00:00 last changed 104 months ago

Messages

Date: 2015-09-27.20:30:23
Resolved by the adoption of

Proposed resolution:

N4387.
Date: 2015-12-17.07:21:33

[ Lenexa 2015-05-05 ]

VV: While in the area of tuples, LWG 2051 should have status of WP, it is resolved by Daniel's "improving pair and tuple" paper.

MC: status Resolved, by N4387

Date: 2012-10-19.07:50:57

[ Portland, 2012 ]

Move to Open at the request of the Evolution Working Group.

Date: 2011-08-16.10:45:53

[ Bloomington, 2011 ]

Move to NAD Future, this would be an extension to existing functionality.

Date: 2011-05-03.17:43:05

One of my constituents wrote the following:

-------snip------------

So far the only use I've found for std::tuple is as an ad-hoc type to emulate multiple return values. If the tuple ctor was made non-explicit one could almost think C++ supported multiple return values especially when combined with std::tie().

// assume types line_segment and point
// assume function double distance(point const&, point const&)

std::tuple<point, point>
closest_points(line_segment const& a, line_segment const& b) {
 point ax;
 point bx;
 /* some math */

 return {ax, bx};
}


double
distance(line_segment const& a, line_segment const& b) {
 point ax;
 point bx;
 std::tie(ax, bx) = closest_points(a, b);

 return distance(ax, bx);
}

-------snap----------

See also the messages starting from lib-29330.

Some notes:

  1. pair allows such a return
  2. a lambda with a deduced return type doesn't allow it for any type
  3. decltype refuses {1, 2}

I would recommend making non-unary tuple constructors non-explicit.

History
Date User Action Args
2015-09-27 20:30:23adminsetmessages: + msg7544
2015-09-27 20:30:23adminsetmessages: + msg7543
2015-09-27 20:30:23adminsetstatus: open -> resolved
2012-10-19 07:50:57adminsetmessages: + msg6179
2012-10-19 07:50:57adminsetstatus: nad future -> open
2011-08-16 10:45:53adminsetmessages: + msg5839
2011-08-16 10:45:53adminsetstatus: new -> nad future
2011-05-01 00:00:00admincreate