Skip to content

Commit e7e163b

Browse files
author
Hoyt Koepke
committed
Clarified some of the conversion paths in the flexible_type converter.
1 parent c452434 commit e7e163b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

oss_src/flexible_type/flexible_type_converter.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ template <> struct ft_converter<3> {
120120
if(static_cast<Integer>(v) != v) {
121121
throw_type_conversion_error(src, "integer / convertable float");
122122
}
123+
dest = static_cast<Integer>(v);
123124
} else if(src.get_type() == flex_type_enum::INTEGER) {
124125
dest = static_cast<Integer>(src.get<flex_int>());
125126
} else {
@@ -133,6 +134,7 @@ template <> struct ft_converter<3> {
133134
}
134135
};
135136

137+
136138
////////////////////////////////////////////////////////////////////////////////
137139

138140
/** Any sequence containers (vectors, lists, deques, etc.) of floating
@@ -233,7 +235,11 @@ template <> struct ft_converter<6> {
233235

234236
////////////////////////////////////////////////////////////////////////////////
235237

236-
/** Any pairs of numeric values.
238+
/** Any pairs of numeric values. This is different from the case below
239+
* since this allows the the std::pair to convert to and from a
240+
* 2-element flex_vec if the types in the std::pair are numeric.
241+
* Internally, the logic is the same as the case below if they are
242+
* not strictly doubles.
237243
*/
238244
template <> struct ft_converter<7> {
239245

@@ -242,8 +248,10 @@ template <> struct ft_converter<7> {
242248
typedef typename second_nested_type<T>::type U2;
243249

244250
return (is_std_pair<T>::value
245-
&& std::is_arithmetic<U1>::value
246-
&& std::is_arithmetic<U1>::value);
251+
&& std::is_convertible<double, U1>::value
252+
&& std::is_convertible<U1, double>::value
253+
&& std::is_convertible<double, U2>::value
254+
&& std::is_convertible<U2, double>::value);
247255
}
248256

249257
template <typename T, typename U>
@@ -269,7 +277,11 @@ template <> struct ft_converter<7> {
269277

270278
template <typename T, typename U>
271279
static void set(flexible_type& dest, const std::pair<T,U>& src) {
272-
dest = flex_vec{flex_float(src.first), flex_float(src.second)};
280+
if(std::is_floating_point<T>::value && std::is_floating_point<U>::value) {
281+
dest = flex_vec{flex_float(src.first), flex_float(src.second)};
282+
} else {
283+
dest = flex_list{convert_to_flexible_type(src.first), convert_to_flexible_type(src.second)};
284+
}
273285
}
274286
};
275287

0 commit comments

Comments
 (0)