From 253f39c03e529c240a3af8b37c6bbc3b7dc9f268 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 23 Dec 2021 14:00:13 +0100 Subject: [PATCH] :alembic: experiment from https://github.com/nlohmann/json/pull/2685#issuecomment-994015092 --- include/nlohmann/json.hpp | 13 +++++++++++++ single_include/nlohmann/json.hpp | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index cb1f2251e..7361e3608 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -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 + reference operator[](T * (&key)[n]) + { + return operator[](static_cast(key)); + } + + template + const_reference operator[](T * (&key)[n]) const + { + return operator[](static_cast(key)); + } + /*! @brief access specified object element with default value diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 9ff85b2d8..e4e397565 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -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 + reference operator[](T * (&key)[n]) + { + return operator[](static_cast(key)); + } + + template + const_reference operator[](T * (&key)[n]) const + { + return operator[](static_cast(key)); + } + /*! @brief access specified object element with default value