/*! @file Defines `boost::hana::zero`. @copyright Louis Dionne 2013-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_ZERO_HPP #define BOOST_HANA_ZERO_HPP #include #include #include #include #include #include #include #include BOOST_HANA_NAMESPACE_BEGIN template struct zero_t { #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Monoid::value, "hana::zero() requires 'M' to be a Monoid"); #endif constexpr decltype(auto) operator()() const { using Zero = BOOST_HANA_DISPATCH_IF(zero_impl, hana::Monoid::value ); return Zero::apply(); } }; template struct zero_impl> : default_ { template static constexpr auto apply(Args&& ...) = delete; }; ////////////////////////////////////////////////////////////////////////// // Model for non-boolean arithmetic data types ////////////////////////////////////////////////////////////////////////// template struct zero_impl::value && !std::is_same::value >> { static constexpr T apply() { return static_cast(0); } }; ////////////////////////////////////////////////////////////////////////// // Model for Constants over a Monoid ////////////////////////////////////////////////////////////////////////// namespace detail { template struct constant_from_zero { static constexpr auto value = hana::zero(); using hana_tag = detail::CanonicalConstant; }; } template struct zero_impl::value && Monoid::value >> { static constexpr decltype(auto) apply() { return hana::to(detail::constant_from_zero{}); } }; BOOST_HANA_NAMESPACE_END #endif // !BOOST_HANA_ZERO_HPP