MichaelšŸ˜¼Cornelius is a user on octodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
MichaelšŸ˜¼Cornelius @emdeesee

C++ devs (yes, all three of you):

Which features of "modern" C++, that is C++11 and newer, are most valuable to you?

Ā· Web Ā· 1 Ā· 5

Note: I'm planning a presentation on "modern" C++ features for an audience of programmers generally familiar with C++ as "c with classes", and I'm looking for some fresh perspectives.

@emdeesee I haven't done C++ since 2007, so I guess I'm in your target audience. OTOH I don't plan to do any more C++ if I can avoid it :)

@emdeesee I'm trying to imagine that... It's hard :) are they actual closures? Doesn't that make memory management a lot more painful?

@plexus lambdas living beyond the scope of captured objects is the big pitfall, yeah.

@plexus They're really nice though when you need a small, pure function to pass to, e.g., and standard library template or similar, and using them to make closures (with care and when appropriate) is nice.

I've used them to eliminate global state by replacing a static function which referenced a global with a lambda that closes over a local instead, and carries the value down the stack.

move semantics, auto, for(:) and lambdas (always have to remind me to use them) are nice

@emdeesee actually, "c with classes" and c++11+ today seem to me more like two different langs.
but now i am a bit curious about your presi.

@XOR I agree with that: that c++89 and c++11+ are remarkably different semantically, while at least superficially similar syntactically.

@emdeesee ofc, a method is a method, a struct is a struct and a while is a while.
but for exmpl. the "avoid new/delete" paradigma is quite radical.

@XOR This particular group has had "prefer RAII and stack-based objects to manual memory management" as standard operating procedure for a while, though adherence is not always perfect.

It seems like both C and Java programmers coming to C++ want to new/delete everything. And when asked why, the answer is often, "Oh, I thought you had to in C++."

@emdeesee improved C99 compatibility, lambda functions, nullptr, explicit conversion interest me the most but I'm stuck in like C++98/03 most of the time

@emdeesee shared_ptr is handy if you're not using some other smart-pointer implementation.

Lamda's look fun too, but I keep forgetting that they exist.

@apLundell Initial responses to this question suggest that lambdas are frequently overlooked, which is interesting.

@emdeesee Problem solved.

I'm going to leave that there until my project has lambda statements in it.

Don't forget `this` to capture the enclosing object as a capture list option. šŸ˜

@emdeesee I also enjoy irritating coworkers with the alternative operators like "and" instead of "&&".
I think those came in with C++98, though.

(I sometimes use the "not" operator non-ironically, because I like using tiny fonts where ! is easy to miss when you're skimming code.)

@apLundell Part of the point of the presentation is to minimize the annoyance of colleagues by gently introducing them to features that are already in use by other colleagues. šŸ˜

@apLundell @emdeesee
thou shalt not irritate ppl with thy code.
thy code shalt be as clear as water

@XOR @apLundell Sometimes it irritates people to be dragged, kicking and screaming, into the present.

@emdeesee @apLundell si, a difficult process. therefore it has to be done very carefully and very well.

@emdeesee I did some searching before answering this question and I found some useful and not so useful items that were unfamiliar.

std::iota is in the "less useful" category (fill a range with x, ++x, ++(++x), etc)

std::minmax and std::minmax_iter look useful. So do the initializer_list versions of min and max, for when you want to min/max more than 2 items.

of course you have standard unordered containers now.

move and emplace and the "&&" type qualifier will cross more than a few eyes.

@stylus I guess I need to read up on std::minmax and std::minmax_iter.

If std::iota were lazy, though ... ooooh. Overload ++ and you're starting to have thing. I just got goosebumps.

As a 'used to write C with classes' programmer, I've learned to really appreciate:

auto (variables, function returns),
smart pointers,
initializer lists,

Much much more!

@samathy Thanks! It's beginning to look like `auto`, range-based `for`, and lambdas are likely to be the focus of this presentation.

@emdeesee I'd be interested to see the resulting talk - where are you speaking?

@samathy At $DAY_JOB, but if I can liberate the presentation, I will do so. Or maybe I'll put together two versions, since "motivated and encumbered by IP restrictions examples" will probably be required.

@emdeesee Lambdas, auto, constexpr, uniform initialization, override, nullptr, default/delete (for constructors, etc) . Using all those day-in, day-out!

@emdeesee I'm eagerly awaiting std::optional support in compilers. other than that, lambdas and the std algorithms probably