|
Boost Users : |
Subject: Re: [Boost-users] Problems using for_each
From: Michael Powell (mwpowellhtx_at_[hidden])
Date: 2013-03-31 14:20:59
On Sun, Mar 31, 2013 at 12:08 PM, Will Mason <willchido_at_[hidden]> wrote:
> Hello,
>
>
> On Sun, Mar 31, 2013 at 10:56 AM, Michael Powell <mwpowellhtx_at_[hidden]>
> wrote:
>>
>> Hello,
>>
>> I am struggling making for_each work right. I am using Sourcery
>> targeting ARM. AFAIK, GCC is actually 4.7.2, and I am flagging
>> -std=c++11.
>>
>> I'm not really picky how we get for_each done (or constructs like it).
>> I'd like to avoid "macro-expansion" for obvious reasons (i.e. debug),
>> and the always-infamous verbosity of a for loop, if possible.
>>
>> I've got the following:
>>
>> vector<rgb_type*> all;
>> rgb_type rgb;
>> rgb_type rgb2 = rgb.clone();
>>
>> for_each(all.begin(), all.end(), cout << _1->r() << endl);
>
>
> Since you are using gcc 4.7.2 with -std=c++11, you can just use a std lambda
> here:
>
> std::for_each(all.begin(), all.end(), [] (rgb_type* val) { std::cout << val->r() << std::endl; });
Yessir, I believe that will work. Possibly also std::bind as needs be.
A little refresher for me, []: return value (void implied), ():
captured function args (with in/out/inout rules), {}: lambda body.
I think what I am also finding is Sourcery code highlighting,
so-called "Semantic Errors" isn't quite in alignment with current C++
language standards.
Thank ye.
> Cheers,
> Will
>
>
>>
>>
>> With errors:
>>
>> _1 was not declared in this scope. (C++ Problem)
>>
>> That or,
>>
>> void rgb_printer_func(rgb_type* prgb) {
>> cout << prgb->r() << endl;
>> }
>>
>> for_each(all.begin(), all.end(), rgb_printer_func);
>>
>> With errors:
>>
>> Invalid arguments Candidates are: #1 for_each(#0, #0, #1) (Semantic Error)
>>
>> Thank you.
>>
>> Regards,
>>
>> Michael Powell
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
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