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
> {
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
- > {
+ T,
+ typename std::enable_if<
+ (!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>
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);