Home > Net >  How to set pack of type by number?
How to set pack of type by number?

Time:07-12

I need some thing like this

template<unsigned N>
class Class
{
    std::function<double(double, double ...)> _function1; // double N times
    std::function<double(double, ...)> _function2; // double N - 1 times
}

CodePudding user response:

Something along these lines, perhaps:

template <typename R, typename T, size_t N>
struct MakeFunctionType {
  template <size_t>
  using SwallowIndex = T;

  template <size_t... Is>
  static std::function<R(SwallowIndex<Is>...)>
      MakeFunctionTypeHelper(std::index_sequence<Is...>);

  using type = decltype(MakeFunctionTypeHelper(
      std::make_index_sequence<N>{}));
};

Demo

  • Related