replace_if.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*!
  2. @file
  3. Forward declares `boost::hana::replace_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_REPLACE_IF_HPP
  9. #define BOOST_HANA_FWD_REPLACE_IF_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Replace all the elements of a structure satisfying a `predicate`
  14. //! with a fixed value.
  15. //! @ingroup group-Functor
  16. //!
  17. //!
  18. //! Signature
  19. //! ---------
  20. //! Given `F` a Functor and `Bool` a Logical, the signature is
  21. //! \f$
  22. //! \mathtt{replace\_if} : F(T) \times (T \to Bool) \times T \to F(T)
  23. //! \f$
  24. //!
  25. //! @param xs
  26. //! The structure to replace elements of.
  27. //!
  28. //! @param predicate
  29. //! A function called as `predicate(x)` for element(s) `x` of the
  30. //! structure and returning a `Logical` representing whether `x`
  31. //! should be replaced by `value`.
  32. //!
  33. //! @param value
  34. //! A value by which every element `x` of the structure for which
  35. //! `predicate` returns a true-valued `Logical` is replaced.
  36. //!
  37. //!
  38. //! Example
  39. //! -------
  40. //! @include example/replace_if.cpp
  41. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  42. constexpr auto replace_if = [](auto&& xs, auto&& predicate, auto&& value) {
  43. return tag-dispatched;
  44. };
  45. #else
  46. template <typename Xs, typename = void>
  47. struct replace_if_impl : replace_if_impl<Xs, when<true>> { };
  48. struct replace_if_t {
  49. template <typename Xs, typename Pred, typename Value>
  50. constexpr auto operator()(Xs&& xs, Pred&& pred, Value&& value) const;
  51. };
  52. constexpr replace_if_t replace_if{};
  53. #endif
  54. BOOST_HANA_NAMESPACE_END
  55. #endif // !BOOST_HANA_FWD_REPLACE_IF_HPP