This commit is contained in:
Niels Lohmann 2021-12-23 14:00:13 +01:00
parent 47b9b7e927
commit 253f39c03e
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
2 changed files with 26 additions and 0 deletions

View File

@ -3816,6 +3816,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
}
// see https://github.com/nlohmann/json/pull/2685#issuecomment-994015092
template<typename T, std::size_t n>
reference operator[](T * (&key)[n])
{
return operator[](static_cast<const T>(key));
}
template<typename T, std::size_t n>
const_reference operator[](T * (&key)[n]) const
{
return operator[](static_cast<const T>(key));
}
/*!
@brief access specified object element with default value

View File

@ -21383,6 +21383,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
}
// see https://github.com/nlohmann/json/pull/2685#issuecomment-994015092
template<typename T, std::size_t n>
reference operator[](T * (&key)[n])
{
return operator[](static_cast<const T>(key));
}
template<typename T, std::size_t n>
const_reference operator[](T * (&key)[n]) const
{
return operator[](static_cast<const T>(key));
}
/*!
@brief access specified object element with default value