8

I would like to instantiate a class like

template<typename ...Args>
class X {
private:
    std::tuple<std::array<Arg0, 255>, std::array<Arg1, 255>, ...> m_tuples; // For Arg in Args
}

I know this is not correct C++, but how could I achieve the effect of expanding the parameter pack template of the class to the arrays held within the tuple?

shane
  • 1,742
  • 2
  • 19
  • 36

1 Answers1

11
template<typename ...Args>
class X {
private:
    std::tuple<std::array<Args, 255>...> m_tuples; // For Arg in Args
};

... you didn't expect to be so close, did you :)

Quentin
  • 62,093
  • 7
  • 131
  • 191
  • I did not! Can you explain how this expansion works? I am stuck thinking about this as I would recursive function calls, popping off the first element of the parameter pack. – shane Dec 07 '16 at 22:06
  • @shane The rules are a bit fuzzy for me, but in short pack expansion works by duplicating a (syntactic) pattern and replacing the argument packs within this pattern. Here the pattern is the whole `std::array`, which gets expanded to what you are after by replacing `Args`. – Quentin Dec 07 '16 at 22:12
  • 2
    @shane See http://stackoverflow.com/questions/17652412/what-are-the-rules-for-the-token-in-the-context-of-variadic-templates. – Ralph Tandetzky Dec 08 '16 at 07:11