has_common_embedding.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*!
  2. @file
  3. Defines `boost::hana::detail::has_[nontrivial_]common_embedding`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_DETAIL_HAS_COMMON_EMBEDDING_HPP
  9. #define BOOST_HANA_DETAIL_HAS_COMMON_EMBEDDING_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/common.hpp>
  12. #include <boost/hana/core/to.hpp>
  13. #include <boost/hana/detail/void_t.hpp>
  14. #include <type_traits>
  15. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  16. template <template <typename...> class Concept, typename T, typename U, typename = void>
  17. struct has_common_embedding_impl : std::false_type { };
  18. template <template <typename...> class Concept, typename T, typename U>
  19. struct has_common_embedding_impl<Concept, T, U, detail::void_t<
  20. typename common<T, U>::type
  21. >> {
  22. using Common = typename common<T, U>::type;
  23. using type = std::integral_constant<bool,
  24. Concept<T>::value &&
  25. Concept<U>::value &&
  26. Concept<Common>::value &&
  27. is_embedded<T, Common>::value &&
  28. is_embedded<U, Common>::value
  29. >;
  30. };
  31. //! @ingroup group-details
  32. //! Returns whether `T` and `U` both have an embedding into a
  33. //! common type.
  34. //!
  35. //! If `T` and `U` do not have a common-type, this metafunction returns
  36. //! false.
  37. template <template <typename...> class Concept, typename T, typename U>
  38. using has_common_embedding = typename has_common_embedding_impl<Concept, T, U>::type;
  39. template <template <typename...> class Concept, typename T, typename U>
  40. struct has_nontrivial_common_embedding_impl
  41. : has_common_embedding_impl<Concept, T, U>
  42. { };
  43. template <template <typename...> class Concept, typename T>
  44. struct has_nontrivial_common_embedding_impl<Concept, T, T>
  45. : std::false_type
  46. { };
  47. //! @ingroup group-details
  48. //! Returns whether `T` and `U` are distinct and both have an embedding
  49. //! into a common type.
  50. //!
  51. //! If `T` and `U` do not have a common-type, this metafunction returns
  52. //! false.
  53. template <template <typename...> class Concept, typename T, typename U>
  54. using has_nontrivial_common_embedding =
  55. typename has_nontrivial_common_embedding_impl<Concept, T, U>::type;
  56. } BOOST_HANA_NAMESPACE_END
  57. #endif // !BOOST_HANA_DETAIL_HAS_COMMON_EMBEDDING_HPP