mirror of
https://github.com/nlohmann/json.git
synced 2024-11-27 16:49:02 +08:00
Fix 'const' qualifier on bool& has no effect (#3678)
* Fix 'const' qualifier on bool& has no effect Thanks, @georgthegreat, for pointing out this issue. * Extend std::vector<bool> unit test
This commit is contained in:
parent
bfbe774d8f
commit
f1e34070d2
@ -267,9 +267,15 @@ 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
|
||||
template < typename BasicJsonType, typename BoolRef,
|
||||
enable_if_t <
|
||||
((std::is_same<std::vector<bool>::reference, BoolRef>::value
|
||||
&& !std::is_same <std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value)
|
||||
|| (std::is_same<std::vector<bool>::const_reference, BoolRef>::value
|
||||
&& !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>,
|
||||
typename BasicJsonType::boolean_t >::value))
|
||||
&& std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value, int > = 0 >
|
||||
inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept
|
||||
{
|
||||
external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b));
|
||||
}
|
||||
|
@ -5500,9 +5500,15 @@ 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
|
||||
template < typename BasicJsonType, typename BoolRef,
|
||||
enable_if_t <
|
||||
((std::is_same<std::vector<bool>::reference, BoolRef>::value
|
||||
&& !std::is_same <std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value)
|
||||
|| (std::is_same<std::vector<bool>::const_reference, BoolRef>::value
|
||||
&& !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>,
|
||||
typename BasicJsonType::boolean_t >::value))
|
||||
&& std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value, int > = 0 >
|
||||
inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept
|
||||
{
|
||||
external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b));
|
||||
}
|
||||
|
@ -454,10 +454,19 @@ TEST_CASE("constructors")
|
||||
CHECK(j.type() == json::value_t::boolean);
|
||||
}
|
||||
|
||||
SECTION("from std::vector<bool>::refrence")
|
||||
SECTION("from std::vector<bool>::reference")
|
||||
{
|
||||
std::vector<bool> v{true};
|
||||
json j(v[0]);
|
||||
CHECK(std::is_same<decltype(v[0]), std::vector<bool>::reference>::value);
|
||||
CHECK(j.type() == json::value_t::boolean);
|
||||
}
|
||||
|
||||
SECTION("from std::vector<bool>::const_reference")
|
||||
{
|
||||
const std::vector<bool> v{true};
|
||||
json j(v[0]);
|
||||
CHECK(std::is_same<decltype(v[0]), std::vector<bool>::const_reference>::value);
|
||||
CHECK(j.type() == json::value_t::boolean);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user