}
};
+// identity
+template <typename C>
+struct DynamicConstructor<
+ C,
+ typename std::enable_if<std::is_same<C, dynamic>::value>::type> {
+ static dynamic construct(const C& x) {
+ return x;
+ }
+};
+
// maps
-template<typename C>
-struct DynamicConstructor<C,
+template <typename C>
+struct DynamicConstructor<
+ C,
typename std::enable_if<
- dynamicconverter_detail::is_map<C>::value>::type> {
+ !std::is_same<C, dynamic>::value &&
+ dynamicconverter_detail::is_map<C>::value>::type> {
static dynamic construct(const C& x) {
dynamic d = dynamic::object;
for (auto& pair : x) {
};
// other ranges
-template<typename C>
-struct DynamicConstructor<C,
+template <typename C>
+struct DynamicConstructor<
+ C,
typename std::enable_if<
- !dynamicconverter_detail::is_map<C>::value &&
- !std::is_constructible<StringPiece, const C&>::value &&
- dynamicconverter_detail::is_range<C>::value>::type> {
+ !std::is_same<C, dynamic>::value &&
+ !dynamicconverter_detail::is_map<C>::value &&
+ !std::is_constructible<StringPiece, const C&>::value &&
+ dynamicconverter_detail::is_range<C>::value>::type> {
static dynamic construct(const C& x) {
dynamic d = dynamic::array;
for (auto& item : x) {
dynamic d2 = floatOver;
EXPECT_THROW(convertTo<float>(d2), std::range_error);
}
+
+TEST(DynamicConverter, partial_dynamics) {
+ std::vector<dynamic> c{
+ dynamic::array(2, 3, 4), dynamic::array(3, 4, 5),
+ };
+ dynamic d = dynamic::array(dynamic::array(2, 3, 4), dynamic::array(3, 4, 5));
+ EXPECT_EQ(d, toDynamic(c));
+
+ std::unordered_map<std::string, dynamic> m{{"one", 1}, {"two", 2}};
+
+ dynamic md = dynamic::object("one", 1)("two", 2);
+ EXPECT_EQ(md, toDynamic(m));
+}