瀏覽代碼

Fixed variant.is<nullptr_t>()

Benoit Blanchon 6 年之前
父節點
當前提交
25879466da
共有 3 個文件被更改,包括 19 次插入0 次删除
  1. 1 0
      CHANGELOG.md
  2. 8 0
      extras/tests/MixedConfiguration/cpp11.cpp
  3. 10 0
      src/ArduinoJson/Variant/VariantRef.hpp

+ 1 - 0
CHANGELOG.md

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

+ 8 - 0
extras/tests/MixedConfiguration/cpp11.cpp

@@ -26,6 +26,14 @@ TEST_CASE("nullptr") {
 
     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") {

+ 10 - 0
src/ArduinoJson/Variant/VariantRef.hpp

@@ -91,6 +91,16 @@ 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, decltype(nullptr)>::value, bool>::type
+      is() const {
+    return variantIsNull(_data);
+  }
+#endif
 
   FORCE_INLINE bool isNull() const {
     return variantIsNull(_data);