Prev: ANN: Library dependency graphs tool status update and questions
Next: warning: ... has a field ... whose type uses the anonymous namespace
From: Boris Rasin on 13 Nov 2008 06:31 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 13 Nov 2008 23:09 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 16 Nov 2008 00:01 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 16 Nov 2008 14:27 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 17 Nov 2008 03:45
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! ] |