Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Oct 26, 2023
1 parent cf0c286 commit 9915073
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions include/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ class basic_value
template <typename... args_t>
basic_value(value_type type, args_t&&... args);

template <typename collection_t,
std::enable_if_t<
std::is_constructible_v<typename basic_array<string_t>::value_type,
typename std::iterator_traits<typename collection_t::iterator>::value_type>,
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,
typename std::iterator_traits<typename map_t::iterator>::value_type>,
bool> = true>
basic_value(map_t&& map) : basic_value(basic_object<string_t>(std::forward<map_t>(map)))
{}

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

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 9915073

Please sign in to comment.