remove.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*!
  2. @file
  3. Defines `boost::hana::remove`.
  4. Copyright Louis Dionne 2013-2022
  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_HPP
  9. #define BOOST_HANA_REMOVE_HPP
  10. #include <boost/hana/fwd/remove.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/equal.hpp>
  15. #include <boost/hana/filter.hpp>
  16. #include <boost/hana/functional/compose.hpp>
  17. #include <boost/hana/not.hpp>
  18. namespace boost { namespace hana {
  19. //! @cond
  20. template <typename Xs, typename Value>
  21. constexpr auto remove_t::operator()(Xs&& xs, Value&& value) const {
  22. using M = typename hana::tag_of<Xs>::type;
  23. using Remove = BOOST_HANA_DISPATCH_IF(remove_impl<M>,
  24. hana::MonadPlus<M>::value
  25. );
  26. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  27. static_assert(hana::MonadPlus<M>::value,
  28. "hana::remove(xs, value) requires 'xs' to be a MonadPlus");
  29. #endif
  30. return Remove::apply(static_cast<Xs&&>(xs),
  31. static_cast<Value&&>(value));
  32. }
  33. //! @endcond
  34. template <typename M, bool condition>
  35. struct remove_impl<M, when<condition>> : default_ {
  36. template <typename Xs, typename Value>
  37. static constexpr auto apply(Xs&& xs, Value&& value) {
  38. return hana::filter(static_cast<Xs&&>(xs),
  39. hana::compose(hana::not_,
  40. hana::equal.to(static_cast<Value&&>(value))));
  41. }
  42. };
  43. }} // end namespace boost::hana
  44. #endif // !BOOST_HANA_REMOVE_HPP