Micro template library A library for building device drivers
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

34 lines
899 B

  1. /*!
  2. * \file utl/impl/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 \ref virtual_tag can passed to base class. The rest
  15. * will handled by utl automatically.
  16. */
  17. //!@{
  18. namespace utl {
  19. //! CRTP support tag type
  20. struct crtp_tag { };
  21. //! virtual support tag type
  22. struct virtual_tag { };
  23. //! \def CRTP boilerplate lines
  24. #define _CRTP_IMPL(T) \
  25. constexpr T& impl() { return *static_cast<T*>(this); } \
  26. constexpr const T& impl() const { return *static_cast<const T*>(this); }
  27. }
  28. //!@}
  29. #endif /* __utl_impl_crtp_h__ */