From: PGK on
Using variadic templates I can generalise the declaration of template
data members, so that something like this:

template <typename T1, typename T2, typename T3>
struct FooA {
T1 var1;
T2 var2;
T3 var3;
};

can, by the use of std::tuple, become:

template <typename ... Types>
struct FooB {
std::tuple<Types ...> vars;
};

but is it possible to do something similar for parameterised types;
such as std::vector? For example:

template <typename T1, typename T2, typename T3>
struct FooC {
std::vector<T1> var1;
std::vector<T2> var2;
std::vector<T3> var3;
};

Many thanks,
Graham

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Daniel Krügler on
On 3 Mrz., 21:35, PGK <graham.k...(a)gmail.com> wrote:
> Using variadic templates I can generalise the declaration of template
> data members, so that something like this:
>
> template <typename T1, typename T2, typename T3>
> struct FooA {
> T1 var1;
> T2 var2;
> T3 var3;
>
> };
>
> can, by the use of std::tuple, become:
>
> template <typename ... Types>
> struct FooB {
> std::tuple<Types ...> vars;
>
> };
>
> but is it possible to do something similar for parameterised types;
> such as std::vector? For example:
>
> template <typename T1, typename T2, typename T3>
> struct FooC {
> std::vector<T1> var1;
> std::vector<T2> var2;
> std::vector<T3> var3;
>
> };

What about:

template <typename ... Types>
struct FooD {
std::tuple<std::vector<Types> ...> vars;
};

?

HTH & Greetings from Bremen,

Daniel Kr�gler


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Anthony Williams on
PGK <graham.keir(a)gmail.com> writes:

> Using variadic templates I can generalise the declaration of template
> data members, so that something like this:
>
> template <typename T1, typename T2, typename T3>
> struct FooA {
> T1 var1;
> T2 var2;
> T3 var3;
> };
>
> can, by the use of std::tuple, become:
>
> template <typename ... Types>
> struct FooB {
> std::tuple<Types ...> vars;
> };
>
> but is it possible to do something similar for parameterised types;
> such as std::vector? For example:
>
> template <typename T1, typename T2, typename T3>
> struct FooC {
> std::vector<T1> var1;
> std::vector<T2> var2;
> std::vector<T3> var3;
> };

Something like:

template <typename ... Types>
struct FooD {
std::tuple<std::vector<Types> ...> vars;
};

should work.

Anthony
--
Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/
just::thread C++0x thread library http://www.stdthread.co.uk
Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]