detectors.hpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2016-2021 Antony Polukhin
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_PFR_DETAIL_DETECTORS_HPP
  6. #define BOOST_PFR_DETAIL_DETECTORS_HPP
  7. #pragma once
  8. #include <boost/pfr/detail/config.hpp>
  9. #include <functional>
  10. #include <type_traits>
  11. namespace boost { namespace pfr { namespace detail {
  12. ///////////////////// `value` is true if Detector<Tleft, Tright> does not compile (SFINAE)
  13. struct can_not_apply{};
  14. template <template <class, class> class Detector, class Tleft, class Tright>
  15. struct not_appliable {
  16. static constexpr bool value = std::is_same<
  17. Detector<Tleft, Tright>,
  18. can_not_apply
  19. >::value;
  20. };
  21. ///////////////////// Detectors for different operators
  22. template <class S, class T> auto comp_eq_detector_msvc_helper(long) -> decltype(std::declval<S>() == std::declval<T>());
  23. template <class S, class T> can_not_apply comp_eq_detector_msvc_helper(int);
  24. template <class T1, class T2> using comp_eq_detector = decltype(comp_eq_detector_msvc_helper<T1,T2>(1L));
  25. template <class S, class T> auto comp_ne_detector_msvc_helper(long) -> decltype(std::declval<S>() != std::declval<T>());
  26. template <class S, class T> can_not_apply comp_ne_detector_msvc_helper(int);
  27. template <class T1, class T2> using comp_ne_detector = decltype(comp_ne_detector_msvc_helper<T1,T2>(1L));
  28. template <class S, class T> auto comp_lt_detector_msvc_helper(long) -> decltype(std::declval<S>() < std::declval<T>());
  29. template <class S, class T> can_not_apply comp_lt_detector_msvc_helper(int);
  30. template <class T1, class T2> using comp_lt_detector = decltype(comp_lt_detector_msvc_helper<T1,T2>(1L));
  31. template <class S, class T> auto comp_le_detector_msvc_helper(long) -> decltype(std::declval<S>() <= std::declval<T>());
  32. template <class S, class T> can_not_apply comp_le_detector_msvc_helper(int);
  33. template <class T1, class T2> using comp_le_detector = decltype(comp_le_detector_msvc_helper<T1,T2>(1L));
  34. template <class S, class T> auto comp_gt_detector_msvc_helper(long) -> decltype(std::declval<S>() > std::declval<T>());
  35. template <class S, class T> can_not_apply comp_gt_detector_msvc_helper(int);
  36. template <class T1, class T2> using comp_gt_detector = decltype(comp_gt_detector_msvc_helper<T1,T2>(1L));
  37. template <class S, class T> auto comp_ge_detector_msvc_helper(long) -> decltype(std::declval<S>() >= std::declval<T>());
  38. template <class S, class T> can_not_apply comp_ge_detector_msvc_helper(int);
  39. template <class T1, class T2> using comp_ge_detector = decltype(comp_ge_detector_msvc_helper<T1,T2>(1L));
  40. template <class S> auto hash_detector_msvc_helper(long) -> decltype(std::hash<S>{}(std::declval<S>()));
  41. template <class S> can_not_apply hash_detector_msvc_helper(int);
  42. template <class T1, class T2> using hash_detector = decltype(hash_detector_msvc_helper<T1,T2>(1L));
  43. template <class S, class T> auto ostreamable_detector_msvc_helper(long) -> decltype(std::declval<S>() << std::declval<T>());
  44. template <class S, class T> can_not_apply ostreamable_detector_msvc_helper(int);
  45. template <class S, class T> using ostreamable_detector = decltype(ostreamable_detector_msvc_helper<S,T>(1L));
  46. template <class S, class T> auto istreamable_detector_msvc_helper(long) -> decltype(std::declval<S>() >> std::declval<T>());
  47. template <class S, class T> can_not_apply istreamable_detector_msvc_helper(int);
  48. template <class S, class T> using istreamable_detector = decltype(istreamable_detector_msvc_helper<S,T>(1L));
  49. }}} // namespace boost::pfr::detail
  50. #endif // BOOST_PFR_DETAIL_DETECTORS_HPP