Hoooooooly Shit (C++11)
Moderator: Coders of Rage
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Hoooooooly Shit (C++11)
I just declared my first Lambda in ESTk... Feels surreal.
- bbguimaraes
- Chaos Rift Junior
- Posts: 294
- Joined: Wed Apr 11, 2012 4:34 pm
- Programming Language of Choice: c++
- Location: Brazil
- Contact:
Re: Hoooooooly Shit (C++11)
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?
Care to share some context?
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Hoooooooly Shit (C++11)
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
- Nokurn
- Chaos Rift Regular
- Posts: 164
- Joined: Mon Jan 31, 2011 12:08 pm
- Favorite Gaming Platforms: PC, SNES, Dreamcast, PS2, N64
- Programming Language of Choice: Proper C++
- Location: Southern California
- Contact:
Re: Hoooooooly Shit (C++11)
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
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Hoooooooly Shit (C++11)
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
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.
- Nokurn
- Chaos Rift Regular
- Posts: 164
- Joined: Mon Jan 31, 2011 12:08 pm
- Favorite Gaming Platforms: PC, SNES, Dreamcast, PS2, N64
- Programming Language of Choice: Proper C++
- Location: Southern California
- Contact:
Re: Hoooooooly Shit (C++11)
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.
Last edited by Nokurn on Mon Jul 01, 2013 5:34 pm, edited 1 time in total.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Hoooooooly Shit (C++11)
...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.
- bbguimaraes
- Chaos Rift Junior
- Posts: 294
- Joined: Wed Apr 11, 2012 4:34 pm
- Programming Language of Choice: c++
- Location: Brazil
- Contact:
Re: Hoooooooly Shit (C++11)
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.
- short
- ES Beta Backer
- Posts: 548
- Joined: Thu Apr 30, 2009 2:22 am
- Current Project: c++, c
- Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
- Programming Language of Choice: c, c++
- Location: Oregon, US
Re: Hoooooooly Shit (C++11)
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.
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
link: https://github.com/bjadamson
- TheBuzzSaw
- Chaos Rift Junior
- Posts: 310
- Joined: Wed Dec 02, 2009 3:55 pm
- Current Project: Paroxysm
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Contact:
Re: Hoooooooly Shit (C++11)
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.