Exclude first n arguments from parameter pack

Viewed 1376

I have a function foo that calls a function bar with a subset of types passed into foo's variadic template. For example:

template <typename... T>
void foo() {
  // ...
  template <size_t start_idx, typename... T>
  using param_pack = /*Parameter pack with T[start_idx]...T[N]*/
  auto b = bar<param_pack<2, T...>>();
  // ...
}

Is there a way to extract a "sub-parameter pack". In the above case if T = [int float char double] then param_pack<2, T...> = [char double]

[EDIT]

My goal is to be able to use something like this to match event handlers. For example

struct ev {};

template <typename... T>
struct event : ev {
  std::tuple<T...> data_;

  event(T&&... d) : data_(std::make_tuple(std::forward<T>(d)...)) {}
};

template <typename... Functor>
struct handler {
  std::tuple<Functor...> funcs_;

  handler(Functor&&... f) : funcs_(std::make_tuple(std::forward<Functor>(f)...)) {}

  void handle_message(ev* e) {
    auto ptrs = std::make_tuple(
      dynamic_cast<event<param_pack<1, typename function_traits<F>::args>>*>(e)...
    ); 

    match(ptrs);
  }
};

Here function_traits::args get a parameter pack for the function arguments and match iterates over the the tuple funcs_ checking if the dynamic_cast was successful and executing the first successful function. I already have these implemented.

The handlers are something like

[] (handler* self, <ARGS>) -> void {
  // ...
}

I am essentially trying to get rid of the self argument.

3 Answers
Related