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

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

by Scott Meyers
Effective Modern C++: 42 Specific Ways to Improve Your Use of C++11 and C++14

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

by Scott Meyers

eBook

$38.49  $50.99 Save 25% Current price is $38.49, Original price is $50.99. You Save 25%.

Available on Compatible NOOK Devices and the free NOOK Apps.
WANT A NOOK?  Explore Now

Related collections and offers


Overview

Coming to grips with C++11 and C++14 is more than a matter of familiarizing yourself with the features they introduce (e.g., auto type declarations, move semantics, lambda expressions, and concurrency support). The challenge is learning to use those features effectively—so that your software is correct, efficient, maintainable, and portable. That’s where this practical book comes in. It describes how to write truly great software using C++11 and C++14—i.e. using modern C++.

Topics include:

  • The pros and cons of braced initialization, noexcept specifications, perfect forwarding, and smart pointer make functions
  • The relationships among std::move, std::forward, rvalue references, and universal references
  • Techniques for writing clear, correct, effective lambda expressions
  • How std::atomic differs from volatile, how each should be used, and how they relate to C++'s concurrency API
  • How best practices in "old" C++ programming (i.e., C++98) require revision for software development in modern C++

Effective Modern C++ follows the proven guideline-based, example-driven format of Scott Meyers' earlier books, but covers entirely new material.

"After I learned the C++ basics, I then learned how to use C++ in production code from Meyer's series of Effective C++ books. Effective Modern C++ is the most important how-to book for advice on key guidelines, styles, and idioms to use modern C++ effectively and well. Don't own it yet? Buy this one. Now".

-- Herb Sutter, Chair of ISO C++ Standards Committee and C++ Software Architect at Microsoft


Product Details

ISBN-13: 9781491908426
Publisher: O'Reilly Media, Incorporated
Publication date: 11/11/2014
Sold by: Barnes & Noble
Format: eBook
Pages: 334
Sales rank: 417,195
File size: 3 MB

About the Author

For more than 20 years, Scott Meyers’ Effective C++ books (Effective C++, More Effective C++, and Effective STL) have set the bar for C++ programming guidance. His clear, engaging explanations of complex technical material have earned him a worldwide following, and they keep him in demand as a trainer, consultant, and conference presenter. Winner of the 2009 Dr. Dobb’s Excellence in Programming Award, he has a Ph.D. in Computer Science from Brown University. His web site is aristeia.com.

Table of Contents

From the Publisher xi

Acknowledgments xiii

Introduction 1

1 Deducing Types 9

Item 1 Understand template type deduction 9

Item 2 Understand auto type deduction 18

Item 3 Understand decltype 23

Item 4 Know how to view deduced types 30

2 auto 37

Item 5 Prefer auto to explicit type declarations 37

Item 6 Use the explicitly typed initializer idiom when auto deduces undesired types 43

3 Moving to Modern C++ 49

Item 7 Distinguish between () and {} when creating objects 49

Item 8 Prefer nullptr to 0 and NULL 58

Item 9 Prefer alias declarations to typedefs 63

Item 10 Prefer scoped enums to unscoped enuns 67

Item 11 Prefer deleted functions to private undefined ones 74

Item 12 Declare overriding functions override 79

Item 13 Prefer const_iterators to iterators 86

Item 14 Declare functions noexcept if they won't emit exceptions 90

Item 15 Use constexpr whenever possible 97

Item 16 Make const member functions thread safe 103

Item 17 Understand special member function generation 109

4 Smart Pointers 117

Item 18 Use std:: unique_ptr for exclusive-ownership resource management 118

Item 19 Use std::shared_ptr for shared-ownership resource management 125

Item 20 Use std::weak_ptr for std:: shared_ptr-like pointers that can dangle 134

Item 21 Prefer std::make_unique and std: :make_shared to direct use of new 139

Item 22 When using the Pimpl Idiom, define special member functions in the implementation file 147

5 Rvalue References, Move Semantics, and Perfect Forwarding 157

Item 23 Understand std::move and std: ;forward 158

Item 24 Distinguish universal references from rvalue references 164

Item 25 Use std::move on rvalue references, std::forward on universal references 168

Item 26 Avoid overloading on universal references 177

Item 27 Familiarize yourself with alternatives to overloading on universal references 184

Item 28 Understand reference collapsing 197

Item 29 Assume that move operations are not present, not cheap, and not used 203

Item 30 Familiarize yourself with perfect forwarding failure cases 207

6 Lambda Expressions 215

Item 31 Avoid default capture modes 216

Item 32 Use init capture to move objects into closures 224

Item 33 Use decltype on auto&& parameters to std::forward them 229

Item 34 Prefer lambdas to std::bind 232

7 The Concurrency API 241

Item 35 Prefer task-based programming to thread-based 241

Item 36 Specify std::launch::async if asynchronicity is essential 245

Item 37 Make std::threads unjoinable on all paths 250

Item 38 Be aware of varying thread handle destructor behavior 258

Item 39 Consider void futures for one-shot event communication 262

Item 40 Use std:: atonic for concurrency, volatile for special memory 271

8 Tweaks 281

Item 41 Consider pass by value for copyable parameters that are cheap to move and always copied 281

Item 42 Consider emplacement instead of insertion 292

Index 303

From the B&N Reads Blog

Customer Reviews