Micro template library A library for building device drivers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

65 lines
1.7 KiB

  1. /*!
  2. * \file if.h
  3. * \brief Template meta-programming conditional helpers
  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. #ifndef __utl_meta_if_h__
  21. #define __utl_meta_if_h__
  22. #include <utl/impl/version.h>
  23. /*!
  24. * \ingroup meta
  25. * \defgroup if
  26. * conditional type support header
  27. */
  28. //! @{
  29. namespace utl {
  30. //! if_
  31. //! @{
  32. template <bool _C, typename _T1, typename _T2>
  33. struct if_ {
  34. typedef _T1 type;
  35. };
  36. template <typename _T1, typename _T2>
  37. struct if_ <false, _T1, _T2> {
  38. typedef _T2 type;
  39. };
  40. //! @}
  41. //! enable_if
  42. //! @{
  43. template <bool, typename _Tp = void>
  44. struct enable_if { };
  45. // Partial specialization for true.
  46. template<typename _Tp>
  47. struct enable_if <true, _Tp> {
  48. typedef _Tp type;
  49. };
  50. //! Alias template for enable_if
  51. template<bool _C, typename _Tp = void>
  52. using enable_if_t = typename enable_if<_C, _Tp>::type;
  53. //! @}
  54. }
  55. //! @}
  56. #endif /* __utl_meta_if_h__ */