Skip to content

Commit

Permalink
Use int for all SFINAE
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Dec 23, 2024
1 parent 166330b commit b3ca892
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/ArduinoJson/Array/JsonArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
// Returns a reference to the new element.
// https://arduinojson.org/v7/api/jsonarray/add/
template <typename T, detail::enable_if_t<
detail::is_same<T, JsonVariant>::value, short> = 0>
detail::is_same<T, JsonVariant>::value, int> = 0>
JsonVariant add() const {
return JsonVariant(detail::ArrayData::addElement(data_, resources_),
resources_);
Expand Down Expand Up @@ -141,7 +141,7 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
// Gets or sets the element at the specified index.
// https://arduinojson.org/v7/api/jsonarray/subscript/
template <typename TVariant,
detail::enable_if_t<detail::IsVariant<TVariant>::value, short> = 0>
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
detail::ElementProxy<JsonArray> operator[](const TVariant& variant) const {
if (variant.template is<size_t>())
return {*this, variant.template as<size_t>()};
Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoJson/Array/JsonArrayConst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class JsonArrayConst : public detail::VariantOperators<JsonArrayConst> {
// Returns the element at the specified index.
// https://arduinojson.org/v7/api/jsonarrayconst/subscript/
template <typename TVariant,
detail::enable_if_t<detail::IsVariant<TVariant>::value, short> = 0>
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
JsonVariantConst operator[](const TVariant& variant) const {
if (variant.template is<size_t>())
return operator[](variant.template as<size_t>());
Expand Down
8 changes: 4 additions & 4 deletions src/ArduinoJson/Document/JsonDocument.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
// DEPRECATED: use obj[key].is<T>() instead
// https://arduinojson.org/v7/api/jsondocument/containskey/
template <typename TVariant,
detail::enable_if_t<detail::IsVariant<TVariant>::value, short> = 0>
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
ARDUINOJSON_DEPRECATED("use doc[key].is<T>() instead")
bool containsKey(const TVariant& key) const {
return containsKey(key.template as<const char*>());
Expand Down Expand Up @@ -239,7 +239,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
// Gets or sets a root object's member.
// https://arduinojson.org/v7/api/jsondocument/subscript/
template <typename TVariant,
detail::enable_if_t<detail::IsVariant<TVariant>::value, short> = 0>
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
JsonVariantConst operator[](const TVariant& key) const {
if (key.template is<JsonString>())
return operator[](key.template as<JsonString>());
Expand All @@ -261,7 +261,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
// Returns a reference to the new element.
// https://arduinojson.org/v7/api/jsondocument/add/
template <typename T, detail::enable_if_t<
detail::is_same<T, JsonVariant>::value, short> = 0>
detail::is_same<T, JsonVariant>::value, int> = 0>
JsonVariant add() {
return JsonVariant(data_.addElement(&resources_), &resources_);
}
Expand Down Expand Up @@ -312,7 +312,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
// Removes a member of the root object or an element of the root array.
// https://arduinojson.org/v7/api/jsondocument/remove/
template <typename TVariant,
detail::enable_if_t<detail::IsVariant<TVariant>::value, short> = 0>
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
void remove(const TVariant& key) {
if (key.template is<const char*>())
remove(key.template as<const char*>());
Expand Down
4 changes: 2 additions & 2 deletions src/ArduinoJson/Object/JsonObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
// Removes the member with the specified key.
// https://arduinojson.org/v7/api/jsonobject/remove/
template <typename TVariant,
detail::enable_if_t<detail::IsVariant<TVariant>::value, short> = 0>
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
void remove(const TVariant& key) const {
if (key.template is<const char*>())
remove(key.template as<const char*>());
Expand Down Expand Up @@ -174,7 +174,7 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
template <typename TChar,
detail::enable_if_t<detail::IsString<TChar*>::value &&
!detail::is_const<TChar>::value,
short> = 0>
int> = 0>
ARDUINOJSON_DEPRECATED("use obj[\"key\"].is<T>() instead")
bool containsKey(TChar* key) const {
return detail::ObjectData::getMember(data_, detail::adaptString(key),
Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoJson/Object/JsonObjectConst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
// DEPRECATED: use obj[key].is<T>() instead
// https://arduinojson.org/v7/api/jsonobjectconst/containskey/
template <typename TVariant,
detail::enable_if_t<detail::IsVariant<TVariant>::value, short> = 0>
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
ARDUINOJSON_DEPRECATED("use obj[key].is<T>() instead")
bool containsKey(const TVariant& key) const {
return containsKey(key.template as<const char*>());
Expand Down
6 changes: 3 additions & 3 deletions src/ArduinoJson/Variant/JsonVariantConst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class JsonVariantConst : public detail::VariantTag,
// Always returns false for the unsupported types.
// https://arduinojson.org/v7/api/jsonvariantconst/is/
template <typename T,
detail::enable_if_t<!ConversionSupported<T>::value, short> = 0>
detail::enable_if_t<!ConversionSupported<T>::value, int> = 0>
bool is() const {
return false;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ class JsonVariantConst : public detail::VariantTag,
// specified index.
// https://arduinojson.org/v7/api/jsonvariantconst/subscript/
template <typename TVariant,
detail::enable_if_t<detail::IsVariant<TVariant>::value, short> = 0>
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
JsonVariantConst operator[](const TVariant& key) const {
if (key.template is<size_t>())
return operator[](key.template as<size_t>());
Expand Down Expand Up @@ -168,7 +168,7 @@ class JsonVariantConst : public detail::VariantTag,
// DEPRECATED: use obj[key].is<T>() instead
// https://arduinojson.org/v7/api/jsonvariantconst/containskey/
template <typename TVariant,
detail::enable_if_t<detail::IsVariant<TVariant>::value, short> = 0>
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
ARDUINOJSON_DEPRECATED("use var[key].is<T>() instead")
bool containsKey(const TVariant& key) const {
return containsKey(key.template as<const char*>());
Expand Down
17 changes: 8 additions & 9 deletions src/ArduinoJson/Variant/VariantRefBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class VariantRefBase : public VariantTag {

// Sets the value to an empty array.
// https://arduinojson.org/v7/api/jsonvariant/to/
template <typename T, enable_if_t<is_same<T, JsonArray>::value, long> = 0>
template <typename T, enable_if_t<is_same<T, JsonArray>::value, int> = 0>
JsonArray to() const;

// Sets the value to an empty object.
// https://arduinojson.org/v7/api/jsonvariant/to/
template <typename T, enable_if_t<is_same<T, JsonObject>::value, short> = 0>
template <typename T, enable_if_t<is_same<T, JsonObject>::value, int> = 0>
JsonObject to() const;

// Sets the value to null.
Expand Down Expand Up @@ -113,7 +113,7 @@ class VariantRefBase : public VariantTag {
// Appends a new (null) element to the array.
// Returns a reference to the new element.
// https://arduinojson.org/v7/api/jsonvariant/add/
template <typename T, enable_if_t<is_same<T, JsonVariant>::value, short> = 0>
template <typename T, enable_if_t<is_same<T, JsonVariant>::value, int> = 0>
T add() const;

// Appends a value to the array.
Expand Down Expand Up @@ -156,8 +156,7 @@ class VariantRefBase : public VariantTag {

// Removes a member of the object or an element of the array.
// https://arduinojson.org/v7/api/jsonvariant/remove/
template <typename TVariant,
enable_if_t<IsVariant<TVariant>::value, short> = 0>
template <typename TVariant, enable_if_t<IsVariant<TVariant>::value, int> = 0>
void remove(const TVariant& key) const {
if (key.template is<size_t>())
remove(key.template as<size_t>());
Expand All @@ -177,7 +176,7 @@ class VariantRefBase : public VariantTag {

// DEPRECATED: use obj["key"].is<T>() instead
// https://arduinojson.org/v7/api/jsonvariant/containskey/
template <typename TChar, enable_if_t<IsString<TChar*>::value, short> = 0>
template <typename TChar, enable_if_t<IsString<TChar*>::value, int> = 0>
ARDUINOJSON_DEPRECATED("use obj[\"key\"].is<T>() instead")
bool containsKey(TChar* key) const;

Expand All @@ -196,9 +195,9 @@ class VariantRefBase : public VariantTag {

// Gets or sets an object member.
// https://arduinojson.org/v7/api/jsonvariant/subscript/
template <typename TChar,
enable_if_t<IsString<TChar*>::value && !is_const<TChar>::value,
short> = 0>
template <
typename TChar,
enable_if_t<IsString<TChar*>::value && !is_const<TChar>::value, int> = 0>
FORCE_INLINE MemberProxy<TDerived, AdaptedString<TChar*>> operator[](
TChar* key) const;

Expand Down
13 changes: 6 additions & 7 deletions src/ArduinoJson/Variant/VariantRefBaseImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ inline void convertToJson(const VariantRefBase<TDerived>& src,
}

template <typename TDerived>
template <typename T, enable_if_t<is_same<T, JsonVariant>::value, short>>
template <typename T, enable_if_t<is_same<T, JsonVariant>::value, int>>
inline T VariantRefBase<TDerived>::add() const {
return JsonVariant(
detail::VariantData::addElement(getOrCreateData(), getResourceManager()),
Expand All @@ -82,7 +82,7 @@ inline bool VariantRefBase<TDerived>::containsKey(const TString& key) const {
}

template <typename TDerived>
template <typename TChar, enable_if_t<IsString<TChar*>::value, short>>
template <typename TChar, enable_if_t<IsString<TChar*>::value, int>>
inline bool VariantRefBase<TDerived>::containsKey(TChar* key) const {
return VariantData::getMember(getData(), adaptString(key),
getResourceManager()) != 0;
Expand Down Expand Up @@ -119,9 +119,8 @@ inline ElementProxy<TDerived> VariantRefBase<TDerived>::operator[](
}

template <typename TDerived>
template <
typename TChar,
enable_if_t<IsString<TChar*>::value && !is_const<TChar>::value, short>>
template <typename TChar,
enable_if_t<IsString<TChar*>::value && !is_const<TChar>::value, int>>
inline MemberProxy<TDerived, AdaptedString<TChar*>>
VariantRefBase<TDerived>::operator[](TChar* key) const {
return {derived(), adaptString(key)};
Expand Down Expand Up @@ -149,15 +148,15 @@ inline bool VariantRefBase<TDerived>::doSet(const T& value, true_type) const {
}

template <typename TDerived>
template <typename T, enable_if_t<is_same<T, JsonArray>::value, long>>
template <typename T, enable_if_t<is_same<T, JsonArray>::value, int>>
inline JsonArray VariantRefBase<TDerived>::to() const {
return JsonArray(
VariantData::toArray(getOrCreateData(), getResourceManager()),
getResourceManager());
}

template <typename TDerived>
template <typename T, enable_if_t<is_same<T, JsonObject>::value, short>>
template <typename T, enable_if_t<is_same<T, JsonObject>::value, int>>
JsonObject VariantRefBase<TDerived>::to() const {
return JsonObject(
VariantData::toObject(getOrCreateData(), getResourceManager()),
Expand Down

0 comments on commit b3ca892

Please sign in to comment.