DxLibEx
float_promote.hpp
Go to the documentation of this file.
1 /*=============================================================================
2  Copyright (C) 2015-2017 DxLibEx project
3  https://github.com/Nagarei/DxLibEx/
4 
5  Distributed under the Boost Software License, Version 1.0.
6  (See http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #ifndef DXLE_TYPE_TRAITS_FLOAT_PROMOTE_HPP
9 #define DXLE_TYPE_TRAITS_FLOAT_PROMOTE_HPP
10 
11 #include <type_traits>
12 #include "dxlibex/config/defines.h"
14 
15 namespace dxle {
17 namespace type_traits {
18  namespace detail {
19  template<typename T> struct float_promote1 : public std::conditional<std::is_floating_point<T>::value, T, double>
20  {
21  static_assert(
22  std::is_arithmetic<T>::value,
23  "float_promote requires arithmetic type."
24  );
25  };
26  template<typename T, typename U, bool is_arithmetic = std::is_arithmetic<T>::value && std::is_arithmetic<U>::value>
27  struct float_promote2 {
28  static_assert(
29  std::is_arithmetic<T>::value && std::is_arithmetic<U>::value,
30  "float_promote requires arithmetic type."
31  );
32  };
33  template<typename T, typename U>
34  struct float_promote2<T, U, true>
35  {
36  using type = first_enabled_t<
37  enable_if<(std::is_same<T, long double>::value || std::is_same<U, long double>::value), long double>,
38  enable_if<(std::is_same<T, float>::value && std::is_same<U, float>::value), float>,
39  double
40  >;
41  };
42 
43  template<typename... Types> struct float_promote_impl;
44  template<typename T, typename U, typename... Tail>
45  struct float_promote_impl<T, U, Tail...>
47  typename dxle::type_traits::detail::float_promote2<T, U>::type,
48  Tail...
49  >
50  {};
51  template<typename T>
54  {};
55  } // namespace detail
56 
57  //
58  // float_promote
59  //
60  template<typename... Types>
63  typename std::remove_cv<Types>::type...
64  >
65  {};
66 
67  template<typename... Types>
68  using float_promote_t = typename dxle::float_promote<Types...>::type;
69 }//namespace
70 using namespace type_traits;
71 } // namespace dxle
72 
73 #endif // #ifndef DXLE_TYPE_TRAITS_FLOAT_PROMOTE_HPP
typename dxle::float_promote< Types... >::type float_promote_t
Definition: cast_if.hpp:12
first_enabled_t< enable_if<(std::is_same< T, long double >::value||std::is_same< U, long double >::value), long double >, enable_if<(std::is_same< T, float >::value &&std::is_same< U, float >::value), float >, double > type
typename first_enabled< Args... >::type first_enabled_t