Hoooooooly Shit (C++11)
Posted: Mon Jul 01, 2013 3:30 pm
I just declared my first Lambda in ESTk... Feels surreal.
The Next Generation of 2D Roleplaying Games
http://elysianshadows.com/phpBB3/
Move semantics are probably one of the most important features of C++11, yet they are regularly overshadowed by more flashy things like auto. Most of the improvements are aimed at usability, but move semantics offer real performance improvements. One of my major complaints with languages like C# was how difficult it is to copy an object, but move semantics in C++ are slowly convincing me that it is actually (relatively) rare for copying to be the correct thing to do.Falco Girgis wrote:Actually, right now I'm adding move semantics to my selection datatypes (which handles tiles in ESTk, images in SheetManager), which need to be copied and returned by value liberally within the TileEngine's internal template implementation. Time to make shit less expensive. :D
Yeah, I was not of the crowd who jumped for joy at "auto."Nokurn wrote:Move semantics are probably one of the most important features of C++11, yet they are regularly overshadowed by more flashy things like auto. Most of the improvements are aimed at usability, but move semantics offer real performance improvements. One of my major complaints with languages like C# was how difficult it is to copy an object, but move semantics in C++ are slowly convincing me that it is actually (relatively) rare for copying to be the correct thing to do.Falco Girgis wrote:Actually, right now I'm adding move semantics to my selection datatypes (which handles tiles in ESTk, images in SheetManager), which need to be copied and returned by value liberally within the TileEngine's internal template implementation. Time to make shit less expensive. :D
The 'explicit' keyword for constructors and conversion operators helps with this. I've taken to marking nearly all constructors, aside from default/copy/move constructors, as explicit. This really makes it hard to avoid accidentally making a bad conversion.Falco Girgis wrote:Especially in code chunks that have implicit conversions going on, I see this potentially resulting in a nightmare.
Falco Girgis wrote:The biggest benefits of this come from long variable declarations for template and iterator types and compile-type type-deduction for return values within templates.
template<typename T1, typename T2> auto sum(const T1& a, const T2& b) -> decltype(a + b) { return a + b; }auto is definitely strongest when combined with templates! However, this won't be necessary come C++14: N3638, N3649.
...good GOD.
I haven't seen this voodoo yet, you have an example you would like to share?Falco Girgis wrote:
I must admit, one of my favorite things about non-closure lambdas is their compatibility with standard C function pointers. As someone who interops with strict C code fairly regularly, I think it's badass to be able to pull a lambda out of my ass and pass it off to a C lib as a callback.