Micro template library A library for building device drivers
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

36 lignes
921 B

  1. /*!
  2. * \file utl/core/crtp.h
  3. * \brief CRTP idiom support header
  4. */
  5. #ifndef __utl_impl_crtp_h__
  6. #define __utl_impl_crtp_h__
  7. #include <utl/core/impl.h>
  8. /*!
  9. * \defgroup crtp CRTP idiom support header
  10. * \ingroup core
  11. *
  12. * utl supports both CRTP idiom and dynamic polymorphism. By default
  13. * CRTP is the preferred way. If the user need virtuals then instead of
  14. * CRTP type, the \c virtual_tag can passed to base class. The rest
  15. * will handled by utl automatically.
  16. *
  17. * \sa utl::virtual_tag
  18. */
  19. //!@{
  20. namespace utl {
  21. //! CRTP support tag type
  22. struct crtp_tag { };
  23. //! virtual support tag type
  24. struct virtual_tag { };
  25. //! \def CRTP boilerplate lines
  26. #define _CRTP_IMPL(T) \
  27. constexpr T& impl() { return *static_cast<T*>(this); } \
  28. constexpr const T& impl() const { return *static_cast<const T*>(this); }
  29. }
  30. //!@}
  31. #endif /* __utl_impl_crtp_h__ */