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.
 
 
 
 

49 lignes
1.6 KiB

  1. /*!
  2. * \file /utl/impl/crtp.h
  3. * \brief CRTP idiom support header
  4. *
  5. * Copyright (C) 2018 Christos Choutouridis
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation, either version 3
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #ifndef __utl_impl_crtp_h__
  22. #define __utl_impl_crtp_h__
  23. #include <utl/core/impl.h>
  24. /*!
  25. * \defgroup crtp CRTP idiom support header
  26. * \ingroup impl
  27. *
  28. * utl supports both CRTP idiom and dynamic polymorphism. By default
  29. * CRTP is the preferred way. If the user need virtuals then instead of
  30. * CRTP type, the \ref virtual_tag can passed to base class. The rest
  31. * will handled by utl automatically.
  32. */
  33. //!@{
  34. namespace utl {
  35. //! CRTP support tag type
  36. struct crtp_tag { };
  37. //! virtual support tag type
  38. struct virtual_tag { };
  39. //! \def CRTP boilerplate lines
  40. #define _CRTP_IMPL(T) \
  41. constexpr T& impl() { return *static_cast<T*>(this); } \
  42. constexpr const T& impl() const { return *static_cast<const T*>(this); }
  43. }
  44. //!@}
  45. #endif /* __utl_impl_crtp_h__ */