effective modern c++
Learn how to program expertly with C++ with this practical book from Scott Meyers, one of the world's foremost authorities on this systems programming language. Scott Meyers takes some of the most difficult pieces of C++ code and unfurls them so that you can see how to manipulate your own project coPraise for effective modern cttSo, still interested in C++? You should be! Modern C++(i.e, C++11/C++14)is far more than just a facelift Considering the new features, it seems that it'smore a reinvention. Looking for guidelines and assistance? Then this bookis surely what you are looking for Concerning C++, Scott Meyers wasand still is a synonym for accuracy, quality, and delightGerhard KreuzerResearch and Development Engineer, Siemens AGFinding utmost expertise is hard enough. Finding teaching perfectionisman authors obsession with strategizing and streamlining explanations -is also difficultYou know you re in for a treat when you get to find both embodied in the same personEffective Modern C++ is a towering achievement from a consummate technical writer.It layers lucid, meaningful, and well-sequenced clarifications on top of complex andnterconnected topics, all in crisp literary style. You're equally unlikely to findtechnical mistake, a dull moment, or a lazy sentence in Effective Modern C++Andrei alexandrescuPh. D, Research Scientist, Facebook, and author of Modern C++ designAs someone with over two decades of C++ experience, to get the most out ofmodern C++(both best practices and pitfalls to avoid), I highly recommendgetting this book, reading it thoroughly, and referring to it oftenI've certainly learned new things going through itNevin liberSenior Software Engineer, DRW Trading GroupBjarne Stroustrup-the creator of C++-said,C++1l feels like a new languageEffective Modern C++ makes us share this same feeling by clearly explaininghow everyday programmers can benefit from new features and idiomsof C++ll and C++14. Another great Scott Meyers bookCassio nerFX Quantitative Analyst, Lloyds Banking GroupScott has the knack of boiling technical complexity down to an understandable kernelHis Effective C++ books helped to raise the coding style of a previous generation of C++programmers; the new book seems positioned to do the same for those using modern c++Roger orrOR/2 Limited, a member of the iso c++ standards committeeEffective Modern C++ is a great tool to improve your modern C++ skills. Not only does itteach you how when and where to use modern C++ and be effective, it also explains whlyWithout doubt, Scott's clear and insightful writing, spread over 42 well-thought items,gives programmers a much better understanding of the language-Bart vandewoestyneResearch and Development Engineer and C++ enthusiastI love C++, it has been my work vehicle for many decades now. And withthe latest raft of features it is even more powerful and expressive than Iwould have previously imagined. But with all this choice comes the questionwhen and how do i apply these features? As has always been the case,Scott's Effective C++ books are the definitive answer to this questionDamien watkinsComputation Software Engineering Team Lead, CSIROGreat read for transitioning to modern C++-new C++11/14language features are described alongside C++98, subject items areeasy to reference, and advice summarized at the end of each sectionEntertaining and useful for both casual and advanced c++ developersRachel chengF5 NetworksIf you're migrating from C++98/03 to C++11/14, you need the eminently practical andclear information Scott provides in Effective Modern C++. If you re already writingC++1l code, you'll probably discover issues with the new features through Scottsthorough discussion of the important new features of the language. Either way, this bookis worth your time.Rob stewartBoost Steering Committee member (boost. org)Effective modern ct+Scott MeyersBeng. Cambridge. Farnham·Kn· Sebastopol, Tokyo OREILLY°Effective modern ct+by Scott MeyersCopyright o 2015 Scott Meyers. All rights reservedPrinted in the canadaPublished by O Reilly Media, InC, 1005 Gravenstein Highway North, Sebastopol, CA 95472O Reilly books may be purchased for educational, business, or sales promotional use. Online editions arealsoavailableformosttitles(http://safaribooksonline.com).Formoreinformationcontactourcorporateinstitutionalsalesdepartment800-998-9938orcorporate@oreilly.comEditor: Rachel roumeliotisProofreader: Charles roumeliotisProduction Editor: Melanie YarbroughIndexer: Scott MeyersCopyeditor: Jasmine KwitynInterior Designer: David FutatoCover Designer: Ellie VolkhausenIllustrator Rebecca demarestNovember 2014First editionRevision history for the first edition2014-11-07: First ReleaseSeehttp:/oreilly.com/catalog/errata.csp?isbn=9781491903995forreleasedetailsThe OReilly logo is a registered trademark of O'Reilly Media, Inc. Effective Modern C++, the cover imageof a Rose-crowned Fruit Dove, and related trade dress are trademarks of o reilly Media, IncWhile the publisher and the author have used good faith efforts to ensure that the information andinstructions contained in this work are accurate, the publisher and the author disclaim all responsibilityfor errors or omissions, including without limitation responsibility for damages resulting from the use ofor reliance on this work. Use of the information and instructions contained in this work is at your ownrisk. if any code samples or other technology this work contains or describes is subject to open sourcelicenses or the intellectual property rights of others, it is your responsibility to ensure that your usethereof complies with such licenses and/or rights978-1-491-90399-5For darlablack labrador retriever extraordinaireTable of contentsFrom the publisherXIAcknowledgmentsIntroduction1. DeducingItem 1: Understand template type deductionItem 2: Understand auto type deduction18Item 3: Understand decltype23Item 4: Know how to view deduced types2.auto.37Item 5: Prefer auto to explicit type declarations37Item 6 Use the explicitly typed initializer idiom when auto deducesundesired types433. Moving to modern c++.........Item 7: Distinguish between () and i] when creating objects49Item 8: Prefer nullptr to o and NULL58Item 9: Prefer alias declarations to typedefsItem 10: Prefer scoped enums to unscoped enums67Item 11: Prefer deleted functions to private undefined onesItem 12: Declare overriding functions overrideItem 13 Prefer const iterators to iterators86Item 14: Declare functions noexcept if they wont emit exceptionsItem 15: Use constexpr whenever possible97Item 16 Make const member functions thread safe103Item 17: Understand special member function generation1094. Smart pointers117Item 18: Use std: unique_ptr for exclusive-ownership resourcemanagement118Item 19: Use std: shared _ptr for shared-ownership resourcemanagement.125Item 20: Use std: Weak_ptr for std: shared_ptr-like pointers that candangle134Item 21: Prefer std: make unique and std: make shared to direct use ofnew139Item 22: When using the Pimpl Idiom, define special member functions inthe implementation file1475. Rvalue References, Move Semantics, and Perfect Forwarding. ......... 157Item 23: Understand std: move and std:: forward158Item 24: Distinguish universal references from rvalue references164Item 25: Use std:: move on rvalue references std: forward on universalreferences168Item 26: Avoid overloading on universal references177Item 27: Familiarize yourself with alternatives to overloading on universalreferences184Item 28: Understand reference collapsing197Item 29: Assume that move operations are not present, not cheap, and notused203Item 30: Familiarize yourself with perfect forwarding failure cases2076. Lambda Expressions.Item 31: Avoid default capture modes216Item 32: Use init capture to move objects into closures224Item 33: Use decltype on auto&& parameters to std: forward them229Item 34: Prefer lambdas to std: bind2327. The Concurrency APl............................ 241Item 35: Prefer task-based programming to thread-based241Item 36: Specify std: Launch: async if asynchronicity is essential245Item 37: Make std: threads unjoinable on all paths250Item 38: Be aware of varying thread handle destructor behavior.258Item 3: Consider void futures for one-shot event communication262I Table of Contents