File indexing completed on 2025-01-30 09:43:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_POWER_HPP
0011 #define BOOST_HANA_POWER_HPP
0012
0013 #include <boost/hana/fwd/power.hpp>
0014
0015 #include <boost/hana/concept/integral_constant.hpp>
0016 #include <boost/hana/concept/ring.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/functional/iterate.hpp>
0020 #include <boost/hana/functional/partial.hpp>
0021 #include <boost/hana/mult.hpp>
0022 #include <boost/hana/one.hpp>
0023
0024 #include <cstddef>
0025
0026
0027 namespace boost { namespace hana {
0028
0029 template <typename X, typename N>
0030 constexpr decltype(auto) power_t::operator()(X&& x, N const& n) const {
0031 using R = typename hana::tag_of<X>::type;
0032 using Power = BOOST_HANA_DISPATCH_IF(power_impl<R>,
0033 hana::Ring<R>::value &&
0034 hana::IntegralConstant<N>::value
0035 );
0036
0037 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0038 static_assert(hana::Ring<R>::value,
0039 "hana::power(x, n) requires 'x' to be in a Ring");
0040
0041 static_assert(hana::IntegralConstant<N>::value,
0042 "hana::power(x, n) requires 'n' to be an IntegralConstant");
0043 #endif
0044
0045 static_assert(N::value >= 0,
0046 "hana::power(x, n) requires 'n' to be non-negative");
0047
0048 return Power::apply(static_cast<X&&>(x), n);
0049 }
0050
0051
0052 template <typename R, bool condition>
0053 struct power_impl<R, when<condition>> : default_ {
0054 template <typename X, typename N>
0055 static constexpr decltype(auto) apply(X&& x, N const&) {
0056 constexpr std::size_t n = N::value;
0057 return hana::iterate<n>(
0058 hana::partial(hana::mult, static_cast<X&&>(x)),
0059 hana::one<R>()
0060 );
0061 }
0062 };
0063 }}
0064
0065 #endif