Effective Modern C++

42 Specific Ways to Improve Your Use of C++11 and C++14

Vanand Gasparyan
Computer Science Reader
3 min readOct 5, 2019

--

C++11/14 was a major update over the previous C++98. This book sheds light on it in a classic, Scott Meyers way. Amazon link to the book.

The first chapter, Deducing Types, consists of four items that prepare a good ground for understanding the 2nd and 5th chapters about auto and move semantics, respectively.

The second chapter goes deeper into the auto, suggesting when to and not to use it. After C++17 there are even more ways and places to use auto, and if you think “… that’s fine, I’ll just wait for the next book from Meyers, Effective Moderner C++…”, don’t get your hopes high.

The third chapter, Moving to Modern C++, is the biggest chapter full of classic Meyers items, mostly about the new features of the language.

The fourth chapter is about the new Smart Pointers. For those who had used smart pointers, this chapter won’t be a discovery. As for others, if you had to use auto_ptr, I’m sorry for you. But good news, it’s over. Happy reading this chapter. And of course, it’s important and helpful for those who are completely new to the smart pointers.

The fifth chapter, Rvalue References, Move semantics and Perfect Forwarding, is of the highest importance. This has become one of the cornerstones of the language. You can’t choose whether or not to use it: it’s inevitable. Once you’re done with this chapter, try to answer the following questions:

  • What is move semantics? (Hint: most of the answers start like “Move semantics is… ehm… for example, you have a class…”. This is not an answer, don’t do that.
  • When do I implement a move constructor/assignment and/or copy constructor/assignment?
  • When do I implement a move constructor/assignment only? What such classes are there in STL?
  • What is considered a valid move constructor/assignment? Write a move for this class:
class VecOfInts
{
private:
int* m_data;
int m_size;
int m_capacity;
public:
VecOfInts(VecOfInts&& rhs)
{
// your implementation here
}
VecOfInts& operator=(VecOfInts&& rhs)
{
// your implementation here
}
};

Be careful what you do with ‘rhs’.

These are the questions you must answer before going to an interview. There might also be questions about forwarding, which this chapter dives very deep into.

The next sixth chapter is about Lambda Expressions. This new feature will require some practice to get used to: it’s a new syntax. It’s just a syntactic sugar though, a faster and nicer way to define and instantiate functors. Frequent STL users will love it.

The seventh chapter is about The Concurrency API. No doubt this was a huge addition to the language. This chapter is especially helpful for people who’ve done concurrency in C++ before, with external libraries, people who know the theory behind the concurrency and multithreading. If you’re not one of them, I’d highly suggest reading at least the first chapter of this other book and get back to this.

Finally, the last small chapter called Tweaks comprises two items only, the last two tips from Meyers.

Yes, you read it right, no more C++ books from him. On Dec 31, 2015, he wrote:

So consider me gone. 25 years after publication of my first academic papers involving C++, I’m retiring from active involvement with the language. — Scott Meyers

The original post can be found here.

So, go read all his books, buckle up with that knowledge, and prepare for the new journey through the C++20.

Final score

Useful for programmers: 10/10

Relevance: 10/10

Real-world examples: 10/10

Detailed and friendly: 10/10

Worth buying: 10/10

--

--