How to do it...

To return multiple values from a function using a compiler that supports C++17 you should do the following:

  1. Use an std::tuple for the return type.
        std::tuple<int, std::string, double> find() 
{
return std::make_tuple(1, "marius", 1234.5);
}
  1. Use structured bindings to unpack the values of the tuple into named objects.
        auto [id, name, score] = find();
  1. Use decomposition declaration to bind the returned values to variables inside an if statement or switch statement.
        if (auto [id, name, score] = find(); score > 1000) 
{
std::cout << name << std::endl;
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset