Skip to content
Snippets Groups Projects
Commit d2738b60 authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

DRTVWR-558: Fix const-ness glitch in LL::apply(func, tuple)

std::get<I>(const tuple) injects const into the type of each returned tuple
element. Need to get a non-const ref to the tuple param to get the true type.

(cherry picked from commit 6dda39065d3ee231998cb8a2896f94e8a45c9a82)
parent 7c79d7a7
No related branches found
No related tags found
2 merge requests!3Update to main branch,!2Rebase onto current main branch
......@@ -74,7 +74,7 @@ template<typename Fn, typename... Args,
int>::type = 0 >
auto invoke(Fn&& f, Args&&... args)
{
return std::mem_fn(f)(std::forward<Args>(args)...);
return std::mem_fn(std::forward<Fn>(f))(std::forward<Args>(args)...);
}
template<typename Fn, typename... Args,
......@@ -102,8 +102,15 @@ using std::apply;
template <typename CALLABLE, typename... ARGS, std::size_t... I>
auto apply_impl(CALLABLE&& func, const std::tuple<ARGS...>& args, std::index_sequence<I...>)
{
// We accept const std::tuple& so a caller can construct an tuple on the
// fly. But std::get<I>(const tuple) adds a const qualifier to everything
// it extracts. Get a non-const ref to this tuple so we can extract
// without the extraneous const.
auto& non_const_args{ const_cast<std::tuple<ARGS...>&>(args) };
// call func(unpacked args)
return invoke(std::forward<CALLABLE>(func), std::get<I>(args)...);
return invoke(std::forward<CALLABLE>(func),
std::forward<ARGS>(std::get<I>(non_const_args))...);
}
template <typename CALLABLE, typename... ARGS>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment