6

Consider:

std::tuple<bool, double, int> getTuple()
{
    return {};
}

What does the standard say about the values in the resulting tuple in this case? Is it guaranteed that e.g. the bool is always false?

juzzlin
  • 45,029
  • 5
  • 38
  • 50
  • I'm going to guess yes, because of [this](https://stackoverflow.com/q/3308028/10957435), but that is assuming tuples use default constructors like this. –  Dec 29 '19 at 22:54

1 Answers1

10

The default constructor of tuple is specified to value-initialize all elements, see case 1 in cppreference link.

In brief, value-initialization is the same as if the element were initialized by {} (there are corner cases I'm omitting). For primitive types this means bool is false, double is 0.0 and int is 0 .

M.M
  • 138,810
  • 21
  • 208
  • 365