DRTVWR-558: Constrain LL::apply()'s use of std::apply().

Once std::apply() becomes available, 'using std::apply;' isn't correct because
the more general template tries to handle the apply(function, vector) case
that we explicitly implement below. Have to provide apply(function, tuple) and
apply(function, array) signatures that can forward to std::apply().
master
Nat Goodspeed 2023-07-13 16:01:56 -04:00
parent 7d1a3d7037
commit 3b46c89271
1 changed files with 10 additions and 3 deletions

View File

@ -93,7 +93,14 @@ auto invoke(Fn&& f, Args&&... args)
#if __cpp_lib_apply >= 201603L
// C++17 implementation
using std::apply;
// We don't just say 'using std::apply;' because that template is too general:
// it also picks up the apply(function, vector) case, which we want to handle
// below.
template <typename CALLABLE, typename... ARGS>
auto apply(CALLABLE&& func, const std::tuple<ARGS...>& args)
{
return std::apply(std::forward<CALLABLE>(func), args);
}
#else // C++14
@ -124,6 +131,8 @@ auto apply(CALLABLE&& func, const std::tuple<ARGS...>& args)
std::index_sequence_for<ARGS...>{});
}
#endif // C++14
// per https://stackoverflow.com/a/57510428/5533635
template <typename CALLABLE, typename T, size_t SIZE>
auto apply(CALLABLE&& func, const std::array<T, SIZE>& args)
@ -131,8 +140,6 @@ auto apply(CALLABLE&& func, const std::array<T, SIZE>& args)
return apply(std::forward<CALLABLE>(func), std::tuple_cat(args));
}
#endif // C++14
/*****************************************************************************
* bind_front()
*****************************************************************************/