ecst icon indicating copy to clipboard operation
ecst copied to clipboard

Passing a tuple of systems to execute_systems() instead of a variadic param pack

Open bjadamson opened this issue 8 years ago • 1 comments

Hey, I got a quick question for you. I've been doing some meta programming in my game lately, and I would like to group my list of "systems" into a tuple (so I can pass it around) and then later pass that tuple to the execute_systems() function located here:

https://github.com/SuperV1234/ecst/blob/master/include/ecst/context/data/step/step.hpp#L33-L34

This doesn't work currently because I don't see a straight-forward way to destructure my std::tuple (actually I'm using hana::tuple but it's the same problem) back into a list of variadic arguments to pass to:

template <typename... TStartSystemTags>
auto execute_systems_from(TStartSystemTags... sts) noexcept;

Here's the diff of what I was thinking of as an approach: https://github.com/bjadamson/ecst/commit/c308eea6ff897d557c53f90a8373ce26d5194d7c

Questions, do you already support this and I don't see it? Does this seem like something that seems like a good idea to support? How would you go about supporting this if you were the one implementing this? (I'm asking because I assume I'll have more time to work on it in the very near future, but my approach seems flawed).

Thanks as always!

bjadamson avatar Dec 23 '16 19:12 bjadamson

This doesn't work currently because I don't see a straight-forward way to destructure my std::tuple (actually I'm using hana::tuple but it's the same problem) back into a list of variadic arguments

I think you're looking for boost::hana::unpack or std::experimental::apply:

auto sum = [](auto... xs)
{
    return (0 + ... + xs);  
};

auto x = boost::hana::make_tuple(1, 2, 3);

assert(boost::hana::unpack(x, sum) == 1 + 2 + 3);

Here's a working example on Wandbox.

Let me know if this helps :)

vittorioromeo avatar Dec 24 '16 17:12 vittorioromeo