find_if.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. @file
  3. Forward declares `boost::hana::find_if`.
  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_IF_HPP
  9. #define BOOST_HANA_FWD_FIND_IF_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 first key satisfying a predicate.
  14. //! @ingroup group-Searchable
  15. //!
  16. //! Given a `Searchable` structure `xs` and a predicate `pred`,
  17. //! `find_if(xs, pred)` returns `just` the first element whose key
  18. //! satisfies the predicate, or `nothing` if there is no such element.
  19. //!
  20. //!
  21. //! @param xs
  22. //! The structure to be searched.
  23. //!
  24. //! @param predicate
  25. //! A function called as `predicate(k)`, where `k` is a key of the
  26. //! structure, and returning whether `k` is the key of the element
  27. //! being searched for. In the current version of the library, the
  28. //! predicate has to return an `IntegralConstant` holding a value
  29. //! that can be converted to `bool`.
  30. //!
  31. //!
  32. //! Example
  33. //! -------
  34. //! @include example/find_if.cpp
  35. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  36. constexpr auto find_if = [](auto&& xs, auto&& predicate) {
  37. return tag-dispatched;
  38. };
  39. #else
  40. template <typename S, typename = void>
  41. struct find_if_impl : find_if_impl<S, when<true>> { };
  42. struct find_if_t {
  43. template <typename Xs, typename Pred>
  44. constexpr auto operator()(Xs&& xs, Pred&& pred) const;
  45. };
  46. constexpr find_if_t find_if{};
  47. #endif
  48. BOOST_HANA_NAMESPACE_END
  49. #endif // !BOOST_HANA_FWD_FIND_IF_HPP