C++ Quiz132 of 173
Difficulty:
⬅️ Prev: 277Quiz ID: 278Next: 279 ➡️

According to the C++23 standard, what is the output of this program?

#include <iostream>
#include <tuple>

int main()
{
    const auto t = std::make_tuple(42, 3.14, 1337);
    std::cout << std::get<int>(t);
}
Hint

There are two ints in the tuple.

Reveal answer

The program has a compilation error

Explanation

std::get(tuple) can only be used on a tuple which has exactly one T in it.

§[tuple.elem]¶5:

(...)
template<class T, class... Types>
  constexpr const T& get(const tuple<Types...>& t) noexcept;
(...)

Mandates: The type T occurs exactly once in Types.

⬅️ Prev: 277Quiz ID: 278Next: 279 ➡️