Skip to content

Commit de05814

Browse files
committed
Move public facing SFINAEs to template declarations
1 parent e33e78d commit de05814

20 files changed

+311
-304
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ HEAD
1010
* `JsonString` is now stored by copy, unless specified otherwise
1111
* Replace undocumented `JsonString::Ownership` with `bool`
1212
* Rename undocumented `JsonString::isLinked()` to `isStatic()`
13+
* Move public facing SFINAEs to template declarations
1314

1415
> ### BREAKING CHANGES
1516
>

src/ArduinoJson/Array/JsonArray.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
4343
// Appends a new (empty) element to the array.
4444
// Returns a reference to the new element.
4545
// https://arduinojson.org/v7/api/jsonarray/add/
46-
template <typename T>
47-
detail::enable_if_t<!detail::is_same<T, JsonVariant>::value, T> add() const {
46+
template <typename T, detail::enable_if_t<
47+
!detail::is_same<T, JsonVariant>::value, int> = 0>
48+
T add() const {
4849
return add<JsonVariant>().to<T>();
4950
}
5051

5152
// Appends a new (null) element to the array.
5253
// Returns a reference to the new element.
5354
// https://arduinojson.org/v7/api/jsonarray/add/
54-
template <typename T>
55-
detail::enable_if_t<detail::is_same<T, JsonVariant>::value, T> add() const {
55+
template <typename T, detail::enable_if_t<
56+
detail::is_same<T, JsonVariant>::value, int> = 0>
57+
JsonVariant add() const {
5658
return JsonVariant(detail::ArrayData::addElement(data_, resources_),
5759
resources_);
5860
}
@@ -67,7 +69,7 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
6769
// Appends a value to the array.
6870
// https://arduinojson.org/v7/api/jsonarray/add/
6971
template <typename T,
70-
typename = detail::enable_if_t<!detail::is_const<T>::value>>
72+
detail::enable_if_t<!detail::is_const<T>::value, int> = 0>
7173
bool add(T* value) const {
7274
return detail::ArrayData::addValue(data_, value, resources_);
7375
}
@@ -115,9 +117,9 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
115117

116118
// Removes the element at the specified index.
117119
// https://arduinojson.org/v7/api/jsonarray/remove/
118-
template <typename TVariant>
119-
detail::enable_if_t<detail::IsVariant<TVariant>::value> remove(
120-
const TVariant& variant) const {
120+
template <typename TVariant,
121+
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
122+
void remove(const TVariant& variant) const {
121123
if (variant.template is<size_t>())
122124
remove(variant.template as<size_t>());
123125
}
@@ -130,19 +132,17 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
130132

131133
// Gets or sets the element at the specified index.
132134
// https://arduinojson.org/v7/api/jsonarray/subscript/
133-
template <typename T>
134-
detail::enable_if_t<detail::is_integral<T>::value,
135-
detail::ElementProxy<JsonArray>>
136-
operator[](T index) const {
135+
template <typename T,
136+
detail::enable_if_t<detail::is_integral<T>::value, int> = 0>
137+
detail::ElementProxy<JsonArray> operator[](T index) const {
137138
return {*this, size_t(index)};
138139
}
139140

140141
// Gets or sets the element at the specified index.
141142
// https://arduinojson.org/v7/api/jsonarray/subscript/
142-
template <typename TVariant>
143-
detail::enable_if_t<detail::IsVariant<TVariant>::value,
144-
detail::ElementProxy<JsonArray>>
145-
operator[](const TVariant& variant) const {
143+
template <typename TVariant,
144+
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
145+
detail::ElementProxy<JsonArray> operator[](const TVariant& variant) const {
146146
if (variant.template is<size_t>())
147147
return {*this, variant.template as<size_t>()};
148148
else

src/ArduinoJson/Array/JsonArrayConst.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ class JsonArrayConst : public detail::VariantOperators<JsonArrayConst> {
4545

4646
// Returns the element at the specified index.
4747
// https://arduinojson.org/v7/api/jsonarrayconst/subscript/
48-
template <typename T>
49-
detail::enable_if_t<detail::is_integral<T>::value, JsonVariantConst>
50-
operator[](T index) const {
48+
template <typename T,
49+
detail::enable_if_t<detail::is_integral<T>::value, int> = 0>
50+
JsonVariantConst operator[](T index) const {
5151
return JsonVariantConst(
5252
detail::ArrayData::getElement(data_, size_t(index), resources_),
5353
resources_);
5454
}
5555

5656
// Returns the element at the specified index.
5757
// https://arduinojson.org/v7/api/jsonarrayconst/subscript/
58-
template <typename TVariant>
59-
detail::enable_if_t<detail::IsVariant<TVariant>::value, JsonVariantConst>
60-
operator[](const TVariant& variant) const {
58+
template <typename TVariant,
59+
detail::enable_if_t<detail::IsVariant<TVariant>::value, int> = 0>
60+
JsonVariantConst operator[](const TVariant& variant) const {
6161
if (variant.template is<size_t>())
6262
return operator[](variant.template as<size_t>());
6363
else

src/ArduinoJson/Array/Utilities.hpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,26 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
1111

1212
// Copies a value to a JsonVariant.
1313
// This is a degenerated form of copyArray() to stop the recursion.
14-
template <typename T>
15-
inline detail::enable_if_t<!detail::is_array<T>::value, bool> copyArray(
16-
const T& src, JsonVariant dst) {
14+
template <typename T, detail::enable_if_t<!detail::is_array<T>::value, int> = 0>
15+
inline bool copyArray(const T& src, JsonVariant dst) {
1716
return dst.set(src);
1817
}
1918

2019
// Copies values from an array to a JsonArray or a JsonVariant.
2120
// https://arduinojson.org/v7/api/misc/copyarray/
22-
template <typename T, size_t N, typename TDestination>
23-
inline detail::enable_if_t<
24-
!detail::is_base_of<JsonDocument, TDestination>::value, bool>
25-
copyArray(T (&src)[N], const TDestination& dst) {
21+
template <typename T, size_t N, typename TDestination,
22+
detail::enable_if_t<
23+
!detail::is_base_of<JsonDocument, TDestination>::value, int> = 0>
24+
inline bool copyArray(T (&src)[N], const TDestination& dst) {
2625
return copyArray(src, N, dst);
2726
}
2827

2928
// Copies values from an array to a JsonArray or a JsonVariant.
3029
// https://arduinojson.org/v7/api/misc/copyarray/
31-
template <typename T, typename TDestination>
32-
inline detail::enable_if_t<
33-
!detail::is_base_of<JsonDocument, TDestination>::value, bool>
34-
copyArray(const T* src, size_t len, const TDestination& dst) {
30+
template <typename T, typename TDestination,
31+
detail::enable_if_t<
32+
!detail::is_base_of<JsonDocument, TDestination>::value, int> = 0>
33+
inline bool copyArray(const T* src, size_t len, const TDestination& dst) {
3534
bool ok = true;
3635
for (size_t i = 0; i < len; i++) {
3736
ok &= copyArray(src[i], dst.template add<JsonVariant>());
@@ -62,9 +61,8 @@ inline bool copyArray(const T* src, size_t len, JsonDocument& dst) {
6261

6362
// Copies a value from a JsonVariant.
6463
// This is a degenerated form of copyArray() to stop the recursion.
65-
template <typename T>
66-
inline detail::enable_if_t<!detail::is_array<T>::value, size_t> copyArray(
67-
JsonVariantConst src, T& dst) {
64+
template <typename T, detail::enable_if_t<!detail::is_array<T>::value, int> = 0>
65+
inline size_t copyArray(JsonVariantConst src, T& dst) {
6866
dst = src.as<T>();
6967
return 1;
7068
}
@@ -102,11 +100,12 @@ inline size_t copyArray(JsonVariantConst src, char (&dst)[N]) {
102100

103101
// Copies values from a JsonDocument to an array.
104102
// https://arduinojson.org/v7/api/misc/copyarray/
105-
template <typename TSource, typename T>
106-
inline detail::enable_if_t<detail::is_array<T>::value &&
107-
detail::is_base_of<JsonDocument, TSource>::value,
108-
size_t>
109-
copyArray(const TSource& src, T& dst) {
103+
template <
104+
typename TSource, typename T,
105+
detail::enable_if_t<detail::is_array<T>::value &&
106+
detail::is_base_of<JsonDocument, TSource>::value,
107+
int> = 0>
108+
inline size_t copyArray(const TSource& src, T& dst) {
110109
return copyArray(src.template as<JsonArrayConst>(), dst);
111110
}
112111

src/ArduinoJson/Deserialization/deserialize.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ DeserializationError doDeserialize(TDestination&& dst, TReader reader,
5555
return err;
5656
}
5757

58-
template <template <typename> class TDeserializer, typename TDestination,
59-
typename TStream, typename... Args,
60-
typename = enable_if_t< // issue #1897
61-
!is_integral<typename first_or_void<Args...>::type>::value>>
58+
template <
59+
template <typename> class TDeserializer, typename TDestination,
60+
typename TStream, typename... Args,
61+
enable_if_t< // issue #1897
62+
!is_integral<typename first_or_void<Args...>::type>::value, int> = 0>
6263
DeserializationError deserialize(TDestination&& dst, TStream&& input,
6364
Args... args) {
6465
return doDeserialize<TDeserializer>(
@@ -68,7 +69,7 @@ DeserializationError deserialize(TDestination&& dst, TStream&& input,
6869

6970
template <template <typename> class TDeserializer, typename TDestination,
7071
typename TChar, typename Size, typename... Args,
71-
typename = enable_if_t<is_integral<Size>::value>>
72+
enable_if_t<is_integral<Size>::value, int> = 0>
7273
DeserializationError deserialize(TDestination&& dst, TChar* input,
7374
Size inputSize, Args... args) {
7475
return doDeserialize<TDeserializer>(dst, makeReader(input, size_t(inputSize)),

0 commit comments

Comments
 (0)