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.
 
 
 

153 lines
3.3 KiB

  1. #pragma once
  2. #include <cppmp/config.h>
  3. #include "types.h"
  4. namespace cppmp
  5. {
  6. namespace __impl
  7. {
  8. /* eval_if_c_impl */
  9. template<bool B, typename T, template<typename...> class E, typename... A>
  10. struct eval_if_impl;
  11. }
  12. /* enable_if */
  13. /**
  14. * @brief Defines T as ::type if B is true, otherwise the resulting type is empty.
  15. */
  16. template<bool B, typename T = void>
  17. struct enable_if
  18. : public std::enable_if<B, T>
  19. { };
  20. /**
  21. * @brief Resulting type is T if B is true. If B is false the resulting type is invalid.
  22. */
  23. template<bool B, typename T = void>
  24. using enable_if_t = typename enable_if<B, T>::type;
  25. /* conditional/if */
  26. /**
  27. * @brief Defines T as ::type if B is true, F otherwise.
  28. */
  29. template<bool B, typename T, typename F>
  30. struct conditional
  31. : public std::conditional<B, T, F>
  32. { };
  33. /**
  34. * @brief Evaluates to T if B is true, to F otherwise.
  35. */
  36. template<bool B, typename T, typename F>
  37. using conditional_t = typename conditional<B, T, F>::type;
  38. /**
  39. * @brief Same as conditional.
  40. */
  41. template<bool B, typename T, typename F>
  42. struct if_
  43. : public conditional<B, T, F>
  44. { };
  45. /**
  46. * @brief Same as conditional_t.
  47. */
  48. template<bool B, typename T, typename F>
  49. using if_t = typename if_<B, T, F>::type;
  50. /* eval_if */
  51. /**
  52. * @brief Defines T as ::type if B is true, evaluates E<A...> otherwise.
  53. */
  54. template<bool B, typename T, template<typename...> class E, typename... A>
  55. struct eval_if
  56. : public __impl::eval_if_impl<B, T, E, A...>
  57. { };
  58. /**
  59. * @brief Evaluates to T if B is true, to E<A...> otherwise.
  60. */
  61. template<bool B, typename T, template<typename...> class E, typename... A>
  62. using eval_if_t = typename eval_if<B, T, E, A...>::type;
  63. /* conjunction/and */
  64. #if __cplusplus >= 201703L
  65. /**
  66. * @brief Evaluates to true_t if all passed arguments are also true_t.
  67. */
  68. template<typename... T>
  69. struct conjunction
  70. : public std::conjunction<T...>
  71. { };
  72. /**
  73. * @brief It to true if all passed arguments are also true_t.
  74. */
  75. template<typename... T>
  76. constexpr decltype(auto) conjunction_v = conjunction<T...>::value;
  77. /**
  78. * @brief Same as conjunction.
  79. */
  80. template<typename... T>
  81. struct and_
  82. : public conjunction<T...>
  83. { };
  84. /**
  85. * @brief Same as conjunction_v.
  86. */
  87. template<typename... T>
  88. constexpr decltype(auto) and_v = conjunction<T...>::value;
  89. #endif
  90. /* disjunction/or */
  91. #if __cplusplus >= 201703L
  92. /**
  93. * @brief Evaluates to true_t if at least one passed arguments is true_t.
  94. */
  95. template<typename... T>
  96. struct disjunction
  97. : public std::disjunction<T...>
  98. { };
  99. /**
  100. * @brief Is true if at least one passed arguments is true_t.
  101. */
  102. template<typename... T>
  103. constexpr decltype(auto) disjunction_v = disjunction<T...>::value;
  104. /**
  105. * @brief Same as disjunction.
  106. */
  107. template<typename... T>
  108. struct or_
  109. : public disjunction<T...>
  110. { };
  111. /**
  112. * @brief Same as disjunction_v.
  113. */
  114. template<typename... T>
  115. constexpr decltype(auto) or_v = disjunction<T...>::value;
  116. #endif
  117. }
  118. #include "conditionals.inl"