contains.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*!
  2. @file
  3. Forward declares `boost::hana::contains` and `boost::hana::in`.
  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_CONTAINS_HPP
  9. #define BOOST_HANA_FWD_CONTAINS_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. #include <boost/hana/functional/flip.hpp>
  13. #include <boost/hana/functional/infix.hpp>
  14. BOOST_HANA_NAMESPACE_BEGIN
  15. //! Returns whether the key occurs in the structure.
  16. //! @ingroup group-Searchable
  17. //!
  18. //! Given a `Searchable` structure `xs` and a `key`, `contains` returns
  19. //! whether any of the keys of the structure is equal to the given `key`.
  20. //! If the structure is not finite, an equal key has to appear at a finite
  21. //! position in the structure for this method to finish. For convenience,
  22. //! `contains` can also be applied in infix notation.
  23. //!
  24. //!
  25. //! @param xs
  26. //! The structure to search.
  27. //!
  28. //! @param key
  29. //! A key to be searched for in the structure. The key has to be
  30. //! `Comparable` with the other keys of the structure.
  31. //!
  32. //!
  33. //! Example
  34. //! -------
  35. //! @include example/contains.cpp
  36. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  37. constexpr auto contains = [](auto&& xs, auto&& key) {
  38. return tag-dispatched;
  39. };
  40. #else
  41. template <typename S, typename = void>
  42. struct contains_impl : contains_impl<S, when<true>> { };
  43. struct contains_t {
  44. template <typename Xs, typename Key>
  45. constexpr auto operator()(Xs&& xs, Key&& key) const;
  46. };
  47. constexpr auto contains = hana::infix(contains_t{});
  48. #endif
  49. //! Return whether the key occurs in the structure.
  50. //! @ingroup group-Searchable
  51. //!
  52. //! Specifically, this is equivalent to `contains`, except `in` takes its
  53. //! arguments in reverse order. Like `contains`, `in` can also be applied
  54. //! in infix notation for increased expressiveness. This function is not a
  55. //! method that can be overriden; it is just a convenience function
  56. //! provided with the concept.
  57. //!
  58. //!
  59. //! Example
  60. //! -------
  61. //! @include example/in.cpp
  62. constexpr auto in = hana::infix(hana::flip(hana::contains));
  63. BOOST_HANA_NAMESPACE_END
  64. #endif // !BOOST_HANA_FWD_CONTAINS_HPP