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.
 
 
 
 

119 lignes
2.9 KiB

  1. /*!
  2. * \file logical.h
  3. * \brief Template meta-programming logic operator and type relations.
  4. *
  5. * Copyright (C) 2018-2019 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_logical_h__
  21. #define __utl_meta_logical_h__
  22. #include <utl/core/impl.h>
  23. #include <utl/meta/selection.h>
  24. /*!
  25. * \ingroup meta
  26. * \defgroup logic
  27. * logic operator and type relations support header
  28. */
  29. //! @{
  30. namespace utl {
  31. namespace meta{
  32. /*!
  33. * Logical relation for types
  34. */
  35. //! @{
  36. //! Negate the *bool* constant parameter
  37. template <bool B>
  38. using not_c = bool_<!B>;
  39. //! not
  40. template<typename _Tp>
  41. using not_ = not_c<_Tp::type::value>;
  42. //! OR implementation
  43. //! @{
  44. namespace detail {
  45. template<typename...> struct _or_;
  46. template<>
  47. struct _or_<> : false_ { };
  48. template<typename _T1>
  49. struct _or_<_T1> : _T1 { };
  50. template<typename _T1, typename _T2>
  51. struct _or_ <_T1, _T2>
  52. : if_<_T1, _T1, _T2> { };
  53. template<typename _T1, typename _T2, typename _T3, typename... _Tn>
  54. struct _or_<_T1, _T2, _T3, _Tn...>
  55. : if_<_T1, _T1, _or_<_T2, _T3, _Tn...>> { };
  56. }
  57. template <typename... _Ts>
  58. using or_ = eval<detail::_or_<_Ts...>>;
  59. //! @}
  60. //! AND implementation
  61. //! @{
  62. namespace detail {
  63. template<typename...> struct _and_;
  64. template<>
  65. struct _and_<>
  66. : true_ { };
  67. template<typename _T1>
  68. struct _and_ <_T1>
  69. : _T1 { };
  70. template<typename _T1, typename _T2>
  71. struct _and_<_T1, _T2>
  72. : if_<_T1, _T2, _T1> { };
  73. template<typename _T1, typename _T2, typename _T3, typename... _Tn>
  74. struct _and_<_T1, _T2, _T3, _Tn...>
  75. : if_<_T1, _and_<_T2, _T3, _Tn...>, _T1> { };
  76. }
  77. template <typename... _Ts>
  78. using and_ = eval<detail::_and_<_Ts...>>;
  79. //! @}
  80. //! same
  81. //! @{
  82. template<typename _T1, typename _T2>
  83. struct same_ : false_ { };
  84. template<typename _Tp>
  85. struct same_ <_Tp, _Tp> : true_ { };
  86. //! @}
  87. //! not same
  88. //! @{
  89. template<typename _T1, typename _T2>
  90. using not_same_ = not_<eval<same_<_T1, _T2>>>;
  91. //! @}
  92. //! @}
  93. }}
  94. //! @}
  95. #endif /* __utl_meta_logical_h__ */