On 01/09/2013 03:53, Matthew Brush wrote:
On 13-08-31 07:42 PM, Lex Trotman wrote:
Just for fun I wrote some theoretical code that could be used in a program like Geany to compare styles between various C's and C++'s (note: none of it tested).
http://pastebin.geany.org/**gYFMO/ http://pastebin.geany.org/gYFMO/
As discussed on IRC here's another way of doing the C++98/03, marked with +es. http://pastebin.geany.org/AzbMV/
Or alternatively in c++11 :)
for_each(begin(App::instance().windows()), end(App::instance().windows()), [] (Window &win) { for_each(begin(win.documents()), end(win.documents(), [] (Document &doc) { // do stuff with each document } ); } );
Still somewhat noisy IMO. How about this, C++98 (I think):
#include <boost/foreach.hpp> #define FOREACH BOOST_FOREACH
FOREACH(Document &doc, win.documents()) { // do stuff with each document }
See: http://www.boost.org/doc/libs/1_54_0/doc/html/foreach.html
"BOOST_FOREACH is designed for ease-of-use and efficiency. It does no dynamic allocations, makes no virtual function calls or calls through function pointers, and makes no calls that are not transparent to the compiler's optimizer. This results in near-optimal code generation; the performance of BOOST_FOREACH is usually within a few percent of the equivalent hand-coded loop. And although BOOST_FOREACH is a macro, it is a remarkably well-behaved one. It evaluates its arguments exactly once, leading to no nasty surprises."