, , ... , std::integer_sequence call() .
- , , , , .
struct foo
{
template <int ... vals>
void call () const
{ std::cout << "- call " << sizeof...(vals) << std::endl; }
};
template <typename IS>
void RecursiveFunct (IS const &)
{ }
template <typename T, int ... vals>
void wrapCall (T const & t, std::integer_sequence<int, vals...> const &)
{ t.template call<vals...>(); }
template<typename IS, typename T, typename ... Args>
void RecursiveFunct (IS const & is, T t, Args... args)
{
wrapCall(t, is);
RecursiveFunct(is, args...);
}
int main ()
{
RecursiveFunct(std::integer_sequence<int, 2, 3, 5, 7>{},
foo{}, foo{}, foo{}, foo{}, foo{});
}
, std::integer_sequence - ++ 14, ( ) ++ 14.
++ 11, std::integer_sequence.
template <typename T, T ... ts>
struct myIntegerSequence
{ };
- EDIT -
OP
integer_sequence?
++ 14, . Cuda? .
wrapCall() wrapCall struct func(). , , funcs.
#include <utility>
#include <iostream>
struct foo
{
template <int ... vals>
void call () const
{ std::cout << "- call " << sizeof...(vals) << std::endl; }
};
template <typename>
void RecursiveFunct ()
{ }
template <typename>
struct wrapCall;
template <int ... vals>
struct wrapCall<std::integer_sequence<int, vals...>>
{
template <typename T>
static constexpr void func (T const & t)
{ t.template call<vals...>(); }
};
template<typename IS, typename T, typename ... Args>
void RecursiveFunct (T t, Args... args)
{
wrapCall<IS>::func(t);
RecursiveFunct<IS>(args...);
}
int main ()
{
RecursiveFunct<std::integer_sequence<int, 2, 3, 5, 7>>
(foo{}, foo{}, foo{}, foo{}, foo{});
}
, std::integer_sequence?