geode-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hitesh Khamesra <>
Subject Re: [VOTE] C++ standardize on return values only
Date Wed, 04 Oct 2017 00:45:29 GMT
Tuple option.

Sent from Yahoo Mail on Android 
  On Tue, Oct 3, 2017 at 4:27 PM, Jacob Barrett<> wrote:   Voting
on the conversation around C++ return values vs. out parameters.
This vote is to adopt the standard of return values over the use of out
parameters. On functions that must return more than one value to use the
C++11 std::tuple type for future compatibility with C++17.

For example:

std::tuple<int, std::string> foo::getAAndB() {...}

And call it with:

int a;
std::string b;
std::tie(a, b) = foo.getAAndB();

Alternatively the tuple can be called like:

auto r = foo.getAAndB();
auto a = std::get<0>(r);
auto b = std::get<1>(r);

In C++17:

auto [a, b] = foo.getAAndB();

Rather than:

int foo::getAAndB(std::string& b) {...}

Called like

std::string b;
auto a = foo.getAAndB(b);


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message