Topic: Questions on the interaction of parameter packs within lambdas?


Author: SG <s.gesemann@gmail.com>
Date: Fri, 3 Apr 2009 10:52:53 CST
Raw View
On 27 Mrz., 05:45, Faisal Vali <fais...@gmail.com> wrote:
> Does anyone know how parameter packs interact with lambdas?
> For e.g how much of this is (or is intended to be) well-formed?
>
> template<class ...Args> void f(Args ... args)
> {
>    int g(Args...);
>    int g(Args& ...);
>
>    auto l1 = [=] { return g(args...); };
>    auto l2 = [&] { return g(args...); };
>    auto l3 = [&, args...] { return g(args...); };
> }

I'm not sure whether you have access to the local functions 'g' (you
probably have). Also, depending on the type parameters "Args" the
overloading of g might be ill-formed. But that would be a template
instantiation problem.

Apart from that, l1 and l2 should compile as far as I can tell.

It seems (according to the current draft, section 14.5.3 paragraph 4)
a pack expansion can't be part of a lambda capture clause. This is
probably an oversight and should be fixed, IMHO.

Cheers!
SG


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Faisal Vali <faisalv@gmail.com>
Date: Thu, 26 Mar 2009 21:45:25 CST
Raw View
Does anyone know how parameter packs interact with lambdas?

For e.g how much of this is (or is intended to be) well-formed?

template<class ...Args> void f(Args ... args)
{
   int g(Args...);
   int g(Args& ...);

   auto l1 = [=] { return g(args...); };  // default capture is by -
value
   auto l2 = [&] { return g(args...); };  // captured as reference -
now we can modify the elements in the original args
   auto l3 = [&, args...] { return g(args...); }; // is this allowed?

}

thanks,
Faisal Vali
Radiation Oncology
Loyola

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]