SRL Archive - General

C++ and C++11


Gu3st...

2014-05-25 20:18:14

Some days ago I read on /r/programming on reddit about C++11 being worth taking another look at if one had already given up on C++ from before that version (but they didn't write why).

I did some googling myself, and found this page: http://www.stroustrup.com/C++11FAQ.html
Surprisingly, C++11 feels like a new language: The pieces just fit together better than they used to and I find a higher-level style of programming more natural than before and as efficient as ever.


I have no experience with C++ from beforehand and I'd like for people to tell me wherever or not it's worth taking a look at.

I'm basically looking for both pros and cons (about C++11 and C++ in general), but please keep from flaming or whatever when discussing.

tls

2014-05-25 20:59:14

My favorite new feature is auto. Compile time object typing.

Gu3st...

2014-05-25 21:03:45

From: tls
My favorite new feature is auto. Compile time object typing.
Is it generally looked down upon to use auto or doesn't it matter? I guess it's looked down upon when it's not clear what object it will become, but I'm not familiar enough to know if that ever happens or how auto even works

Sk1nyNerd

2014-05-25 21:05:50

@Brandon vs. @Wizzup?

Round 2

Fight!


e: lol jk, couldnt resist. neat document. didnt know there was so many types of c

tls

2014-05-25 21:09:46

Like most "looked down upon" practices, you have to use it in the right circumstances. It is just more useful/less dangerous now in C++11.

Kasi

2014-05-25 22:52:27

Def worth taking a look at. As you should with any language.

auto is pretty nice but but my favourite c++11/0x feature is lambdas'.

Brandon

2014-05-26 00:02:03

I like Lambdas too, however my favourite new feature is move construction. Java 8 recently got lambdas too which is nice.


Move construction is probably the most complicated feature by far and I don't fully understand ALL of it yet but I like it. Instead of having objects copied, they can be "moved". The downside is that if you do it wrong, it copies which is very bad in design and caught me off-guard when I was learning it. There's a lot of crap about it that is hidden too. For example: perfect forwarding (forwarding an object to a function directly).

Move construction allows you to construct objects directly in a contain without passing around pointers or anything like that. But again, it has nasty surprises and pitfalls if you don't know it very well. All in all, if you can do it right, it is the most efficient thing you'll ever learn in the language.

My second favourite feature is variadic templates: http://villavu.com/forum/showthread.php?t=82610


All in all, C++11 changes a lot of things but it still requires you know some of the old stuff sometimes.