Page 1 of 1

Hoooooooly Shit (C++11)

Posted: Mon Jul 01, 2013 3:30 pm
by Falco Girgis
I just declared my first Lambda in ESTk... Feels surreal. :shock:

Re: Hoooooooly Shit (C++11)

Posted: Mon Jul 01, 2013 3:51 pm
by bbguimaraes
It does, doesn't it? It's incredible how such a simple (if you don't consider closures, of course) feature can change the way you look at a language.

Care to share some context? :mrgreen:

Re: Hoooooooly Shit (C++11)

Posted: Mon Jul 01, 2013 3:57 pm
by Falco Girgis
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

Re: Hoooooooly Shit (C++11)

Posted: Mon Jul 01, 2013 4:12 pm
by Nokurn
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
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.

Re: Hoooooooly Shit (C++11)

Posted: Mon Jul 01, 2013 4:29 pm
by Falco Girgis
Nokurn wrote:
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
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.
Yeah, I was not of the crowd who jumped for joy at "auto."

I actually don't think I'm going to start abusing the shit out of it everywhere... Especially in code chunks that have implicit conversions going on, I see this potentially resulting in a nightmare. 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... And let's not forget... "int" is shorter than "auto." :)

Move semantics definitely stood out to me as something that was a big deal. I would rank that, lambdas (and std::functions), and the incredibly powerful new things templates are capable of as being the best additions. I'm very much looking forward to the next time I need to create a complex template with C++11.

Re: Hoooooooly Shit (C++11)

Posted: Mon Jul 01, 2013 5:01 pm
by Nokurn
Falco Girgis wrote:Especially in code chunks that have implicit conversions going on, I see this potentially resulting in a nightmare.
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: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.

Re: Hoooooooly Shit (C++11)

Posted: Mon Jul 01, 2013 5:18 pm
by Falco Girgis
Nokurn wrote:
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.
:shock: ...good GOD.

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.

Re: Hoooooooly Shit (C++11)

Posted: Tue Jul 02, 2013 6:26 am
by bbguimaraes
I also appreciated the long-needed delete, override and default keywords for method declarations. It always seemed so wrong not to have them... These are the kind of features that are trivial to implement (most of the functionality is already there in the compiler), but make a huge difference for people working on the code.

Re: Hoooooooly Shit (C++11)

Posted: Mon Jul 08, 2013 10:09 am
by short
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.
I haven't seen this voodoo yet, you have an example you would like to share? :)

Re: Hoooooooly Shit (C++11)

Posted: Sun Jul 14, 2013 5:27 pm
by TheBuzzSaw
I still think C++ modules (proposed for C++14) will blow everything away. Move semantics are fantastic, but being able to dump #include would be too good.