-2

Perhaps I being naive here, but I believe the following code should compile:

template <typename ... T>
struct Test {
        std::tuple<T> foo;
};

int main() {
        struct Test<int, long> test;

        return 0;
}

Instead g++ complains:

test.cpp:5: error: parameter packs not expanded with '...':
test.cpp:5: note:         'T'

What am I missing?

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
R.D.
  • 2,471
  • 2
  • 15
  • 21
  • Please do some [basic research about a feature](http://en.cppreference.com/w/cpp/language/parameter_pack) before asking about it on SO. It's not like the information isn't out there. – Nicol Bolas Dec 10 '15 at 01:12
  • I did, I kept hitting this thread http://stackoverflow.com/questions/14033828/translating-a-stdtuple-into-a-template-parameter-pack which wasn't helpful. – R.D. Dec 10 '15 at 01:13
  • Did you try Google? A simple "C++ use variadic template" search would have found you tons of resources. – Nicol Bolas Dec 10 '15 at 01:15

1 Answers1

1

You do that by expanding the pack with ...:

template <typename... T>
struct Test
{
    std::tuple<T...> foo;
    //         ^^^^
};
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • This did it! Would the same trick work when passing it as a argument? For example the constructor `Test(T...t) : foo(std::make_tuple(t)) {};` gives me a similar error – R.D. Dec 10 '15 at 01:04
  • To answer my own question, need to do `t...` in the argument to `make_tuple`. – R.D. Dec 10 '15 at 01:05