Skip to content

Commit

Permalink
chore: loose -> stream
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Oct 20, 2023
1 parent f3fcfeb commit b75252f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions include/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ namespace literals
template <typename string_t = default_string_t>
const basic_value<string_t> invalid_value();

template <bool loose, typename any_t, typename string_t = default_string_t>
template <bool stream, typename any_t, typename string_t = default_string_t>
basic_value<string_t> serialize(any_t&& arg);

// ******************************
Expand Down Expand Up @@ -2576,13 +2576,13 @@ namespace _serialization_helper
return std::move(os).str();
}

template <bool loose, typename input_t, typename string_t>
template <bool stream, typename input_t, typename string_t>
MEOJSON_INLINE string_t to_string(input_t&& arg)
{
if constexpr (std::is_constructible_v<string_t, input_t>) {
return arg;
}
else if constexpr (loose) {
else if constexpr (stream) {
return to_stream_string<input_t, string_t>(std::forward<input_t>(arg));
}
else {
Expand All @@ -2591,7 +2591,7 @@ namespace _serialization_helper
}
}

template <bool loose, typename any_t, typename string_t>
template <bool stream, typename any_t, typename string_t>
MEOJSON_INLINE basic_value<string_t> serialize(any_t&& arg)
{
using namespace _serialization_helper;
Expand All @@ -2610,7 +2610,7 @@ MEOJSON_INLINE basic_value<string_t> serialize(any_t&& arg)
for (auto&& val : arg) {
using value_t = decltype(val);

result.emplace(serialize<loose, value_t, string_t>(std::forward<value_t>(val)));
result.emplace(serialize<stream, value_t, string_t>(std::forward<value_t>(val)));
}
return result;
}
Expand All @@ -2620,13 +2620,13 @@ MEOJSON_INLINE basic_value<string_t> serialize(any_t&& arg)
using key_t = decltype(key);
using value_t = decltype(val);

result.emplace(to_string<loose, key_t, string_t>(std::forward<key_t>(key)),
serialize<loose, value_t, string_t>(std::forward<value_t>(val)));
result.emplace(to_string<stream, key_t, string_t>(std::forward<key_t>(key)),
serialize<stream, value_t, string_t>(std::forward<value_t>(val)));
}
return result;
}
else {
return to_string<loose, any_t, string_t>(std::forward<any_t>(arg));
return to_string<stream, any_t, string_t>(std::forward<any_t>(arg));
}
}

Expand Down
2 changes: 1 addition & 1 deletion sample/sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ bool serializing()
{ "key2", { { 3, { 0.4 } }, { 4, { 0.5, 0.6, 0.7 } } } },
};
// the "std::map<int, xxx>" cannot be converted to json because the key is "int",
// you can set the template parameter "loose" of "serialize" to true, which will make a more relaxed conversion.
// you can set the template parameter "stream" of "serialize" to true, which will make a more relaxed conversion.
root["more_complex"] = json::serialize<true>(more_complex);

// for test
Expand Down

0 comments on commit b75252f

Please sign in to comment.