adjust_if.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*!
  2. @file
  3. Forward declares `boost::hana::adjust_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_ADJUST_IF_HPP
  9. #define BOOST_HANA_FWD_ADJUST_IF_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Apply a function on all the elements of a structure satisfying a predicate.
  14. //! @ingroup group-Functor
  15. //!
  16. //! Given a Functor, a predicate `pred` and a function `f`, `adjust_if`
  17. //! will _adjust_ the elements of the Functor that satisfy the predicate
  18. //! with the function `f`. In other words, `adjust_if` will return a new
  19. //! Functor equal to the original one, except that the elements satisfying
  20. //! the predicate will be transformed with the given function. Elements
  21. //! for which the predicate is not satisfied are left untouched, and they
  22. //! are kept as-is in the resulting Functor.
  23. //!
  24. //!
  25. //! Signature
  26. //! ---------
  27. //! Given a `Functor` `F` and a `Logical` `Bool`, the signature is
  28. //! \f$
  29. //! \mathtt{adjust\_if} : F(T) \times (T \to Bool) \times (T \to T) \to F(T)
  30. //! \f$
  31. //!
  32. //! @param xs
  33. //! The structure to adjust with `f`.
  34. //!
  35. //! @param pred
  36. //! A function called as `pred(x)` for each element of the Functor,
  37. //! and returning whether `f` should be applied on that element.
  38. //!
  39. //! @param f
  40. //! A function called as `f(x)` on the element(s) of the Functor that
  41. //! satisfy the predicate.
  42. //!
  43. //!
  44. //! Example
  45. //! -------
  46. //! @include example/adjust_if.cpp
  47. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  48. constexpr auto adjust_if = [](auto&& xs, auto const& pred, auto const& f) {
  49. return tag-dispatched;
  50. };
  51. #else
  52. template <typename Xs, typename = void>
  53. struct adjust_if_impl : adjust_if_impl<Xs, when<true>> { };
  54. struct adjust_if_t {
  55. template <typename Xs, typename Pred, typename F>
  56. constexpr auto operator()(Xs&& xs, Pred const& pred, F const& f) const;
  57. };
  58. constexpr adjust_if_t adjust_if{};
  59. #endif
  60. BOOST_HANA_NAMESPACE_END
  61. #endif // !BOOST_HANA_FWD_ADJUST_IF_HPP