Skip to content

Commit

Permalink
⚗️ experiment from #2685 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Dec 23, 2021
1 parent 47b9b7e commit 253f39c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 253f39c

Please sign in to comment.