Effective C++11

Скотт Майерс выложил предварительное содержание будущей книги Effective C++11. Мне нравится, по большому счету, чтение самого содержания + немного размышлений довольно хорошо помогает понять C++11.

Moving from C++98 to C++11

  • Prefer auto to explicit type declarations.
  • Remember that auto + { expr } ⇒ std::initializer_list.
  • Prefer nullptr to 0 and NULL.
  • Prefer enum classes to enums.
  • Prefer alias templates to typedefs.
  • Declare overriding functions override.
  • Distinguish () and {} when creating objects.
  • Prefer emplacement to insertion.
  • Declare functions noexcept whenever possible.
  • Make const member functions thread-safe.
  • Avoid std::enable_if in function signatures.
  • Handle iterators where copying means moving.

Rvalue References, Move Semantics, and Perfect Forwarding

  • Distinguish universal references from rvalue references.
  • Avoid overloading on universal references.
  • Pass and return rvalue references via std::move, universal references via std::forward.
  • Assume that move operations are not present, not cheap, and not used.
  • Be aware of perfect forwarding failure cases.
  • Understand reference collapsing.

Secrets of the C++11 Threading API

  • Thread construction may throw.
  • Destroying a joinable thread calls terminate.
  • Arguments passed to std::thread, std::async, and std::call_once are unconditionally copied.
  • std::async is really two different functions with somewhat different APIs.
  • Futures from std::async are special.
  • void futures can be used for interthread communication.
  • To poll a future, use wait_for with a zero timeout.
  • Native handles let you go beyond the C++11 API.
  • Clock adjustments affect _until functions.

Lambda Expressions

  • Prefer lambdas to std::bind.
  • Prefer lambdas to variadic arguments for threading functions
  • Beware default captures in member functions.

Smart Pointers

  • Use std::make_shared whenever possible.
  • Prefer pass-by-ref-to-const to pass-by-value for std::shared_ptrs.


  • Pass by value when you’ll copy your parameter.
  • Keep abreast of standardization developments.

2 Comments Effective C++11

  1. breee breee

    > Avoid std::enable_if in function signatures

    Замечательно. Ввели новую плюшку и теперь пишут книги о том, что ее нужно избегать

    1. Alexander Stavonin

      Так тут речь не о том, что бы избегать плюшки полностью, а о том, что бы избегать использования плюшки в определенной ситуации. Мне кажется, это несколько разные вещи.


Leave a Reply