1 /*! 2 @file 3 Defines `boost::hana::adjust`. 4 5 @copyright Louis Dionne 2013-2017 6 Distributed under the Boost Software License, Version 1.0. 7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 8 */ 9 10 #ifndef BOOST_HANA_ADJUST_HPP 11 #define BOOST_HANA_ADJUST_HPP 12 13 #include <boost/hana/fwd/adjust.hpp> 14 15 #include <boost/hana/adjust_if.hpp> 16 #include <boost/hana/concept/functor.hpp> 17 #include <boost/hana/config.hpp> 18 #include <boost/hana/core/dispatch.hpp> 19 #include <boost/hana/equal.hpp> 20 21 22 BOOST_HANA_NAMESPACE_BEGIN 23 //! @cond 24 template <typename Xs, typename Value, typename F> operator ()(Xs && xs,Value && value,F && f) const25 constexpr auto adjust_t::operator()(Xs&& xs, Value&& value, F&& f) const { 26 using S = typename hana::tag_of<Xs>::type; 27 using Adjust = BOOST_HANA_DISPATCH_IF(adjust_impl<S>, 28 hana::Functor<S>::value 29 ); 30 31 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS 32 static_assert(hana::Functor<S>::value, 33 "hana::adjust(xs, value, f) requires 'xs' to be a Functor"); 34 #endif 35 36 return Adjust::apply(static_cast<Xs&&>(xs), 37 static_cast<Value&&>(value), 38 static_cast<F&&>(f)); 39 } 40 //! @endcond 41 42 template <typename Fun, bool condition> 43 struct adjust_impl<Fun, when<condition>> : default_ { 44 template <typename Xs, typename Value, typename F> applyadjust_impl45 static constexpr auto apply(Xs&& xs, Value&& value, F&& f) { 46 return hana::adjust_if( 47 static_cast<Xs&&>(xs), 48 hana::equal.to(static_cast<Value&&>(value)), 49 static_cast<F&&>(f) 50 ); 51 } 52 }; 53 BOOST_HANA_NAMESPACE_END 54 55 #endif // !BOOST_HANA_ADJUST_HPP 56