|
Boost Users : |
Subject: Re: [Boost-users] Converting a BOOST_FOREACH to use the new c++ 11 lambda syntax
From: Michael Caisse (mcaisse-lists_at_[hidden])
Date: 2013-01-01 13:53:03
On 01/01/2013 07:34 AM, Sean Farrow wrote:
> Hi Fokes:
>
> Im trying to convert a BOOST_FOREACH loop to use the new lambda syntax:
>
> I have a ptree variable declared in a class of which the foreach is
> part. I also have a vector<std::wstring> that I need to use within my
> lambda.
>
> This all being the case, the following is the original BOOST_FOREACH:
>
> BOOST_FOREACH(boost::property_tree::ptree::value_type &v, IniTree)
>
>
> IniSections.push_back(ConvertToWString(v.first));
>
> And the following is the converted lambda:
>
> std::for_each(IniTree.begin(), IniTree.end(), [&]
> (boost::property_tree::ptree::value_type &v)
>
> {
>
>
> IniSections.push_back(ConvertToWString(v.first));
>
> });
>
Hi Sean -
This will work fine. I personally prefer to be more selective in my
captures when it is so specific. Instead of the capture all by ref [&] I
might use [&IniSections].
michael
-- Michael Caisse ciere consulting ciere.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net