Просмотр исходного кода

Make error message more readable in case of an invalid conversion

Benoit Blanchon 1 год назад
Родитель
Сommit
f99b2d63f9
1 измененных файлов с 7 добавлено и 8 удалено
  1. 7 8
      src/ArduinoJson/Variant/JsonVariantConst.hpp

+ 7 - 8
src/ArduinoJson/Variant/JsonVariantConst.hpp

@@ -67,17 +67,16 @@ class JsonVariantConst : public detail::VariantTag,
 
   // Casts the value to the specified type.
   // https://arduinojson.org/v7/api/jsonvariantconst/as/
-  template <typename T>
-  detail::enable_if_t<ConversionSupported<T>::value, T> as() const {
+  template <typename T,
+            detail::enable_if_t<ConversionSupported<T>::value, bool> = true>
+  T as() const {
     return Converter<T>::fromJson(*this);
   }
 
-  // Casts the value to the specified type.
-  // https://arduinojson.org/v7/api/jsonvariantconst/as/
-  template <typename T>
-  detail::enable_if_t<!ConversionSupported<T>::value,
-                      detail::InvalidConversion<JsonVariantConst, T>>
-  as() const;
+  // Invalid conversion. Will not compile.
+  template <typename T,
+            detail::enable_if_t<!ConversionSupported<T>::value, bool> = true>
+  detail::InvalidConversion<JsonVariantConst, T> as() const;
 
   // Returns true if the value is of the specified type.
   // https://arduinojson.org/v7/api/jsonvariantconst/is/