Acknowledgments
I started investigating what was then known as C++0x (the nascent C++11) in 2009. I posted numerous questions to the Usenet newsgroup comp.std.c++
, and Iâm grateful to the members of that community (especially Daniel Krügler) for their very helpful postings. In more recent years, Iâve turned to Stack Overflow when I had questions about C++11 and C++14, and Iâm equally indebted to that community for its help in understanding the finer points of modern C++.Â
In 2010, I prepared materials for a training course on C++0x (ultimately published as Overview of the New C++, Artima Publishing, 2010). Both those materials and my knowledge greatly benefited from the technical vetting performed by Stephan T. Lavavej, Bernhard Merkle, Stanley Friesen, Leor Zolman, Hendrik Schober, and Anthony Williams. Without their help, I would probably never have been in a position to undertake Effective Modern C++. That title, incidentally, was suggested or endorsed by several readers responding to my 18 February 2014 blog post, âHelp me name my book,â and Andrei Alexandrescu (author of Modern C++ Design, Addison-Wesley, 2001) was kind enough to bless the title as not poaching on his terminological turf.Â
Iâm unable to identify the origins of all the information in this book, but some sources had a relatively direct impact. Item 4âs use of an undefined template to coax type information out of compilers was suggested by Stephan T. Lavavej, and Matt P. Dziubinski brought Boost.TypeIndex to my attention. In Item 5, the unsigned
-std::vector<int>::size_type
example is from Andrey Karpovâs 28 February 2010 article, âIn what way can C++0x standard help you eliminate 64-bit errors.â The std::pair<std::string,
int>
/std::pair<const
std::string,
int>
example in the same Item is from Stephan T. Lavavejâs talk at Going Native 2012, âSTL11: Magic && Secrets.â Item 6 was inspired by Herb Sutterâs 12 August 2013 article, âGotW #94 Solution: AAA Style (Almost Always Auto).â Item 9 was motivated by Martinho Fernandesâ blog post of 27 May 2012, âHandling dependent names.â The Item 12 example demonstrating overloading on reference qualifiers is based on Caseyâs answer to the question, âWhatâs a use case for overloading member functions on reference qualifiers?,â posted to Stack Overflow on 14 January 2014. My Item 15 treatment of C++14âs expanded support for constexpr
functions incorporates information I received from Rein Halbersma. Item 16 is based on Herb Sutterâs C++ and Beyond 2012 presentation, âYou donât know const
and mutable
.â Item 18âs advice to have factory functions return std::unique_ptr
s is based on Herb Sutterâs 30 May 2013 article, âGotW# 90 Solution: Factories.â In Item 19, fastLoadWidget
is derived from Herb Sutterâs Going Native 2013 presentation, âMy Favorite C++ 10-Liner.â My treatment of std::unique_ptr
and incomplete types in Item 22 draws on Herb Sutterâs 27 November 2011 article, âGotW #100: Compilation Firewallsâ as well as Howard Hinnantâs 22 May 2011 answer to the Stack Overflow question, âIs std::unique_ptr<T> required to know the full definition of T?â The Matrix
addition example in Item 25 is based on writings by David Abrahams. JoeArgonneâs 8 December 2012 comment on the 30 November 2012 blog post, âAnother alternative to lambda move capture,â was the source of Item 32âs std::bind
-based approach to emulating init capture in C++11. Item 37âs explanation of the problem with an implicit detach in std::thread
âs destructor is taken from Hans-J. Boehmâs 4 December 2008 paper, âN2802: A plea to reconsider detach-on-destruction for thread objects.â Item 41 was originally motivated by discussions of David Abrahamsâ 15 August 2009 blog post, âWant speed? Pass by value.â The idea that move-only types deserve special treatment is due to Matthew Fioravante, while the analysis of assignment-based copying stems from comments by Howard Hinnant. In Item 42, Stephan T. Lavavej and Howard Hinnant helped me understand the relative performance profiles of emplacement and insertion functions, and Michael Winterberg brought to my attention how emplacement can lead to resource leaks. (Michael credits Sean Parentâs Going Native 2013 presentation, âC++ Seasoning,â as his source.) Michael also pointed out how emplacement functions use direct initialization, while insertion functions use copy initialization.
Reviewing drafts of a technical book is a demanding, time-consuming, and utterly critical task, and Iâm fortunate that so many people were willing to do it for me. Full or partial drafts of Effective Modern C++ were officially reviewed by Cassio Neri, Nate Kohl, Gerhard Kreuzer, Leor Zolman, Bart Vandewoestyne, Stephan T. Lavavej, Nevin â:-)â Liber, Rachel Cheng, Rob Stewart, Bob Steagall, Damien Watkins, Bradley E. Needham, Rainer Grimm, Fredrik Winkler, Jonathan Wakely, Herb Sutter, Andrei Alexandrescu, Eric Niebler, Thomas Becker, Roger Orr, Anthony Williams, Michael Winterberg, Benjamin Huchley, Tom Kirby-Green, Alexey A Nikitin, William Dealtry, Hubert Matthews, and Tomasz KamiÅski. I also received feedback from several readers through OâReillyâs Early Release EBooks and Safari Books Onlineâs Rough Cuts, comments on my blog (The View from Aristeia), and email. Iâm grateful to each of these people. The book is much better than it would have been without their help. Iâm particularly indebted to Stephan T. Lavavej and Rob Stewart, whose extraordinarily detailed and comprehensive remarks lead me to worry that they spent nearly as much time on this book as I did. Special thanks also go to Leor Zolman, who, in addition to reviewing the manuscript, double-checked all the code examples.
Dedicated reviews of digital versions of the book were performed by Gerhard Kreuzer, Emyr Williams, and Bradley E. Needham.
My decision to limit the line length in code displays to 64 characters (the maximum likely to display properly in print as well as across a variety of digital devices, device orientations, and font configurations) was based on data provided by Michael Maher.
Since initial publication, Iâve incorporated bug fixes and other improvements suggested by Kostas Vlahavas, Daniel Alonso Alemany, Takatoshi Kondo, Bartek Szurgot, Tyler Brock, Jay Zipnick, Barry Revzin, Robert McCabe, Oliver Bruns, Fabrice Ferino, Dainis Jonitis, Petr Valasek, Bart Vandewoestyne, Kjell Hedstrom, Marcel Wid, Mark A. McLaughlin, Miroslaw Michalski, Vlad Gheorghiu, Mitsuru Kariya, Minkoo Seo, Tomasz KamiÅski, AgustÃn K-ballo Bergé, GrebÑnkin Sergey, Adam Peterson, Matthias J. Sax, Semen Trygubenko, Lewis Stiller, Leor Zolman, and Kisung Han. Many thanks to all these people for helping improve the accuracy and clarity of Effective Modern C++.
Ashley Morgan Williams made dining at the Lake Oswego Pizzicato uniquely entertaining. When it comes to man-sized Caesars, sheâs the go-to gal.
More than 20 years after first living through my playing author, my wife, Nancy L. Urbano, once again tolerated many months of distracted conversations with a cocktail of resignation, exasperation, and timely splashes of understanding and support. During the same period, our dog, Darla, was largely content to doze away the hours I spent staring at computer screens, but she never let me forget that thereâs life beyond the keyboard.
Get Effective Modern C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.