/*! @file Defines `boost::hana::negate`. @copyright Louis Dionne 2013-2017 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_NEGATE_HPP #define BOOST_HANA_NEGATE_HPP #include #include #include #include #include #include #include namespace boost { namespace hana { //! @cond template constexpr decltype(auto) negate_t::operator()(X&& x) const { using G = typename hana::tag_of::type; using Negate = BOOST_HANA_DISPATCH_IF(negate_impl, hana::Group::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Group::value, "hana::negate(x) requires 'x' to be in a Group"); #endif return Negate::apply(static_cast(x)); } //! @endcond template struct negate_impl> : default_ { template static constexpr decltype(auto) apply(X&& x) { return hana::minus(hana::zero(), static_cast(x)); } }; ////////////////////////////////////////////////////////////////////////// // Model for arithmetic data types ////////////////////////////////////////////////////////////////////////// template struct negate_impl::value && !std::is_same::value>> { template static constexpr decltype(auto) apply(X&& x) { return -static_cast(x); } }; }} // end namespace boost::hana #endif // !BOOST_HANA_NEGATE_HPP