intrinsics.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*=============================================================================
  2. Copyright (c) 2016 Paul Fultz II
  3. intrinsics.hpp
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #ifndef BOOST_HOF_GUARD_INTRINSICS_HPP
  8. #define BOOST_HOF_GUARD_INTRINSICS_HPP
  9. #include <type_traits>
  10. #include <boost/hof/detail/holder.hpp>
  11. #include <boost/hof/config.hpp>
  12. // *** clang ***
  13. #if defined(__clang__)
  14. // #define BOOST_HOF_IS_CONSTRUCTIBLE(...) std::is_constructible<__VA_ARGS__>::value
  15. // #define BOOST_HOF_IS_NOTHROW_CONSTRUCTIBLE(...) std::is_nothrow_constructible<__VA_ARGS__>::value
  16. // #define BOOST_HOF_IS_CONVERTIBLE(...) std::is_convertible<__VA_ARGS__>::value
  17. #define BOOST_HOF_IS_CONSTRUCTIBLE(...) __is_constructible(__VA_ARGS__)
  18. #define BOOST_HOF_IS_NOTHROW_CONSTRUCTIBLE(...) __is_nothrow_constructible(__VA_ARGS__)
  19. #define BOOST_HOF_IS_CONVERTIBLE(...) __is_convertible_to(__VA_ARGS__)
  20. #define BOOST_HOF_IS_BASE_OF(...) __is_base_of(__VA_ARGS__)
  21. #define BOOST_HOF_IS_CLASS(...) __is_class(__VA_ARGS__)
  22. #define BOOST_HOF_IS_EMPTY(...) __is_empty(__VA_ARGS__)
  23. #define BOOST_HOF_IS_LITERAL(...) __is_literal(__VA_ARGS__)
  24. #define BOOST_HOF_IS_POLYMORPHIC(...) __is_polymorphic(__VA_ARGS__)
  25. #define BOOST_HOF_IS_FINAL(...) __is_final(__VA_ARGS__)
  26. #define BOOST_HOF_IS_NOTHROW_COPY_CONSTRUCTIBLE(...) __has_nothrow_copy(__VA_ARGS__)
  27. // *** gcc ***
  28. #elif defined(__GNUC__)
  29. #define BOOST_HOF_IS_CONSTRUCTIBLE(...) std::is_constructible<__VA_ARGS__>::value
  30. #define BOOST_HOF_IS_NOTHROW_CONSTRUCTIBLE(...) std::is_nothrow_constructible<__VA_ARGS__>::value
  31. #define BOOST_HOF_IS_CONVERTIBLE(...) std::is_convertible<__VA_ARGS__>::value
  32. #define BOOST_HOF_IS_BASE_OF(...) __is_base_of(__VA_ARGS__)
  33. #define BOOST_HOF_IS_CLASS(...) __is_class(__VA_ARGS__)
  34. #define BOOST_HOF_IS_EMPTY(...) __is_empty(__VA_ARGS__)
  35. #define BOOST_HOF_IS_LITERAL(...) __is_literal_type(__VA_ARGS__)
  36. #define BOOST_HOF_IS_POLYMORPHIC(...) __is_polymorphic(__VA_ARGS__)
  37. #define BOOST_HOF_IS_NOTHROW_COPY_CONSTRUCTIBLE(...) __has_nothrow_copy(__VA_ARGS__)
  38. #if __GNUC__ == 4 && __GNUC_MINOR__ < 7
  39. #define BOOST_HOF_IS_FINAL(...) (false)
  40. #else
  41. #define BOOST_HOF_IS_FINAL(...) __is_final(__VA_ARGS__)
  42. #endif
  43. #define BOOST_HOF_IS_NOTHROW_COPY_CONSTRUCTIBLE(...) __has_nothrow_copy(__VA_ARGS__)
  44. // *** other ***
  45. #else
  46. #define BOOST_HOF_IS_CONSTRUCTIBLE(...) std::is_constructible<__VA_ARGS__>::value
  47. #define BOOST_HOF_IS_NOTHROW_CONSTRUCTIBLE(...) std::is_nothrow_constructible<__VA_ARGS__>::value
  48. #define BOOST_HOF_IS_CONVERTIBLE(...) std::is_convertible<__VA_ARGS__>::value
  49. #define BOOST_HOF_IS_BASE_OF(...) std::is_base_of<__VA_ARGS__>::value
  50. #define BOOST_HOF_IS_CLASS(...) std::is_class<__VA_ARGS__>::value
  51. #define BOOST_HOF_IS_EMPTY(...) std::is_empty<__VA_ARGS__>::value
  52. #ifdef _MSC_VER
  53. #define BOOST_HOF_IS_LITERAL(...) __is_literal_type(__VA_ARGS__)
  54. #else
  55. #define BOOST_HOF_IS_LITERAL(...) std::is_literal_type<__VA_ARGS__>::value
  56. #endif
  57. #define BOOST_HOF_IS_POLYMORPHIC(...) std::is_polymorphic<__VA_ARGS__>::value
  58. #if defined(_MSC_VER)
  59. #define BOOST_HOF_IS_NOTHROW_COPY_CONSTRUCTIBLE(...) (std::is_nothrow_copy_constructible<__VA_ARGS__>::value || std::is_reference<__VA_ARGS__>::value)
  60. #else
  61. #define BOOST_HOF_IS_NOTHROW_COPY_CONSTRUCTIBLE(...) std::is_nothrow_copy_constructible<__VA_ARGS__>::value
  62. #endif
  63. #if defined(_MSC_VER)
  64. #define BOOST_HOF_IS_FINAL(...) __is_final(__VA_ARGS__)
  65. #else
  66. #define BOOST_HOF_IS_FINAL(...) (false)
  67. #endif
  68. #endif
  69. #if BOOST_HOF_NO_STD_DEFAULT_CONSTRUCTIBLE
  70. #define BOOST_HOF_IS_DEFAULT_CONSTRUCTIBLE(...) boost::hof::detail::is_default_constructible_helper<__VA_ARGS__>::value
  71. #else
  72. #define BOOST_HOF_IS_DEFAULT_CONSTRUCTIBLE BOOST_HOF_IS_CONSTRUCTIBLE
  73. #endif
  74. #define BOOST_HOF_IS_NOTHROW_MOVE_CONSTRUCTIBLE(...) BOOST_HOF_IS_NOTHROW_CONSTRUCTIBLE(__VA_ARGS__, __VA_ARGS__ &&)
  75. namespace boost { namespace hof { namespace detail {
  76. template<class T, class=void>
  77. struct is_default_constructible_check
  78. : std::false_type
  79. {};
  80. template<class T>
  81. struct is_default_constructible_check<T, typename holder<
  82. decltype(T())
  83. >::type>
  84. : std::true_type
  85. {};
  86. template<class T>
  87. struct is_default_constructible_helper
  88. : std::conditional<(std::is_reference<T>::value),
  89. std::false_type,
  90. is_default_constructible_check<T>
  91. >::type
  92. {};
  93. template<class T, class... Xs>
  94. struct is_constructible
  95. : std::is_constructible<T, Xs...>
  96. {};
  97. template<class T>
  98. struct is_constructible<T>
  99. : is_default_constructible_helper<T>
  100. {};
  101. }
  102. }} // namespace boost::hof
  103. #endif