More C++ Idioms

Contents

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. Empty Base Optimization (EBO)  
  23. enable-if  
  24. Erase-Remove  
  25. Execute-Around Pointer  
  26. Exploding Return Type TODO
  27. Export Guard Macro TODO
  28. Expression-template  
  29. Fake Vtable TODO
  30. Fast Pimpl   TODO
  31. Final Class  
  32. Free Function Allocators 
  33. Function Object TODO
  34. Generic Container Idioms  
  35. Hierarchy Generation TODO
  36. Include Guard Macro  
  37. Inline Guard Macro  
  38. Inner Class  
  39. Int-To-Type  
  40. Interface Class  
  41. Iterator Pair  
  42. Making New Friends  
  43. Metafunction  
  44. Move Constructor  
  45. Multi-statement Macro  
  46. Member Detector  
  47. Named Constructor  
  48. Named External Argument TODO
  49. Named Loop (labeled loop)  
  50. Named Parameter  
  51. Named Template Parameters TODO
  52. Nifty Counter (Schwarz Counter)  
  53. Non-copyable Mixin  
  54. Non-member Non-friend Function   TODO
  55. Non-throwing swap  
  56. Non-Virtual Interface (NVI, Public Overloaded Non-Virtuals Call Protected Non-Overloaded Virtuals)  
  57. nullptr  
  58. Object Generator  
  59. Object Template TODO
  60. Parameterized Base Class (Parameterized Inheritance)  
  61. Pimpl (Handle Body, Compilation Firewall, Cheshire Cat)  
  62. Policy Clone (Metafunction wrapper)  
  63. Policy-based Design TODO
  64. Polymorphic Exception  
  65. Polymorphic Value Types   TODO
  66. Recursive Type Composition TODO
  67. Requiring or Prohibiting Heap-based Objects
  68. Resource Acquisition Is Initialization (RAII, Execute-Around Object, Scoped Locking)  
  69. Resource Return  
  70. Return Type Resolver  
  71. Runtime Static Initialization Order Idioms  
  72. Safe bool  
  73. Scope Guard  
  74. Substitution Failure Is Not An Error (SFINAE)  
  75. Shortening Long Template Names TODO
  76. Shrink-to-fit  
  77. Small Object Optimization TODO
  78. Smart Pointer  
  79. Storage Class Tracker TODO
  80. Tag Dispatching   TODO
  81. Temporary Base Class  
  82. Temporary Proxy  
  83. The result_of technique TODO
  84. Thin Template  
  85. Traits   TODO
  86. Type Erasure  
  87. Type Generator (Templated Typedef)  
  88. Type Safe Enum  
  89. Type Selection  
  90. Virtual Constructor  
  91. 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