intrinsics.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #define BOOST_HOF_IS_LITERAL(...) std::is_literal_type<__VA_ARGS__>::value
  53. #define BOOST_HOF_IS_POLYMORPHIC(...) std::is_polymorphic<__VA_ARGS__>::value
  54. #if defined(_MSC_VER)
  55. #define BOOST_HOF_IS_NOTHROW_COPY_CONSTRUCTIBLE(...) (std::is_nothrow_copy_constructible<__VA_ARGS__>::value || std::is_reference<__VA_ARGS__>::value)
  56. #else
  57. #define BOOST_HOF_IS_NOTHROW_COPY_CONSTRUCTIBLE(...) std::is_nothrow_copy_constructible<__VA_ARGS__>::value
  58. #endif
  59. #if defined(_MSC_VER)
  60. #define BOOST_HOF_IS_FINAL(...) __is_final(__VA_ARGS__)
  61. #else
  62. #define BOOST_HOF_IS_FINAL(...) (false)
  63. #endif
  64. #endif
  65. #if BOOST_HOF_NO_STD_DEFAULT_CONSTRUCTIBLE
  66. #define BOOST_HOF_IS_DEFAULT_CONSTRUCTIBLE(...) boost::hof::detail::is_default_constructible_helper<__VA_ARGS__>::value
  67. #else
  68. #define BOOST_HOF_IS_DEFAULT_CONSTRUCTIBLE BOOST_HOF_IS_CONSTRUCTIBLE
  69. #endif
  70. #define BOOST_HOF_IS_NOTHROW_MOVE_CONSTRUCTIBLE(...) BOOST_HOF_IS_NOTHROW_CONSTRUCTIBLE(__VA_ARGS__, __VA_ARGS__ &&)
  71. namespace boost { namespace hof { namespace detail {
  72. template<class T, class=void>
  73. struct is_default_constructible_check
  74. : std::false_type
  75. {};
  76. template<class T>
  77. struct is_default_constructible_check<T, typename holder<
  78. decltype(T())
  79. >::type>
  80. : std::true_type
  81. {};
  82. template<class T>
  83. struct is_default_constructible_helper
  84. : std::conditional<(std::is_reference<T>::value),
  85. std::false_type,
  86. is_default_constructible_check<T>
  87. >::type
  88. {};
  89. template<class T, class... Xs>
  90. struct is_constructible
  91. : std::is_constructible<T, Xs...>
  92. {};
  93. template<class T>
  94. struct is_constructible<T>
  95. : is_default_constructible_helper<T>
  96. {};
  97. }
  98. }} // namespace boost::hof
  99. #endif