Modern C++ Combo:
Moving Up to Modern C++
and
Effective Modern C++
A 4- or 5-Day Course by Leor Zolman and Scott Meyers
Synopsis:
This offering combines Leor Zolman's Moving Up to Modern C++, an overview of the new features of C++11/14/17, with a selection of items from Scott Meyers' Effective Modern C++, a course based on his book of the same name.
Taken together, the two segments of the course provide a strong grounding in Modern C++ fundamentals, along with some deep dives to explore new idioms and best practices that have evolved during the first half-decade of Modern C++'s general availability to developers.
Prerequisites:
Attendees should have prior programming experience with C++98 / C++03.
Contents (4-Day Version
From Moving Up to Modern C++:
- C++ Timeline
- Goals for C++11
- Part I: The Simpler Core Language Features
- auto, decltype, trailing return type
- non-member begin/end (and variations)
- nullptr
- Generalized function return type deduction
- auto vs. decltype(auto)
- Range-based for loop
- >> in template specializations
- static_assert
- noexcept
- extern template
- Variadic templates
- constexpr functions in C++11 and C++14
- constexpr data
- Template alias
- C++14 variable templates
- Unicode and raw string literals
- Inline namespaces
- Attributes
- Fixed-width integer types
- Scoped enums
- Generalized unions and PODs
- Other misc. features
- Part II: Features Specific to Class Design
- Generated functions: =default / =delete
- Override control: override / final
- Delegating constructors
- Inheriting constructors
- Increased flexibility for in-class initializers
- New rules for static data members
- Explicit conversion operators
- Reference-qualified member functions
- Part III: Larger Language Features
- Initialization
- Initializer lists
- Uniform initialization
- Prevention of narrowing
- Lambdas
- Capture modes
- Lambdas as "local functions"
- C++14 generic lambdas
- Move semantics
- The meanings of 'lvalue' and 'rvalue'
- rvalue references
- The move operations
- Universal References
- Reference collapsing
- Perfect forwarding
- The Rule of 5
- C++14 generalized lambda capture
- Part IV: Concurrency
- Threads
- Passing arguments to threads
- Data lifetime considerations
- Synchronization with mutexes and locking
- Acquiring multiple locks
- mutex types
- Returning values from threads using futures and async
- Launch policies
- Querying future status
- Condition variables
- Thread-local storage
- Atomics
- Part V: New Library Components
- std::tuple
- New Function/Function Object Facilities
- Smart Pointers
- std::unique_ptr
- std::shared_ptr
- std::make_shared/std::make_unique
- Fixed-length Array
- Hash-based Containers
- Performance enhancements
- Online Resources
(From Effective Modern C++):
- Moving to Modern C++
- Prefer
auto
to explicit types when declaring objects.
- Remember that
auto
+ { expr }
⇒ std::initializer_list
.
- Distinguish
()
and {}
when creating objects.
- Prefer
nullptr
to 0
and NULL
.
- Prefer scoped enums to unscoped enums.
- Prefer deleted functions to private undefined ones.
- Declare overriding functions
override
.
- Declare functions
noexcept
if they won’t emit exceptions.
- Use
constexpr
whenever possible.
- Make
const
member functions thread-safe.
- Smart Pointers
- Use
std::unique_ptr
for exclusive-ownership resource management.
- Use
std::shared_ptr
for shared-ownership resource management.
- Prefer
std::make_unique
and std::make_shared
to direct use of new
.
- The Concurrency API
- Make
std::thread
s unjoinable on all paths.
- Use
std::launch::async
with std::async
if asynchronicity is essential.
- Be aware of varying thread handle destructor behavior.
- Create tasks, not threads.
- Consider
void
futures for one-shot event communication
- Miscellaneous
- Consider emplacement instead of insertion.
Format:
Four day option: Lecture and Q/A/Discussion, with 1.5 days devoted to the overview module and 2.5 days to the best practices module.
Five day option: Lecture, Q/A/Discussion and several short exercises (during the overview module). 2 days are devoted to the overview, and 3 days to best practices.
Length:
4-5 full days