summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/apply.h19
-rw-r--r--indra/llcommon/llsdutil.h3
2 files changed, 16 insertions, 6 deletions
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 <size_t ARITY, typename CALLABLE, typename T>
+auto apply_n(CALLABLE&& func, const std::vector<T>& args)
+{
+ apply_validate_size(args.size(), ARITY);
+ return apply_impl(std::forward<CALLABLE>(func),
+ args,
+ std::make_index_sequence<ARITY>());
+}
+
/**
* 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 <typename CALLABLE, typename T>
auto apply(CALLABLE&& func, const std::vector<T>& args)
{
+ // infer arity from the definition of func
constexpr auto arity = boost::function_traits<CALLABLE>::arity;
- apply_validate_size(args.size(), arity);
- return apply_impl(std::forward<CALLABLE>(func),
- args,
- std::make_index_sequence<arity>());
+ // now that we have a compile-time arity, apply_n() works
+ return apply_n<arity>(std::forward<CALLABLE>(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 <typename CALLABLE>
auto apply(CALLABLE&& func, const LLSD& args)