1
0
mirror of https://github.com/nlohmann/json synced 2024-11-09 22:20:05 +00:00

Add to_json() for std::vector<bool>::reference (#3534)

This commit is contained in:
Florian Albrechtskirchinger 2022-06-13 13:21:55 +02:00 committed by GitHub
parent af34396129
commit 9c31d54389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -272,6 +272,13 @@ inline void to_json(BasicJsonType& j, T b) noexcept
external_constructor<value_t::boolean>::construct(j, b);
}
template<typename BasicJsonType,
enable_if_t<std::is_convertible<const std::vector<bool>::reference&, typename BasicJsonType::boolean_t>::value, int> = 0>
inline void to_json(BasicJsonType& j, const std::vector<bool>::reference& b) noexcept
{
external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b));
}
template<typename BasicJsonType, typename CompatibleString,
enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
inline void to_json(BasicJsonType& j, const CompatibleString& s)

View File

@ -5253,6 +5253,13 @@ inline void to_json(BasicJsonType& j, T b) noexcept
external_constructor<value_t::boolean>::construct(j, b);
}
template<typename BasicJsonType,
enable_if_t<std::is_convertible<const std::vector<bool>::reference&, typename BasicJsonType::boolean_t>::value, int> = 0>
inline void to_json(BasicJsonType& j, const std::vector<bool>::reference& b) noexcept
{
external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b));
}
template<typename BasicJsonType, typename CompatibleString,
enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
inline void to_json(BasicJsonType& j, const CompatibleString& s)

View File

@ -474,6 +474,13 @@ TEST_CASE("constructors")
json j(false);
CHECK(j.type() == json::value_t::boolean);
}
SECTION("from std::vector<bool>::refrence")
{
std::vector<bool> v{true};
json j(v[0]);
CHECK(j.type() == json::value_t::boolean);
}
}
SECTION("create a binary (explicit)")