Hoooooooly Shit (C++11)

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Falco Girgis
Elysian Shadows Team
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)

Post by Falco Girgis »

I just declared my first Lambda in ESTk... Feels surreal. :shock:
User avatar
bbguimaraes
Chaos Rift Junior
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)

Post 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:
User avatar
Falco Girgis
Elysian Shadows Team
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)

Post 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
User avatar
Nokurn
Chaos Rift Regular
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)

Post 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.
User avatar
Falco Girgis
Elysian Shadows Team
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)

Post 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.
User avatar
Nokurn
Chaos Rift Regular
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)

Post 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.
Last edited by Nokurn on Mon Jul 01, 2013 5:34 pm, edited 1 time in total.
User avatar
Falco Girgis
Elysian Shadows Team
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)

Post 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.
User avatar
bbguimaraes
Chaos Rift Junior
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)

Post 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.
User avatar
short
ES Beta Backer
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)

Post 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? :)
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
TheBuzzSaw
Chaos Rift Junior
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)

Post 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.
Post Reply