mirror of
https://github.com/nlohmann/json.git
synced 2025-07-24 02:21:01 +03:00
✨ added overload for std::vector<bool> #494
Adds a to_json function for std::vector<bool> to allow implicit conversion from bit vectors to basic_json.
This commit is contained in:
19
src/json.hpp
19
src/json.hpp
@ -324,6 +324,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<>
|
||||
@ -562,6 +575,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, std::vector<bool> e) noexcept
|
||||
{
|
||||
external_constructor<value_t::array>::construct(j, e);
|
||||
}
|
||||
|
||||
template <
|
||||
typename BasicJsonType, typename CompatibleArrayType,
|
||||
enable_if_t <
|
||||
|
Reference in New Issue
Block a user