diff options
| author | Nat Goodspeed <nat@lindenlab.com> | 2022-12-22 15:51:56 -0500 | 
|---|---|---|
| committer | Nat Goodspeed <nat@lindenlab.com> | 2023-07-13 12:47:58 -0400 | 
| commit | 8ac35b626072bd94178861dbbaf7d835354c9765 (patch) | |
| tree | 94abf006c0481ee18ad9828381cdb05fb5d4863c /indra | |
| parent | 07c5645f5f9130a7fc338df0bc2bb791d43bd702 (diff) | |
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)
Diffstat (limited to 'indra')
| -rw-r--r-- | indra/llcommon/apply.h | 19 | ||||
| -rw-r--r-- | indra/llcommon/llsdutil.h | 3 | 
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) | 
