is_subset.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*!
  2. @file
  3. Forward declares `boost::hana::is_subset`.
  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_FWD_IS_SUBSET_HPP
  9. #define BOOST_HANA_FWD_IS_SUBSET_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. #include <boost/hana/functional/infix.hpp>
  13. BOOST_HANA_NAMESPACE_BEGIN
  14. //! Returns whether a structure contains a subset of the keys of
  15. //! another structure.
  16. //! @ingroup group-Searchable
  17. //!
  18. //! Given two `Searchable`s `xs` and `ys`, `is_subset` returns a `Logical`
  19. //! representing whether `xs` is a subset of `ys`. In other words, it
  20. //! returns whether all the keys of `xs` are also present in `ys`. This
  21. //! method does not return whether `xs` is a _strict_ subset of `ys`; if
  22. //! `xs` and `ys` are equal, all the keys of `xs` are also present in
  23. //! `ys`, and `is_subset` returns true.
  24. //!
  25. //! @note
  26. //! For convenience, `is_subset` can also be applied in infix notation.
  27. //!
  28. //!
  29. //! Cross-type version of the method
  30. //! --------------------------------
  31. //! This method is tag-dispatched using the tags of both arguments.
  32. //! It can be called with any two `Searchable`s sharing a common
  33. //! `Searchable` embedding, as defined in the main documentation
  34. //! of the `Searchable` concept. When `Searchable`s with two different
  35. //! tags but sharing a common embedding are sent to `is_subset`, they
  36. //! are first converted to this common `Searchable` and the `is_subset`
  37. //! method of the common embedding is then used. Of course, the method
  38. //! can be overriden for custom `Searchable`s for efficieny.
  39. //!
  40. //! @note
  41. //! While cross-type dispatching for `is_subset` is supported, it is
  42. //! not currently used by the library because there are no models
  43. //! of `Searchable` with a common embedding.
  44. //!
  45. //!
  46. //! @param xs
  47. //! The structure to check whether it is a subset of `ys`.
  48. //!
  49. //! @param ys
  50. //! The structure to check whether it is a superset of `xs`.
  51. //!
  52. //!
  53. //! Example
  54. //! -------
  55. //! @include example/is_subset.cpp
  56. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  57. constexpr auto is_subset = [](auto&& xs, auto&& ys) {
  58. return tag-dispatched;
  59. };
  60. #else
  61. template <typename S1, typename S2, typename = void>
  62. struct is_subset_impl : is_subset_impl<S1, S2, when<true>> { };
  63. struct is_subset_t {
  64. template <typename Xs, typename Ys>
  65. constexpr auto operator()(Xs&& xs, Ys&& ys) const;
  66. };
  67. constexpr auto is_subset = hana::infix(is_subset_t{});
  68. #endif
  69. BOOST_HANA_NAMESPACE_END
  70. #endif // !BOOST_HANA_FWD_IS_SUBSET_HPP