3

The function signature of std::apply does not constrain the template parameter Tuple to be a specialization of std::tuple, so it can still accept a tuple-like objects that defines std::tuple_size_v (godbolt):

#include <tuple>
#include <utility>
#include <array>

int main() {
  std::apply([](int, int) {}, std::array{0, 0});
  std::apply([](int, int) {}, std::pair {0, 0});
  std::apply([](int, int) {}, std::tuple{0, 0});
}

But the description of std::apply in [tuple.apply] is:

20.5.5 Calling a function with a tuple of arguments

Does this mean that applying std::apply to objects other than std::tuple is undefined behavior?

康桓瑋
  • 33,481
  • 5
  • 40
  • 90

1 Answers1

7

20.5.5 Calling a function with a tuple of arguments

I highly doubt that the section titles are normative.

The actual function is described as being equivalent to the reference implementation, which uses get and tuple_size_v to inspect the "tuple" parameter.

Cppreference concurs.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
  • @康桓瑋 Oops, I've removed the part about user-defined types. I wonder why `make_from_tuple`, which is defined right next to it, uses unqualified `get`... – HolyBlackCat Sep 11 '21 at 12:44
  • They use `std::get`, not unqualified ones, per [contents]/3 https://eel.is/c++draft/contents#3. – F.v.S. Sep 28 '22 at 07:42