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
Hello,
On Sun, Mar 31, 2013 at 10:56 AM, Michael Powell
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
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; }); 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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Sun, Mar 31, 2013 at 12:08 PM, Will Mason
Hello,
On Sun, Mar 31, 2013 at 10:56 AM, Michael Powell
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
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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hello,
On Sun, Mar 31, 2013 at 12:20 PM, Michael Powell
On Sun, Mar 31, 2013 at 12:08 PM, Will Mason
wrote: Hello,
On Sun, Mar 31, 2013 at 10:56 AM, Michael Powell
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
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.
Also, it occurs to me that, depending on your personal stylistic preferences, you could do the following with about the same level of verbosity: for (auto val : all) std::cout << val->r() << std::endl; Cheers, Will
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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Sun, Mar 31, 2013 at 1:49 PM, Will Mason
Hello,
On Sun, Mar 31, 2013 at 12:20 PM, Michael Powell
wrote: On Sun, Mar 31, 2013 at 12:08 PM, Will Mason
wrote: Hello,
On Sun, Mar 31, 2013 at 10:56 AM, Michael Powell
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
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.
Also, it occurs to me that, depending on your personal stylistic preferences, you could do the following with about the same level of verbosity:
for (auto val : all) std::cout << val->r() << std::endl;
Or, for (rgb_type_pointer prgb : all) std::cout << prgb->r() << std::endl; Where, typedef rgb_type* rgb_type_pointer; Sourcery seems happy with that, or at least no syntax is highlighting. Cheers,
Will
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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Michael Powell
-
Will Mason