From: Boris Rasin on
I am thinking about possible implementation for a class to store
arbitrary number of objects of arbitrary types, just like tuple<>, but
with support for later (perfect) forwarding. As far as I understand,
the code in the simplified example below is not supported by c++0x. If
so, can someone explain why support for this case is not included in c+
+0x variadic templates? Is there an alternative implementation I am
missing?

template <class ... Args>
class store
{
public:

store (Args ... args) : members (args) ... {}
void forward() { some_func (members ...); }

Args ... members; // Error: template parameter pack expansion not
supported in this context. Why not?

};

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

From: Mathias Gaunard on
On 14 nov, 00:31, Boris Rasin <rasin.bo...(a)gmail.com> wrote:

> template <class ... Args>
> class store
> {
> public:
>
> store (Args ... args) : members (args) ... {}
> void forward() { some_func (members ...); }
>
> Args ... members; // Error: template parameter pack expansion not
> supported in this context. Why not?

What could it do?
Try tuple<Args...> members;


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

From: Boris Rasin on
On Nov 14, 6:09 pm, Mathias Gaunard <loufo...(a)gmail.com> wrote:
> On 14 nov, 00:31, Boris Rasin <rasin.bo...(a)gmail.com> wrote:
>
> > template <class ... Args>
> > class store
> > {
> > public:
>
> > store (Args ... args) : members (args) ... {}
> > void forward() { some_func (members ...); }
>
> > Args ... members; // Error: template parameter pack expansion not
> > supported in this context. Why not?
>
> What could it do?
> Try tuple<Args...> members;

{ clc++m banner removed; please don't quote it. -mod }

Like I said, I want (perfect) forwarding at a later stage (see
"forward" member function in my sample). And "tuple<Args...> members"
wouldn't work.


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

From: Mathias Gaunard on
On 16 nov, 18:01, Boris Rasin <rasin.bo...(a)gmail.com> wrote:

> Like I said, I want (perfect) forwarding at a later stage (see
> "forward" member function in my sample). And "tuple<Args...> members"
> wouldn't work.

And how so?
tuple can be your own type if std::tuple somehow doesn't suit your
needs.

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

From: Alberto Ganesh Barbati on
Boris Rasin ha scritto:
> On Nov 14, 6:09 pm, Mathias Gaunard <loufo...(a)gmail.com> wrote:
>> On 14 nov, 00:31, Boris Rasin <rasin.bo...(a)gmail.com> wrote:
>>
>>> template <class ... Args>
>>> class store
>>> {
>>> public:
>>> store (Args ... args) : members (args) ... {}
>>> void forward() { some_func (members ...); }
>>> Args ... members; // Error: template parameter pack expansion not
>>> supported in this context. Why not?
>> What could it do?
>> Try tuple<Args...> members;
>
> Like I said, I want (perfect) forwarding at a later stage (see
> "forward" member function in my sample). And "tuple<Args...> members"
> wouldn't work.
>

All you need is an helper function like this:

template <class T, class... Args>
/* whatever */ invoke(T f, tuple<Args...>&& args);

which calls f with the supplied arguments. It should not be too
difficult to make it a perfect forwarder.

Ganesh

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