summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2023-01-24 13:34:42 -0500
committerNat Goodspeed <nat@lindenlab.com>2023-07-13 12:49:39 -0400
commitd2738b60e2dfa255e504247f2b5009bc1dc24954 (patch)
treee594d5a46d6eb50288b9b8d7062887836cbc503c /indra/llcommon
parent7c79d7a7d4d5cb1e39293cdc98fd972be5bd3012 (diff)
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)
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/apply.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/indra/llcommon/apply.h b/indra/llcommon/apply.h
index 123813bcec..0009dd1f80 100644
--- a/indra/llcommon/apply.h
+++ b/indra/llcommon/apply.h
@@ -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>