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.
 
 
 
 

101 lignes
2.5 KiB

  1. /*!
  2. * \file logical.h
  3. * \brief Template meta-programming logic operator and type relations.
  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_logical_h__
  21. #define __utl_meta_logical_h__
  22. #include <utl/impl/impl.h>
  23. #include <utl/meta/bool.h>
  24. #include <utl/meta/if.h>
  25. /*!
  26. * \ingroup meta
  27. * \defgroup logic
  28. * logic operator and type relations support header
  29. */
  30. //! @{
  31. namespace utl {
  32. //! NOT implementation
  33. template<bool C_>
  34. struct not_ : bool_<!C_> { };
  35. //! OR implementation
  36. //! @{
  37. template<typename...> struct or_;
  38. template<>
  39. struct or_<>
  40. : false_ { };
  41. template<typename _T1>
  42. struct or_<_T1>
  43. : _T1 { };
  44. template<typename _T1, typename _T2>
  45. struct or_ <_T1, _T2>
  46. : select_<_T1::value, _T1, _T2> { };
  47. template<typename _T1, typename _T2, typename _T3, typename... _Tn>
  48. struct or_<_T1, _T2, _T3, _Tn...>
  49. : select_<_T1::value, _T1, or_<_T2, _T3, _Tn...>> { };
  50. //! @}
  51. //! AND implementation
  52. //! @{
  53. template<typename...> struct and_;
  54. template<>
  55. struct and_<>
  56. : true_ { };
  57. template<typename _T1>
  58. struct and_ <_T1>
  59. : _T1 { };
  60. template<typename _T1, typename _T2>
  61. struct and_<_T1, _T2>
  62. : select_<_T1::value, _T2, _T1> { };
  63. template<typename _T1, typename _T2, typename _T3, typename... _Tn>
  64. struct and_<_T1, _T2, _T3, _Tn...>
  65. : select_<_T1::value, and_<_T2, _T3, _Tn...>, _T1> { };
  66. //! @}
  67. //! same
  68. //! @{
  69. template<typename _T1, typename _T2>
  70. struct same_ : false_ { };
  71. template<typename _Tp>
  72. struct same_ <_Tp, _Tp> : true_ { };
  73. //! @}
  74. //! not same
  75. //! @{
  76. template<typename _T1, typename _T2>
  77. struct not_same_ : true_ { };
  78. template<typename _Tp>
  79. struct not_same_ <_Tp, _Tp> : false_ { };
  80. //! @}
  81. }
  82. #endif /* __utl_meta_logical_h__ */