/*! @file Defines `boost::hana::power`. @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_POWER_HPP #define BOOST_HANA_POWER_HPP #include #include #include #include #include #include #include #include #include #include BOOST_HANA_NAMESPACE_BEGIN //! @cond template constexpr decltype(auto) power_t::operator()(X&& x, N const& n) const { using R = typename hana::tag_of::type; using Power = BOOST_HANA_DISPATCH_IF(power_impl, hana::Ring::value && hana::IntegralConstant::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Ring::value, "hana::power(x, n) requires 'x' to be in a Ring"); static_assert(hana::IntegralConstant::value, "hana::power(x, n) requires 'n' to be an IntegralConstant"); #endif static_assert(N::value >= 0, "hana::power(x, n) requires 'n' to be non-negative"); return Power::apply(static_cast(x), n); } //! @endcond template struct power_impl> : default_ { template static constexpr decltype(auto) apply(X&& x, N const&) { constexpr std::size_t n = N::value; return hana::iterate( hana::partial(hana::mult, static_cast(x)), hana::one() ); } }; BOOST_HANA_NAMESPACE_END #endif // !BOOST_HANA_POWER_HPP