From 8ac35b626072bd94178861dbbaf7d835354c9765 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 22 Dec 2022 15:51:56 -0500 Subject: DRTVWR-558: Add apply_n(function, std::vector) for variadics. apply_n(function, LLSD array) has been useful, so for completeness, add the corresponding function for std::vector. Add a reference to apply_n() in comments for both apply() functions. (cherry picked from commit dfb63a92e0e9a419931caf5112e1f590924e0867) --- indra/llcommon/apply.h | 19 ++++++++++++++----- indra/llcommon/llsdutil.h | 3 ++- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/apply.h b/indra/llcommon/apply.h index 357887dfd7..123813bcec 100644 --- a/indra/llcommon/apply.h +++ b/indra/llcommon/apply.h @@ -188,19 +188,28 @@ struct apply_error: public LLException apply_error(const std::string& what): LLException(what) {} }; +template +auto apply_n(CALLABLE&& func, const std::vector& args) +{ + apply_validate_size(args.size(), ARITY); + return apply_impl(std::forward(func), + args, + std::make_index_sequence()); +} + /** * apply(function, std::vector) goes beyond C++17 std::apply(). For this case * @a function @emph cannot be variadic: the compiler must know at compile - * time how many arguments to pass. This isn't Python. + * time how many arguments to pass. This isn't Python. (But see apply_n() to + * pass a specific number of args to a variadic function.) */ template auto apply(CALLABLE&& func, const std::vector& args) { + // infer arity from the definition of func constexpr auto arity = boost::function_traits::arity; - apply_validate_size(args.size(), arity); - return apply_impl(std::forward(func), - args, - std::make_index_sequence()); + // now that we have a compile-time arity, apply_n() works + return apply_n(std::forward(func), args); } } // namespace LL diff --git a/indra/llcommon/llsdutil.h b/indra/llcommon/llsdutil.h index 546e27930d..baf4400768 100644 --- a/indra/llcommon/llsdutil.h +++ b/indra/llcommon/llsdutil.h @@ -621,7 +621,8 @@ auto apply_n(CALLABLE&& func, const LLSD& args) /** * apply(function, LLSD) goes beyond C++17 std::apply(). For this case * @a function @emph cannot be variadic: the compiler must know at compile - * time how many arguments to pass. This isn't Python. + * time how many arguments to pass. This isn't Python. (But see apply_n() to + * pass a specific number of args to a variadic function.) */ template auto apply(CALLABLE&& func, const LLSD& args) -- cgit v1.2.3