diff --git a/src/ArduinoJson/Deserialization/DeserializationError.hpp b/src/ArduinoJson/Deserialization/DeserializationError.hpp index 16c52ffd..fb9e1d2f 100644 --- a/src/ArduinoJson/Deserialization/DeserializationError.hpp +++ b/src/ArduinoJson/Deserialization/DeserializationError.hpp @@ -4,7 +4,6 @@ #pragma once -#include #include #include #include @@ -15,7 +14,7 @@ namespace ARDUINOJSON_NAMESPACE { -class DeserializationError : public SafeBoolIdom { +class DeserializationError { public: enum Code { Ok, @@ -53,9 +52,9 @@ class DeserializationError : public SafeBoolIdom { return lhs != rhs._code; } - // Behaves like a bool - operator bool_type() const { - return _code != Ok ? safe_true() : safe_false(); + // Returns true if there is an error + explicit operator bool() const { + return _code != Ok; } // Returns internal enum, useful for switch statement diff --git a/src/ArduinoJson/Misc/SafeBoolIdiom.hpp b/src/ArduinoJson/Misc/SafeBoolIdiom.hpp deleted file mode 100644 index ff4bf53a..00000000 --- a/src/ArduinoJson/Misc/SafeBoolIdiom.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON -// MIT License - -#pragma once - -#include - -namespace ARDUINOJSON_NAMESPACE { - -template -class SafeBoolIdom { - protected: - typedef void (T::*bool_type)() const; - void safeBoolHelper() const {} - - static bool_type safe_true() { - return &SafeBoolIdom::safeBoolHelper; - } - - static bool_type safe_false() { - return 0; - } -}; - -} // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Strings/JsonString.hpp b/src/ArduinoJson/Strings/JsonString.hpp index 3c4cc0b4..a250248e 100644 --- a/src/ArduinoJson/Strings/JsonString.hpp +++ b/src/ArduinoJson/Strings/JsonString.hpp @@ -4,8 +4,6 @@ #pragma once -#include - #if ARDUINOJSON_ENABLE_STD_STREAM # include #endif @@ -14,7 +12,7 @@ namespace ARDUINOJSON_NAMESPACE { // A string. // https://arduinojson.org/v6/api/jsonstring/ -class JsonString : public SafeBoolIdom { +class JsonString { public: enum Ownership { Copied, Linked }; @@ -47,9 +45,9 @@ class JsonString : public SafeBoolIdom { return _size; } - // safe bool idiom - operator bool_type() const { - return _data ? safe_true() : safe_false(); + // Returns true if the string is non-null + explicit operator bool() const { + return _data != 0; } // Returns true if strings are equal.