小编The*_*Ham的帖子

"解包"std :: array <T,N>作为函数的参数

这是一个非常好的(不是我的)示例,你可以如何扩展(或"爆炸")元组作为函数的参数:

template<int ...I> struct index_tuple_type {
  template<int N> using append = index_tuple_type<I..., N>;
};

template<int N> struct make_index_impl {
  using type = typename make_index_impl<N-1>::type::template append<N-1>;
};

template<> struct make_index_impl<0> { using type = index_tuple_type<>; };

template<int N> using index_tuple = typename make_index_impl<N>::type;

template <typename I, typename ...Args>
struct func_traits;

template <typename R, int ...I, typename ...Args>
struct func_traits<R, index_tuple_type<I...>, Args...> {
  template <typename TT, typename FT>
  static inline R call(TT &&t, FT &&f) {
    return f(std::get<I>(std::forward<TT>(t))...);
  }
};

template<
  typename …
Run Code Online (Sandbox Code Playgroud)

c++ templates c++11 stdtuple stdarray

3
推荐指数
1
解决办法
1182
查看次数

标签 统计

c++ ×1

c++11 ×1

stdarray ×1

stdtuple ×1

templates ×1