File indexing completed on 2025-01-18 09:36:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef BOOST_GEOMETRY_UTIL_SELECT_MOST_PRECISE_HPP
0019 #define BOOST_GEOMETRY_UTIL_SELECT_MOST_PRECISE_HPP
0020
0021
0022 #include <type_traits>
0023
0024
0025 namespace boost { namespace geometry
0026 {
0027
0028 #ifndef DOXYGEN_NO_DETAIL
0029
0030 namespace detail { namespace select_most_precise
0031 {
0032
0033
0034
0035
0036
0037
0038 template <typename T>
0039 struct type_priority
0040 : std::conditional_t
0041 <
0042 std::is_void<T>::value,
0043 std::integral_constant<int, 0>,
0044 std::conditional_t
0045 <
0046 std::is_fundamental<T>::value,
0047 std::conditional_t
0048 <
0049 std::is_floating_point<T>::value,
0050 std::integral_constant<int, 2>,
0051 std::integral_constant<int, 1>
0052 >,
0053 std::integral_constant<int, 3>
0054 >
0055 >
0056 {};
0057
0058
0059 template <typename T>
0060 struct type_size
0061 : std::integral_constant<std::size_t, sizeof(T)>
0062 {};
0063
0064 template <>
0065 struct type_size<void>
0066 : std::integral_constant<std::size_t, 0>
0067 {};
0068
0069
0070 }}
0071 #endif
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092 template <typename ...Types>
0093 struct select_most_precise
0094 {
0095 typedef void type;
0096 };
0097
0098 template <typename T>
0099 struct select_most_precise<T>
0100 {
0101 typedef T type;
0102 };
0103
0104 template <typename T1, typename T2>
0105 struct select_most_precise<T1, T2>
0106 {
0107 static const int priority1 = detail::select_most_precise::type_priority<T1>::value;
0108 static const int priority2 = detail::select_most_precise::type_priority<T2>::value;
0109 static const std::size_t size1 = detail::select_most_precise::type_size<T1>::value;
0110 static const std::size_t size2 = detail::select_most_precise::type_size<T2>::value;
0111
0112 typedef std::conditional_t
0113 <
0114 (priority1 > priority2),
0115 T1,
0116 std::conditional_t
0117 <
0118 (priority2 > priority1),
0119 T2,
0120 std::conditional_t
0121 <
0122 (priority1 == 0 || priority1 == 3),
0123 T1,
0124 std::conditional_t
0125 <
0126 (size2 > size1),
0127 T2,
0128 T1
0129 >
0130 >
0131 >
0132 > type;
0133 };
0134
0135 template <typename T1, typename T2, typename ...Types>
0136 struct select_most_precise<T1, T2, Types...>
0137 {
0138 typedef typename select_most_precise
0139 <
0140 typename select_most_precise<T1, T2>::type,
0141 typename select_most_precise<Types...>::type
0142 >::type type;
0143 };
0144
0145
0146 }}
0147
0148 #endif