Fixed variant.is<nullptr_t>()

This commit is contained in:
Benoit Blanchon
2020-01-13 20:47:43 +01:00
parent 27ec1afb7a
commit 25879466da
3 changed files with 19 additions and 0 deletions

View File

@ -13,6 +13,7 @@ HEAD
(ArduinoJson now produces standard UTF-8 instead of CESU-8) (ArduinoJson now produces standard UTF-8 instead of CESU-8)
* Added `measureJson`, `measureJsonPretty`, and `measureMsgPack` to `keywords.txt` * Added `measureJson`, `measureJsonPretty`, and `measureMsgPack` to `keywords.txt`
(This file is used for syntax highlighting in the Arduino IDE) (This file is used for syntax highlighting in the Arduino IDE)
* Fixed `variant.is<nullptr_t>()`
> ### BREAKING CHANGES > ### BREAKING CHANGES
> >

View File

@ -26,6 +26,14 @@ TEST_CASE("nullptr") {
REQUIRE(variant.isNull()); REQUIRE(variant.isNull());
} }
SECTION("JsonVariant.is<nullptr_t>()") {
variant.set(42);
REQUIRE(variant.is<std::nullptr_t>() == false);
variant.clear();
REQUIRE(variant.is<std::nullptr_t>() == true);
}
} }
TEST_CASE("Issue #1120") { TEST_CASE("Issue #1120") {

View File

@ -91,6 +91,16 @@ class VariantRefBase {
is() const { is() const {
return variantIsObject(_data); return variantIsObject(_data);
} }
#if ARDUINOJSON_HAS_NULLPTR
//
// bool is<nullptr_t> const;
template <typename T>
FORCE_INLINE
typename enable_if<is_same<T, decltype(nullptr)>::value, bool>::type
is() const {
return variantIsNull(_data);
}
#endif
FORCE_INLINE bool isNull() const { FORCE_INLINE bool isNull() const {
return variantIsNull(_data); return variantIsNull(_data);