C++ Idioms

Idioms are language-specific techniques for solving some more or less popular problems.

Some well-known idioms:

  • include guard
  • RAII - Resource Acquisition Is Initialization (use it instead of missing Java "finally" keyword for automatic object destruction)
  • PIMPL - Pointer To Implementation (hide class implementation to speed-up compilation)
  • CRTP - Curiously Recurring Template Pattern ("Template Method" pattern implemented with help of C++ templates)
  • SFINAE - Substitution Failure Is Not An Error (make use of compiler feature that ignores invalid templates if valid implementations are available)
  • traits - see for example iterator_traits in "iterator" header file

SFINAE

  • SFINAE - wikipedia.org
  • SFINAE - cppreference.com
  • std::enable_if - example of SFINAE implementation in standard library
  • see also boost::enable_if - if you use C++98/C++03

Resources - articles

Resources - Videos

See also

Share

follow