Skip to content

Commit

Permalink
Fixed variant.is<nullptr_t>()
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Jan 13, 2020
1 parent f9cfea2 commit 97e6d20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ HEAD
(No need to define `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_STD_STREAM` anymore)
* Improved decoding of UTF-16 surrogate pairs (PR #1157 by @kaysievers)
(ArduinoJson now produces standard UTF-8 instead of CESU-8)
* Fixed `variant.is<nullptr_t>()`


v6.13.0 (2019-11-01)
Expand Down
8 changes: 8 additions & 0 deletions extras/tests/MixedConfiguration/cpp11.cpp
Expand Up @@ -26,6 +26,14 @@ TEST_CASE("nullptr") {

REQUIRE(variant.isNull());
}

SECTION("JsonVariant.is<nullptr_t>()") {
variant.set(42);
REQUIRE(variant.is<nullptr_t>() == false);

variant.clear();
REQUIRE(variant.is<nullptr_t>() == true);
}
}

TEST_CASE("Issue #1120") {
Expand Down
9 changes: 9 additions & 0 deletions src/ArduinoJson/Variant/VariantRef.hpp
Expand Up @@ -91,6 +91,15 @@ class VariantRefBase {
is() const {
return variantIsObject(_data);
}
#if ARDUINOJSON_HAS_NULLPTR
//
// bool is<nullptr_t> const;
template <typename T>
FORCE_INLINE typename enable_if<is_same<T, nullptr_t>::value, bool>::type is()
const {
return variantIsNull(_data);
}
#endif

FORCE_INLINE bool isNull() const {
return variantIsNull(_data);
Expand Down

0 comments on commit 97e6d20

Please sign in to comment.