remove_if.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*!
  2. @file
  3. Forward declares `boost::hana::remove_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_REMOVE_IF_HPP
  9. #define BOOST_HANA_FWD_REMOVE_IF_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Remove all the elements of a monadic structure that satisfy some
  14. //! predicate.
  15. //! @ingroup group-MonadPlus
  16. //!
  17. //! Given a monadic structure `xs` and a unary predicate, `remove_if`
  18. //! returns a new monadic structure equal to `xs` without all its elements
  19. //! that satisfy the predicate. This is equivalent to `filter` with a
  20. //! negated predicate, i.e.
  21. //! @code
  22. //! remove_if(xs, predicate) == filter(xs, negated predicated)
  23. //! @endcode
  24. //!
  25. //!
  26. //! Signature
  27. //! ---------
  28. //! Given a MonadPlus `M` and a predicate of type \f$ T \to Bool \f$ for
  29. //! some compile-time Logical `Bool`, the signature is
  30. //! \f$
  31. //! \mathrm{remove\_if} : M(T) \times (T \to Bool) \to M(T)
  32. //! \f$
  33. //!
  34. //! @param xs
  35. //! A monadic structure to remove some elements from.
  36. //!
  37. //! @param predicate
  38. //! A unary predicate called as `predicate(x)`, where `x` is an element
  39. //! of the structure, and returning whether `x` should be removed from
  40. //! the structure. In the current version of the library, `predicate`
  41. //! must return a compile-time Logical.
  42. //!
  43. //!
  44. //! Example
  45. //! -------
  46. //! @include example/remove_if.cpp
  47. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  48. constexpr auto remove_if = [](auto&& xs, auto&& predicate) {
  49. return tag-dispatched;
  50. };
  51. #else
  52. template <typename M, typename = void>
  53. struct remove_if_impl : remove_if_impl<M, when<true>> { };
  54. struct remove_if_t {
  55. template <typename Xs, typename Pred>
  56. constexpr auto operator()(Xs&& xs, Pred&& pred) const;
  57. };
  58. constexpr remove_if_t remove_if{};
  59. #endif
  60. BOOST_HANA_NAMESPACE_END
  61. #endif // !BOOST_HANA_FWD_REMOVE_IF_HPP