Skip to content

Commit

Permalink
Const array
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Jan 23, 2019
1 parent 021be1b commit 1d01a60
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ArduinoJson/Document/JsonDocument.hpp
Expand Up @@ -119,6 +119,10 @@ class JsonDocument : public Visitable {
return getVariant()[index];
}

FORCE_INLINE VariantConstRef operator[](size_t index) const {
return getVariant()[index];
}

protected:
JsonDocument(MemoryPool pool) : _pool(pool) {
_data.setNull();
Expand Down
1 change: 1 addition & 0 deletions test/JsonDocument/subscript.cpp
Expand Up @@ -27,5 +27,6 @@ TEST_CASE("JsonDocument::operator[]") {
deserializeJson(doc, "[\"hello\",\"world\"]");

REQUIRE(doc[1] == "world");
REQUIRE(cdoc[1] == "world");
}
}

0 comments on commit 1d01a60

Please sign in to comment.