Commit e88735c8 authored by Marcus Holland-Moritz's avatar Marcus Holland-Moritz Committed by Facebook Github Bot

Handle conversion from float in toDynamic()

Summary:
This adds the necessary ConversionHelper to enable float-to-double
conversion when using `toDynamic` on any type that contains `float`.

Fixes the added test case, which previously failed to compile.

Reviewed By: yfeldblum

Differential Revision: D3525942

fbshipit-source-id: d904dde5585316ea9a15e21430e91ac4e33116b9
parent f5a9f91c
......@@ -107,14 +107,17 @@ namespace detail {
> {
typedef int64_t type;
};
template<class T>
template <>
struct ConversionHelper<float> {
typedef double type;
};
template <class T>
struct ConversionHelper<
T,
typename std::enable_if<
(!std::is_integral<T>::value || std::is_same<T,bool>::value) &&
!std::is_same<T,std::nullptr_t>::value
>::type
> {
(!std::is_integral<T>::value || std::is_same<T, bool>::value) &&
!std::is_same<T, float>::value &&
!std::is_same<T, std::nullptr_t>::value>::type> {
typedef T type;
};
template<class T>
......
......@@ -343,6 +343,12 @@ TEST(DynamicConverter, construct) {
EXPECT_EQ(d, toDynamic(c));
}
{
vector<float> c{1.0f, 2.0f, 4.0f};
dynamic d = dynamic::array(1.0, 2.0, 4.0);
EXPECT_EQ(d, toDynamic(c));
}
{
map<int, int> c { { 2, 4 }, { 3, 9 } };
dynamic d = dynamic::object(2, 4)(3, 9);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment