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.
 
 
 
 

48 lines
1.7 KiB

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