adjust.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*!
  2. @file
  3. Defines `boost::hana::adjust`.
  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_ADJUST_HPP
  9. #define BOOST_HANA_ADJUST_HPP
  10. #include <boost/hana/fwd/adjust.hpp>
  11. #include <boost/hana/adjust_if.hpp>
  12. #include <boost/hana/concept/functor.hpp>
  13. #include <boost/hana/config.hpp>
  14. #include <boost/hana/core/dispatch.hpp>
  15. #include <boost/hana/equal.hpp>
  16. namespace boost { namespace hana {
  17. //! @cond
  18. template <typename Xs, typename Value, typename F>
  19. constexpr auto adjust_t::operator()(Xs&& xs, Value&& value, F&& f) const {
  20. using S = typename hana::tag_of<Xs>::type;
  21. using Adjust = BOOST_HANA_DISPATCH_IF(adjust_impl<S>,
  22. hana::Functor<S>::value
  23. );
  24. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  25. static_assert(hana::Functor<S>::value,
  26. "hana::adjust(xs, value, f) requires 'xs' to be a Functor");
  27. #endif
  28. return Adjust::apply(static_cast<Xs&&>(xs),
  29. static_cast<Value&&>(value),
  30. static_cast<F&&>(f));
  31. }
  32. //! @endcond
  33. template <typename Fun, bool condition>
  34. struct adjust_impl<Fun, when<condition>> : default_ {
  35. template <typename Xs, typename Value, typename F>
  36. static constexpr auto apply(Xs&& xs, Value&& value, F&& f) {
  37. return hana::adjust_if(
  38. static_cast<Xs&&>(xs),
  39. hana::equal.to(static_cast<Value&&>(value)),
  40. static_cast<F&&>(f)
  41. );
  42. }
  43. };
  44. }} // end namespace boost::hana
  45. #endif // !BOOST_HANA_ADJUST_HPP