find.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*!
  2. @file
  3. Forward declares `boost::hana::find`.
  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_FIND_HPP
  9. #define BOOST_HANA_FWD_FIND_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Finds the value associated to the given key in a structure.
  14. //! @ingroup group-Searchable
  15. //!
  16. //! Given a `key` and a `Searchable` structure, `find` returns the `just`
  17. //! the first value whose key is equal to the given `key`, or `nothing` if
  18. //! there is no such key. Comparison is done with `equal`. `find` satisfies
  19. //! the following:
  20. //! @code
  21. //! find(xs, key) == find_if(xs, equal.to(key))
  22. //! @endcode
  23. //!
  24. //!
  25. //! @param xs
  26. //! The structure to be searched.
  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. In the current
  31. //! version of the library, the comparison of `key` with any other key
  32. //! of the structure must return a compile-time `Logical`.
  33. //!
  34. //!
  35. //! Example
  36. //! -------
  37. //! @include example/find.cpp
  38. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  39. constexpr auto find = [](auto&& xs, auto const& key) {
  40. return tag-dispatched;
  41. };
  42. #else
  43. template <typename S, typename = void>
  44. struct find_impl : find_impl<S, when<true>> { };
  45. struct find_t {
  46. template <typename Xs, typename Key>
  47. constexpr auto operator()(Xs&& xs, Key const& key) const;
  48. };
  49. constexpr find_t find{};
  50. #endif
  51. BOOST_HANA_NAMESPACE_END
  52. #endif // !BOOST_HANA_FWD_FIND_HPP