Quantcast
Channel: Intel® C++-Compiler
Viewing all articles
Browse latest Browse all 1665

trouble with tuple

$
0
0

I consider myself a noob with regards to variadic template programming.

In the std there is the template tuple. In which you can create the tuple with any number of and mixture of type. This is quite handy (except for the reversed order which is a minor annoyance).

The problem I am trying to work out is in accessing programmicly tuple entries. Pseudo code:

template<typename... T>
inline // avoid duplicate symbols
void qt_unwrap_fn_args(std::tuple<void(*) (T...), T...>* t)
{
  auto fn = std::get<0>(t);
  // now call the enclosed functor with a variable number of args
  // 4 args directly would be this way:
  fn(
    std::get<1>(t),
    std::get<2>(t),
    std::get<3>(t),
    std::get<4>(t)
  );
// but i'd prefer to do it with ... expansion
// due to the fact that the arguments vary in number
// I am having difficulty in figuring out how to have the template expansion generate the
// correct number of arguments together with literal get number
  fn(
    std::get<T sequence number + 1>(t)... // expands to std::get<1>(t),..., std::get<4>(t)
  );
}

As an unrelated issue the above sketch shows obtaining the functor via std::get<0)(t), on my system V16.0 update 2 this does not return the first arg (last in memory). I have to retype case t, and then extract the functor that way. I will leave this issue for another day.

The object of the code is to convert a packet (POD) into a function call together with arguments.

 Jim Dempsey


Viewing all articles
Browse latest Browse all 1665

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>