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
tupleof arguments
Does this mean that applying std::apply to objects other than std::tuple is undefined behavior?
20.5.5 Calling a function with a
tupleof 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With