Fixed operator|(MemberProxy, JsonObject) (fixes #1415)

This commit is contained in:
Benoit Blanchon
2020-10-23 10:22:14 +02:00
parent ff66182dc6
commit 10ec0f21b0
7 changed files with 50 additions and 8 deletions

View File

@@ -9,6 +9,7 @@
#include <ArduinoJson/Polyfills/attributes.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Variant/VariantAs.hpp>
#include <ArduinoJson/Variant/VariantTag.hpp>
namespace ARDUINOJSON_NAMESPACE {
@@ -17,15 +18,24 @@ CompareResult compare(const T1 &lhs, const T2 &rhs); // VariantCompare.cpp
template <typename TVariant>
struct VariantOperators {
// Returns the default value if the VariantRef is undefined of incompatible
// Returns the default value if the VariantRef is undefined or incompatible
template <typename T>
friend typename enable_if<!IsVisitable<T>::value, T>::type operator|(
friend typename enable_if<!IsVariant<T>::value, T>::type operator|(
const TVariant &variant, T defaultValue) {
if (variant.template is<T>())
return variant.template as<T>();
else
return defaultValue;
}
// Returns the default value if the VariantRef is undefined or incompatible
template <typename T>
friend typename enable_if<IsVariant<T>::value, typename T::variant_type>::type
operator|(const TVariant &variant, T defaultValue) {
if (variant)
return variant;
else
return defaultValue;
}
// value == TVariant
template <typename T>