1 /*! 2 @file 3 Defines `boost::hana::max`. 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_MAX_HPP 11 #define BOOST_HANA_MAX_HPP 12 13 #include <boost/hana/fwd/max.hpp> 14 15 #include <boost/hana/concept/orderable.hpp> 16 #include <boost/hana/config.hpp> 17 #include <boost/hana/core/dispatch.hpp> 18 #include <boost/hana/if.hpp> 19 #include <boost/hana/less.hpp> 20 21 22 BOOST_HANA_NAMESPACE_BEGIN 23 //! @cond 24 template <typename X, typename Y> operator ()(X && x,Y && y) const25 constexpr decltype(auto) max_t::operator()(X&& x, Y&& y) const { 26 using T = typename hana::tag_of<X>::type; 27 using U = typename hana::tag_of<Y>::type; 28 using Max = BOOST_HANA_DISPATCH_IF(decltype(max_impl<T, U>{}), 29 hana::Orderable<T>::value && 30 hana::Orderable<U>::value 31 ); 32 33 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS 34 static_assert(hana::Orderable<T>::value, 35 "hana::max(x, y) requires 'x' to be Orderable"); 36 37 static_assert(hana::Orderable<U>::value, 38 "hana::max(x, y) requires 'y' to be Orderable"); 39 #endif 40 41 return Max::apply(static_cast<X&&>(x), static_cast<Y&&>(y)); 42 } 43 //! @endcond 44 45 template <typename T, typename U, bool condition> 46 struct max_impl<T, U, when<condition>> : default_ { 47 template <typename X, typename Y> applymax_impl48 static constexpr decltype(auto) apply(X&& x, Y&& y) { 49 decltype(auto) cond = hana::less(x, y); 50 return hana::if_(static_cast<decltype(cond)&&>(cond), 51 static_cast<Y&&>(y), 52 static_cast<X&&>(x) 53 ); 54 } 55 }; 56 BOOST_HANA_NAMESPACE_END 57 58 #endif // !BOOST_HANA_MAX_HPP 59