remove_if.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*!
  2. @file
  3. Defines `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_REMOVE_IF_HPP
  9. #define BOOST_HANA_REMOVE_IF_HPP
  10. #include <boost/hana/fwd/remove_if.hpp>
  11. #include <boost/hana/concept/monad_plus.hpp>
  12. #include <boost/hana/config.hpp>
  13. #include <boost/hana/core/dispatch.hpp>
  14. #include <boost/hana/filter.hpp>
  15. #include <boost/hana/functional/compose.hpp>
  16. #include <boost/hana/not.hpp>
  17. BOOST_HANA_NAMESPACE_BEGIN
  18. //! @cond
  19. template <typename Xs, typename Pred>
  20. constexpr auto remove_if_t::operator()(Xs&& xs, Pred&& pred) const {
  21. using M = typename hana::tag_of<Xs>::type;
  22. using RemoveIf = BOOST_HANA_DISPATCH_IF(remove_if_impl<M>,
  23. hana::MonadPlus<M>::value
  24. );
  25. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  26. static_assert(hana::MonadPlus<M>::value,
  27. "hana::remove_if(xs, predicate) requires 'xs' to be a MonadPlus");
  28. #endif
  29. return RemoveIf::apply(static_cast<Xs&&>(xs),
  30. static_cast<Pred&&>(pred));
  31. }
  32. //! @endcond
  33. template <typename M, bool condition>
  34. struct remove_if_impl<M, when<condition>> : default_ {
  35. template <typename Xs, typename Pred>
  36. static constexpr auto apply(Xs&& xs, Pred&& pred) {
  37. return hana::filter(static_cast<Xs&&>(xs),
  38. hana::compose(hana::not_, static_cast<Pred&&>(pred)));
  39. }
  40. };
  41. BOOST_HANA_NAMESPACE_END
  42. #endif // !BOOST_HANA_REMOVE_IF_HPP