
Easing into Modern C++: A lightning talk for the unsure [video] - ScottWRobinson
https://www.youtube.com/watch?v=8wnj6M-jj9c
======
smilekzs
Video excerpt:

1\. When overriding methods, use `void Method() override;` instead of `virtual
void Method()`. (original video says use both `virtual` and `override` but
this is redundant as `override` implies `virtual`)

2\. Explicit type for enum: `enum MyEnum : uint32_t { ... };`. Does not
require `enum class`.

3\. Prefer `using NewType = OldType` to `typedef OldType NewType` (so that
it's obvious which type is your `NewType` --- not so much when function
pointers and arrays are involved in the `typedef` case).

4\. Struct/class member fields can have in-line default values: `struct A {
int x = 1; int y = 2; };`.

5\. Explicitly `delete` constructors and assign operators.

6\. Use `constexpr` functions to calculate compile-time constants instead of
macros.

7\. `explicit operator bool`

8\. `static_assert` is now standard (no more macro needed)

9\. `#include <chrono>` for type-safe time

~~~
electricslpnsld
No mention of smart pointers? I'd wager I use unique_ptr _way_ more than type-
safe time!

~~~
GuB-42
Because smart pointers are a different way to code. It is not a drop in
feature that makes your code better without any design change.

In all examples you can't really argue. All these things are common patterns
that require ugly hacks to work in traditional C++. Modern C++ made them the
way people would naturally write them, and they don't involve self imposed
restrictions or performance overheads.

The chrono stuff is a bonus, not included in the main 7, probably chosen
because of the author personal experience. But I understand that if you work
with code that involve a lot of timing, it can be a godsend. Time unit
mismatch can be incredibly frustrating, I've experienced it myself both as the
culprit and as a victim.

------
ur-whale
These are all good suggestions, but for me the three nicest features of modern
c++ are:

    
    
        - auto
        - lambdas
        - all the "inplace" construction stuff (*.emplace_back)
    

These _truly_ change the language and make it _way_ better.

The day C++ allows trailing commas in argument lists and gets rid of semi-
columns, my life will be complete ;)

~~~
je42
and \- range based for loop

\- deduction guides (C++17) (no more make_some_type)

\- structured bindings (C++17)

\- optional,variant (C++17)

~~~
ur-whale
> \- range based for loop

Oh yeah.

How could I not include this in the list <bangs head>

I use them _all_ the time.

------
SloopJon
These are the type of tips that would great in a new edition of _C++ Common
Knowledge_. _Effective Modern C++_ is great, but sometimes a little more in
depth than you need or want on a first reading.

------
eecsninja
Good stuff. Makes me wonder how many programmers still think of pre-C++11, and
all the tropes of what's wrong with the older form of the language, when they
opt for using other languages like Java. SMH.

