1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-24 02:21:01 +03:00

Merge branch 'develop' into feature/exceptions_3.0.0

This commit is contained in:
Niels Lohmann
2017-03-12 11:51:24 +01:00
7 changed files with 116 additions and 8 deletions

View File

@ -81,7 +81,7 @@ SOFTWARE.
#endif
// allow to disable exceptions
#if not defined(JSON_NOEXCEPTION) || defined(__EXCEPTIONS)
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && not defined(JSON_NOEXCEPTION)
#define JSON_THROW(exception) throw exception
#define JSON_TRY try
#define JSON_CATCH(exception) catch(exception)
@ -529,6 +529,19 @@ struct external_constructor<value_t::array>
j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
j.assert_invariant();
}
template<typename BasicJsonType>
static void construct(BasicJsonType& j, const std::vector<bool>& arr)
{
j.m_type = value_t::array;
j.m_value = value_t::array;
j.m_value.array->reserve(arr.size());
for (bool x : arr)
{
j.m_value.array->push_back(x);
}
j.assert_invariant();
}
};
template<>
@ -767,6 +780,12 @@ void to_json(BasicJsonType& j, UnscopedEnumType e) noexcept
external_constructor<value_t::number_integer>::construct(j, e);
}
template<typename BasicJsonType>
void to_json(BasicJsonType& j, const std::vector<bool>& e)
{
external_constructor<value_t::array>::construct(j, e);
}
template <
typename BasicJsonType, typename CompatibleArrayType,
enable_if_t <
@ -6392,6 +6411,10 @@ class basic_json
*/
class serializer
{
private:
serializer(const serializer&) = delete;
serializer& operator=(const serializer&) = delete;
public:
/*!
@param[in] s output stream to serialize to
@ -13427,6 +13450,22 @@ struct hash<nlohmann::json>
return h(j.dump());
}
};
/// specialization for std::less<value_t>
template <>
struct less<::nlohmann::detail::value_t>
{
/*!
@brief compare two value_t enum values
@since version 3.0.0
*/
bool operator()(nlohmann::detail::value_t lhs,
nlohmann::detail::value_t rhs) const noexcept
{
return nlohmann::detail::operator<(lhs, rhs);
}
};
} // namespace std
/*!