CppIdioms

MIT License

Stars
75

CppIdioms

Pimpl

Pimpl(Pointer to implementation) C++(visible class)(implementation class)

handle/body,

EBCO

EBCO(Empty Base Class Optimization)C++0

EBO

boost::compressed_pair, std::vectorstd::shared_ptrallocator member

CRTP

CRTP(Curiously Recurring Template Pattern)C++

// CRTP idioms
template <class Derived>
class Base {
};
class Derived : public Base<Derived> {
    // ...
};
template<typename T>
class DerivedTemplate : public Base<DerivedTemplate<T>> {
   // ...
};

butil::LinkedListenable_shared_from_thisc++20:ranges::view_interface

Mixin

Mixin(Mix in) C++:

template<typename... Mixins>
class MixinClass : public Mixins... {
  public:
    MixinClass() :  Mixins()... {}
  // ...
};

std::nested_exception

Scoped Locking

Scoped Locking RAIIlockingScoped LockingC++4

  • std::lock_guard (c++11): std::mutex(std::shared_mutex)
  • std::unique_lock (c++11): std::mutex(std::shared_mutex), std::lock_guard
  • std::shared_lock (c++14): std::shared_mutex
  • std::scoped_lock (c++17): std::mutex(std::shared_mutex)

std::lock_guard, std::unique_lock, std::shared_lock std::scoped_lock

Type Erasure

Type Erasure

Variants of the technique of using a single run-time representation for values of a number of types and relying on the (static) type system to ensure that they are used only according to their declared type has been called type erasure - Bjarne Stroustrup <<The C++ Programming Language 4ed>>

Type ErasureC++JavaPython

: std::any std::function