/*! @file Defines `boost::hana::hash`. @copyright Jason Rice 2016 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_HANA_HASH_HPP #define BOOST_HANA_HASH_HPP #include #include #include #include #include #include #include #include namespace boost { namespace hana { //! @cond template constexpr auto hash_t::operator()(X const& x) const { using Tag = typename hana::tag_of::type; using Hash = BOOST_HANA_DISPATCH_IF(hash_impl, hana::Hashable::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Hashable::value, "hana::hash(x) requires 'x' to be Hashable"); #endif return Hash::apply(x); } //! @endcond template struct hash_impl> : default_ { template static constexpr auto apply(X const&) = delete; }; namespace detail { template struct hash_integral_helper; template struct hash_integral_helper { template static constexpr auto apply(X const&) { return hana::type_c>; } }; template struct hash_integral_helper::value>::type > { template static constexpr auto apply(X const&) { constexpr signed long long x = X::value; return hana::type_c>; } }; template struct hash_integral_helper::value>::type > { template static constexpr auto apply(X const&) { constexpr unsigned long long x = X::value; return hana::type_c>; } }; template <> struct hash_integral_helper { template static constexpr auto apply(X const&) { return hana::type_c>; } }; template <> struct hash_integral_helper { template static constexpr auto apply(X const&) { using T = std::conditional::value, signed long long, unsigned long long >::type; constexpr T x = X::value; return hana::type_c>; } }; } template struct hash_impl::value>> { template static constexpr auto apply(X const& x) { using T = typename std::remove_cv::type; return detail::hash_integral_helper::apply(x); } }; }} // end namespace boost::hana #endif // !BOOST_HANA_HASH_HPP