Skip to content

Commit 34dd461

Browse files
committed
Remove safe bool idiom (#1820)
1 parent 8f7211a commit 34dd461

File tree

3 files changed

+8
-37
lines changed

3 files changed

+8
-37
lines changed

src/ArduinoJson/Deserialization/DeserializationError.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#pragma once
66

7-
#include <ArduinoJson/Misc/SafeBoolIdiom.hpp>
87
#include <ArduinoJson/Namespace.hpp>
98
#include <ArduinoJson/Polyfills/pgmspace_generic.hpp>
109
#include <ArduinoJson/Polyfills/preprocessor.hpp>
@@ -15,7 +14,7 @@
1514

1615
namespace ARDUINOJSON_NAMESPACE {
1716

18-
class DeserializationError : public SafeBoolIdom<DeserializationError> {
17+
class DeserializationError {
1918
public:
2019
enum Code {
2120
Ok,
@@ -53,9 +52,9 @@ class DeserializationError : public SafeBoolIdom<DeserializationError> {
5352
return lhs != rhs._code;
5453
}
5554

56-
// Behaves like a bool
57-
operator bool_type() const {
58-
return _code != Ok ? safe_true() : safe_false();
55+
// Returns true if there is an error
56+
explicit operator bool() const {
57+
return _code != Ok;
5958
}
6059

6160
// Returns internal enum, useful for switch statement

src/ArduinoJson/Misc/SafeBoolIdiom.hpp

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/ArduinoJson/Strings/JsonString.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#pragma once
66

7-
#include <ArduinoJson/Misc/SafeBoolIdiom.hpp>
8-
97
#if ARDUINOJSON_ENABLE_STD_STREAM
108
# include <ostream>
119
#endif
@@ -14,7 +12,7 @@ namespace ARDUINOJSON_NAMESPACE {
1412

1513
// A string.
1614
// https://arduinojson.org/v6/api/jsonstring/
17-
class JsonString : public SafeBoolIdom<JsonString> {
15+
class JsonString {
1816
public:
1917
enum Ownership { Copied, Linked };
2018

@@ -47,9 +45,9 @@ class JsonString : public SafeBoolIdom<JsonString> {
4745
return _size;
4846
}
4947

50-
// safe bool idiom
51-
operator bool_type() const {
52-
return _data ? safe_true() : safe_false();
48+
// Returns true if the string is non-null
49+
explicit operator bool() const {
50+
return _data != 0;
5351
}
5452

5553
// Returns true if strings are equal.

0 commit comments

Comments
 (0)