Skip to content

Commit

Permalink
feat: #25 (#30)
Browse files Browse the repository at this point in the history
Co-authored-by: zzyyyl <[email protected]>

fix #25
  • Loading branch information
MistEO authored Oct 26, 2023
1 parent cf0c286 commit 59f6d44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 13 additions & 1 deletion include/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,19 @@ class basic_value
template <typename... args_t>
basic_value(value_type type, args_t&&... args);

template <typename value_t, typename _ = std::enable_if_t<!std::is_convertible_v<value_t, basic_value<string_t>>>>
template <typename collection_t,
std::enable_if_t<std::is_constructible_v<typename basic_array<string_t>::value_type,
utils::range_value_t<collection_t>>,
bool> = true>
basic_value(collection_t&& collection) : basic_value(basic_array<string_t>(std::forward<collection_t>(collection)))
{}
template <typename map_t, std::enable_if_t<std::is_constructible_v<typename basic_object<string_t>::value_type,
utils::range_value_t<map_t>>,
bool> = true>
basic_value(map_t&& map) : basic_value(basic_object<string_t>(std::forward<map_t>(map)))
{}

template <typename value_t, std::enable_if_t<!std::is_convertible_v<value_t, basic_value<string_t>>, bool> = true>
basic_value(value_t) = delete;

// I don't know if you want to convert char to string or number, so I delete these constructors.
Expand Down
6 changes: 3 additions & 3 deletions sample/sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,16 @@ bool serializing()
root["arr"] += json::array { 6, 7 };

std::vector<int> vec = { 1, 2, 3, 4, 5 };
root["arr from vec"] = json::array(vec);
root["arr from vec"] = vec;

std::set<std::string> set = { "a", "bb\n\nb", "cc\t" };
root["arr from set"] = json::array(set);
root["arr from set"] = set;

std::map<std::string, int> map {
{ "key1", 1 },
{ "key2", 2 },
};
root["obj from map"] = json::object(map);
root["obj from map"] = map;

std::vector<std::list<std::set<int>>> complex { { { 1, 2, 3 }, { 4, 5 } }, { { 6 }, { 7, 8 } } };
root["complex"] = json::serialize<false>(complex);
Expand Down

0 comments on commit 59f6d44

Please sign in to comment.