More C++ Idioms

PrefaceEdit

  C++ has indeed become too "expert friendly" -- Bjarne Stroustrup, The Problem with Programming, Technology Review, Nov 2006.

Stroustrup's saying is true because experts are intimately familiar with the idioms in the language. With the increase in the idioms a programmer understands, the language becomes friendlier to him or her. The objective of this open content book is to present modern C++ idioms to programmers who have moderate level of familiarity with C++, and help elevate their knowledge so that C++ feels much friendlier to them. It is designed to be an exhaustive catalog of reusable idioms that expert C++ programmers often use while programming or designing using C++. This is an effort to capture their techniques and vocabulary into a single work. This book describes the idioms in a regular format: Name-Intent-Motivation-Solution-References, which is succinct and helps speed learning. By their nature, idioms tend to have appeared in the C++ community and in published work many times. An effort has been made to refer to the original source(s) where possible; if you find a reference incomplete or incorrect, please feel free to suggest or make improvements.

The world is invited to catalog reusable pieces of C++ knowledge (similar to the book on design patterns by GoF). The goal here is to first build an exhaustive catalog of modern C++ idioms and later evolve it into an idiom language, just like a pattern language. Finally, the contents of this book can be redistributed under the terms of the GNU Free Documentation License.

Aimed toward: Anyone with an intermediate level of knowledge in C++ and supported language paradigms

More InformationEdit

Authors | Praise | Guidelines for Authors | GNU Free Documentation License

 

More C++ Idioms Recent Changes RSS 2.0




Table of ContentsEdit

Note: synonyms for each idiom are listed in parentheses.

  1. Address Of  
  2. Algebraic Hierarchy  
  3. Attach by Initialization  
  4. Attorney-Client  
  5. Barton-Nackman trick  
  6. Base-from-Member  
  7. Boost mutant  
  8. Calling Virtuals During Initialization  
  9. Capability Query  
  10. Checked delete  
  11. Clear-and-minimize  
  12. Coercion by Member Template  
  13. Computational Constructor  
  14. Concrete Data Type  
  15. Construct On First Use  
  16. Construction Tracker  
  17. Copy-and-swap  
  18. Copy-on-write  
  19. Intrusive reference counting (Counted Body)  
  20. Covariant Return Types TODO
  21. Curiously Recurring Template Pattern (CRTP)  
  22. Deprecate and Delete TODO
  23. Empty Base Optimization (EBO)  
  24. enable-if  
  25. Erase-Remove  
  26. Execute-Around Pointer  
  27. Exploding Return Type TODO
  28. Export Guard Macro TODO
  29. Expression-template  
  30. Fake Vtable TODO
  31. Fast Pimpl   TODO
  32. Final Class  
  33. Free Function Allocators 
  34. Function Object TODO
  35. Function Poisoning TODO
  36. Generic Container Idioms  
  37. Hierarchy Generation TODO
  38. Implicit conversions TODO
  39. Include Guard Macro  
  40. Inline Guard Macro  
  41. Inner Class  
  42. Int-To-Type  
  43. Interface Class  
  44. Iterator Pair  
  45. Making New Friends  
  46. Metafunction  
  47. Move Constructor  
  48. Multi-statement Macro  
  49. Member Detector  
  50. Named Constructor  
  51. Named External Argument TODO
  52. Named Loop (labeled loop)  
  53. Named Parameter  
  54. Named Template Parameters TODO
  55. Nifty Counter (Schwarz Counter)  
  56. Non-copyable Mixin  
  57. Non-member Non-friend Function   TODO
  58. Non-throwing swap  
  59. Non-Virtual Interface (NVI, Public Overloaded Non-Virtuals Call Protected Non-Overloaded Virtuals)  
  60. nullptr  
  61. Object Generator  
  62. Object Template TODO
  63. Parameterized Base Class (Parameterized Inheritance)  
  64. Pimpl (Handle Body, Compilation Firewall, Cheshire Cat)  
  65. Policy Clone (Metafunction wrapper)  
  66. Policy-based Design TODO
  67. Polymorphic Exception  
  68. Polymorphic Value Types   TODO
  69. Recursive Type Composition TODO
  70. Requiring or Prohibiting Heap-based Objects
  71. Resource Acquisition Is Initialization (RAII, Execute-Around Object, Scoped Locking)  
  72. Resource Return  
  73. Return Type Resolver  
  74. Runtime Static Initialization Order Idioms  
  75. Safe bool  
  76. Scope Guard  
  77. Substitution Failure Is Not An Error (SFINAE)  
  78. Shortening Long Template Names TODO
  79. Shrink-to-fit  
  80. Small Object Optimization TODO
  81. Smart Pointer  
  82. Storage Class Tracker TODO
  83. Tag Dispatching   TODO
  84. Temporary Base Class  
  85. Temporary Proxy  
  86. The result_of technique TODO
  87. Thin Template  
  88. Thread-Safe Interface TODO
  89. Traits   TODO
  90. Type Erasure  
  91. Type Generator (Templated Typedef)  
  92. Type Safe Enum  
  93. Type Selection  
  94. Virtual Constructor  
  95. Virtual Friend Function  

Advanced idiomsEdit

These are some more advanced C++ idioms.

  1. Envelope Letter   TODO


Deprecated idiomsEdit

  1. Const auto_ptr  


Wikibook Development Stages
Sparse text   Developing text   Maturing text   Developed text   Comprehensive text