Boost logo

Boost Users :

Subject: [Boost-users] Problems using for_each
From: Michael Powell (mwpowellhtx_at_[hidden])
Date: 2013-03-31 12:56:24


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);

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 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