// Boost.Units - A C++ library for zero-overhead dimensional analysis and // unit/quantity manipulation and conversion // // Copyright (C) 2003-2008 Matthias Christian Schabel // Copyright (C) 2008 Steven Watanabe // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_UNITS_POW_HPP #define BOOST_UNITS_POW_HPP #include #include #include #include #include /// \file /// \brief Raise values to exponents known at compile-time. namespace boost { namespace units { /// raise a value to a @c static_rational power. template inline typename power_typeof_helper::type pow(const Y& x) { return power_typeof_helper::value(x); } /// raise a value to an integer power. template inline typename power_typeof_helper >::type pow(const Y& x) { return power_typeof_helper >::value(x); } #ifndef BOOST_UNITS_DOXYGEN /// raise @c T to a @c static_rational power. template struct power_typeof_helper > { typedef typename mpl::if_, double, T>::type internal_type; typedef detail::static_rational_power_impl, internal_type> impl; typedef typename impl::type type; static type value(const T& x) { return impl::call(x); } }; /// raise @c float to a @c static_rational power. template struct power_typeof_helper > { // N.B. pathscale doesn't accept inheritance for some reason. typedef power_typeof_helper > base; typedef typename base::type type; static type value(const double& x) { return base::value(x); } }; #endif /// take the @c static_rational root of a value. template typename root_typeof_helper::type root(const Y& x) { return root_typeof_helper::value(x); } /// take the integer root of a value. template typename root_typeof_helper >::type root(const Y& x) { return root_typeof_helper >::value(x); } #ifndef BOOST_UNITS_DOXYGEN /// take @c static_rational root of an @c T template struct root_typeof_helper > { // N.B. pathscale doesn't accept inheritance for some reason. typedef power_typeof_helper > base; typedef typename base::type type; static type value(const T& x) { return(base::value(x)); } }; #endif } // namespace units } // namespace boost #endif // BOOST_UNITS_STATIC_RATIONAL_HPP