Sprout/sprout/math/float_promote.hpp

51 lines
1.4 KiB
C++
Raw Normal View History

2012-05-05 17:35:33 +09:00
#ifndef SPROUT_MATH_FLOAT_PROMOTE_HPP
#define SPROUT_MATH_FLOAT_PROMOTE_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
namespace math {
namespace detail {
2012-06-20 23:18:41 +09:00
template<typename T, typename U>
struct float_promote2
2012-05-05 17:35:33 +09:00
: public std::conditional<
2012-06-20 23:18:41 +09:00
(std::is_same<T, long double>::value || std::is_same<U, long double>::value),
std::common_type<long double>,
2012-05-05 17:35:33 +09:00
typename std::conditional<
2012-06-20 23:18:41 +09:00
(std::is_same<T, float>::value && std::is_same<U, float>::value),
float,
2012-05-05 17:35:33 +09:00
double
2012-06-20 23:18:41 +09:00
>
>::type
{
static_assert(std::is_arithmetic<U>::value, "float_promote requires arithmetic type.");
};
2012-05-05 17:35:33 +09:00
2012-06-20 23:18:41 +09:00
template<typename Current, typename Head, typename... Tail>
struct float_promote_impl
2012-05-05 17:35:33 +09:00
: public sprout::math::detail::float_promote_impl<
2012-06-20 23:18:41 +09:00
typename sprout::math::detail::float_promote2<Current, Head>::type,
Tail...
2012-05-05 17:35:33 +09:00
>
{};
2012-06-20 23:18:41 +09:00
template<typename Current, typename Head>
struct float_promote_impl<Current, Head>
: public sprout::math::detail::float_promote2<Current, Head>
{};
2012-05-05 17:35:33 +09:00
} // namespace detail
//
// float_promote
//
template<typename... Types>
struct float_promote
2012-06-20 23:18:41 +09:00
: public sprout::math::detail::float_promote_impl<
float, typename std::remove_cv<Types>::type...
2012-05-05 17:35:33 +09:00
>
{};
} // namespace math
} // namespace sprout
#endif // #ifndef SPROUT_MATH_FLOAT_PROMOTE_HPP