diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bea7dd92..bccd0ef23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ HEAD * `JsonString` is now stored by copy, unless specified otherwise * Replace undocumented `JsonString::Ownership` with `bool` * Rename undocumented `JsonString::isLinked()` to `isStatic()` +* Move public facing SFINAEs to template declarations > ### BREAKING CHANGES > diff --git a/src/ArduinoJson/Array/JsonArray.hpp b/src/ArduinoJson/Array/JsonArray.hpp index 565cff26f..7f02f9872 100644 --- a/src/ArduinoJson/Array/JsonArray.hpp +++ b/src/ArduinoJson/Array/JsonArray.hpp @@ -43,16 +43,18 @@ class JsonArray : public detail::VariantOperators { // Appends a new (empty) element to the array. // Returns a reference to the new element. // https://arduinojson.org/v7/api/jsonarray/add/ - template - detail::enable_if_t::value, T> add() const { + template ::value, int> = 0> + T add() const { return add().to(); } // Appends a new (null) element to the array. // Returns a reference to the new element. // https://arduinojson.org/v7/api/jsonarray/add/ - template - detail::enable_if_t::value, T> add() const { + template ::value, int> = 0> + JsonVariant add() const { return JsonVariant(detail::ArrayData::addElement(data_, resources_), resources_); } @@ -67,7 +69,7 @@ class JsonArray : public detail::VariantOperators { // Appends a value to the array. // https://arduinojson.org/v7/api/jsonarray/add/ template ::value>> + detail::enable_if_t::value, int> = 0> bool add(T* value) const { return detail::ArrayData::addValue(data_, value, resources_); } @@ -115,9 +117,9 @@ class JsonArray : public detail::VariantOperators { // Removes the element at the specified index. // https://arduinojson.org/v7/api/jsonarray/remove/ - template - detail::enable_if_t::value> remove( - const TVariant& variant) const { + template ::value, int> = 0> + void remove(const TVariant& variant) const { if (variant.template is()) remove(variant.template as()); } @@ -130,19 +132,17 @@ class JsonArray : public detail::VariantOperators { // Gets or sets the element at the specified index. // https://arduinojson.org/v7/api/jsonarray/subscript/ - template - detail::enable_if_t::value, - detail::ElementProxy> - operator[](T index) const { + template ::value, int> = 0> + detail::ElementProxy operator[](T index) const { return {*this, size_t(index)}; } // Gets or sets the element at the specified index. // https://arduinojson.org/v7/api/jsonarray/subscript/ - template - detail::enable_if_t::value, - detail::ElementProxy> - operator[](const TVariant& variant) const { + template ::value, int> = 0> + detail::ElementProxy operator[](const TVariant& variant) const { if (variant.template is()) return {*this, variant.template as()}; else diff --git a/src/ArduinoJson/Array/JsonArrayConst.hpp b/src/ArduinoJson/Array/JsonArrayConst.hpp index 6b9db1925..b05351879 100644 --- a/src/ArduinoJson/Array/JsonArrayConst.hpp +++ b/src/ArduinoJson/Array/JsonArrayConst.hpp @@ -45,9 +45,9 @@ class JsonArrayConst : public detail::VariantOperators { // Returns the element at the specified index. // https://arduinojson.org/v7/api/jsonarrayconst/subscript/ - template - detail::enable_if_t::value, JsonVariantConst> - operator[](T index) const { + template ::value, int> = 0> + JsonVariantConst operator[](T index) const { return JsonVariantConst( detail::ArrayData::getElement(data_, size_t(index), resources_), resources_); @@ -55,9 +55,9 @@ class JsonArrayConst : public detail::VariantOperators { // Returns the element at the specified index. // https://arduinojson.org/v7/api/jsonarrayconst/subscript/ - template - detail::enable_if_t::value, JsonVariantConst> - operator[](const TVariant& variant) const { + template ::value, int> = 0> + JsonVariantConst operator[](const TVariant& variant) const { if (variant.template is()) return operator[](variant.template as()); else diff --git a/src/ArduinoJson/Array/Utilities.hpp b/src/ArduinoJson/Array/Utilities.hpp index 9073468c8..200cb66b8 100644 --- a/src/ArduinoJson/Array/Utilities.hpp +++ b/src/ArduinoJson/Array/Utilities.hpp @@ -11,27 +11,26 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE // Copies a value to a JsonVariant. // This is a degenerated form of copyArray() to stop the recursion. -template -inline detail::enable_if_t::value, bool> copyArray( - const T& src, JsonVariant dst) { +template ::value, int> = 0> +inline bool copyArray(const T& src, JsonVariant dst) { return dst.set(src); } // Copies values from an array to a JsonArray or a JsonVariant. // https://arduinojson.org/v7/api/misc/copyarray/ -template -inline detail::enable_if_t< - !detail::is_base_of::value, bool> -copyArray(T (&src)[N], const TDestination& dst) { +template ::value, int> = 0> +inline bool copyArray(T (&src)[N], const TDestination& dst) { return copyArray(src, N, dst); } // Copies values from an array to a JsonArray or a JsonVariant. // https://arduinojson.org/v7/api/misc/copyarray/ -template -inline detail::enable_if_t< - !detail::is_base_of::value, bool> -copyArray(const T* src, size_t len, const TDestination& dst) { +template ::value, int> = 0> +inline bool copyArray(const T* src, size_t len, const TDestination& dst) { bool ok = true; for (size_t i = 0; i < len; i++) { ok &= copyArray(src[i], dst.template add()); @@ -62,9 +61,8 @@ inline bool copyArray(const T* src, size_t len, JsonDocument& dst) { // Copies a value from a JsonVariant. // This is a degenerated form of copyArray() to stop the recursion. -template -inline detail::enable_if_t::value, size_t> copyArray( - JsonVariantConst src, T& dst) { +template ::value, int> = 0> +inline size_t copyArray(JsonVariantConst src, T& dst) { dst = src.as(); return 1; } @@ -102,11 +100,12 @@ inline size_t copyArray(JsonVariantConst src, char (&dst)[N]) { // Copies values from a JsonDocument to an array. // https://arduinojson.org/v7/api/misc/copyarray/ -template -inline detail::enable_if_t::value && - detail::is_base_of::value, - size_t> -copyArray(const TSource& src, T& dst) { +template < + typename TSource, typename T, + detail::enable_if_t::value && + detail::is_base_of::value, + int> = 0> +inline size_t copyArray(const TSource& src, T& dst) { return copyArray(src.template as(), dst); } diff --git a/src/ArduinoJson/Deserialization/deserialize.hpp b/src/ArduinoJson/Deserialization/deserialize.hpp index a95049a3b..c1963a8fa 100644 --- a/src/ArduinoJson/Deserialization/deserialize.hpp +++ b/src/ArduinoJson/Deserialization/deserialize.hpp @@ -55,10 +55,11 @@ DeserializationError doDeserialize(TDestination&& dst, TReader reader, return err; } -template