Page 1 of 1
I love C++11
Posted: Wed Nov 05, 2014 11:51 am
by kovarex
So we are just starting to use C++11 in the Factorio sources and I feel like I'v got new set of toys on christmas.
When things like this happen:
Before:
Code: Select all
std::vector<std::string> names;
names.push_back("stone-furnace");
names.push_back("straight-rail");
names.push_back("gate");
BOOST_FOREACH (const std::string& name, names)
After:
Code: Select all
for (const std::string& name: {"stone-furnace", "straight-rail", "gate"})
It makes me happy

Re: I love C++11
Posted: Wed Nov 05, 2014 12:38 pm
by Xecutor
Yeah, C++11 makes a lot of things much nicer to do.
However, overuse of 'auto' makes sources, while shorter, but harder to read.
Also, is you have proper class Rect with iterator, begin and end, you can write something like this:
Code: Select all
for(Pos pos:Rect(from,sz))
{
...
}
instead of
Code: Select all
Pos pos=from;
Pos till=from+sz;
for(;pos.y<till.y;++pos.y)
{
for(pos.x=from.x;pos.x<till.x;++pos.x)
{
...
}
}
Re: I love C++11
Posted: Wed Nov 05, 2014 12:55 pm
by kovarex
Yeah, I would like to avoid overusing auto, as it damages readability.
But in situations like:
Code: Select all
for (const boost::property_tree::ptree::value_type& item: input)
I feel it might be ok.
Also, using the auto for custom structures is also nice, you just need to provide begin/end methods, we use it for iterating of inventories already.
Re: I love C++11
Posted: Wed Nov 05, 2014 10:43 pm
by Nova
Yes, C++11 is very nice. It's so logical, so pure, so nice...

Did ask myself if you already use C++11, but the source code is closed source and i didn't want to ask such a small question because it would maybe annoy you.
Only getting the IDE to work with it was a pain...