Added a deprecation warning for as<char*>()

This commit is contained in:
Benoit Blanchon
2021-04-26 08:42:33 +02:00
parent 06fad301cb
commit 4b89878c10
6 changed files with 75 additions and 20 deletions

View File

@ -65,10 +65,17 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
}
template <typename T>
FORCE_INLINE T as() const {
FORCE_INLINE typename enable_if<!is_same<T, char*>::value, T>::type as()
const {
return getUpstreamElement().template as<T>();
}
template <typename T>
FORCE_INLINE typename enable_if<is_same<T, char*>::value, const char*>::type
DEPRECATED("Replace as<char*>() with as<const char*>()") as() const {
return as<const char*>();
}
template <typename T>
FORCE_INLINE operator T() const {
return getUpstreamElement();

View File

@ -46,20 +46,6 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
template <typename TValue>
FORCE_INLINE typename enable_if<!is_array<TValue>::value, this_type &>::type
operator=(const TValue &src) {
/********************************************************************
** THIS IS NOT A BUG IN THE LIBRARY **
** -------------------------------- **
** Get a compilation error pointing here? **
** It doesn't mean the error *is* here. **
** Often, it's because you try to assign the wrong value type. **
** **
** For example: **
** char age = 42 **
** doc["age"] = age; **
** Instead, use: **
** int8_t age = 42; **
** doc["age"] = age; **
********************************************************************/
getOrAddUpstreamMember().set(src);
return *this;
}
@ -81,9 +67,16 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
return getUpstreamMember().isNull();
}
template <typename TValue>
FORCE_INLINE TValue as() const {
return getUpstreamMember().template as<TValue>();
template <typename T>
FORCE_INLINE typename enable_if<!is_same<T, char *>::value, T>::type as()
const {
return getUpstreamMember().template as<T>();
}
template <typename T>
FORCE_INLINE typename enable_if<is_same<T, char *>::value, const char *>::type
DEPRECATED("Replace as<char*>() with as<const char*>()") as() const {
return as<const char *>();
}
template <typename T>

View File

@ -94,10 +94,17 @@ class VariantRef : public VariantRefBase<VariantData>,
}
template <typename T>
FORCE_INLINE T as() const {
FORCE_INLINE typename enable_if<!is_same<T, char *>::value, T>::type as()
const {
return Converter<T>::fromJson(*this);
}
template <typename T>
FORCE_INLINE typename enable_if<is_same<T, char *>::value, const char *>::type
DEPRECATED("Replace as<char*>() with as<const char*>()") as() const {
return as<const char *>();
}
template <typename T>
FORCE_INLINE bool is() const {
return Converter<T>::checkJson(*this);
@ -204,10 +211,17 @@ class VariantConstRef : public VariantRefBase<const VariantData>,
}
template <typename T>
FORCE_INLINE T as() const {
FORCE_INLINE typename enable_if<!is_same<T, char *>::value, T>::type as()
const {
return Converter<T>::fromJson(*this);
}
template <typename T>
FORCE_INLINE typename enable_if<is_same<T, char *>::value, const char *>::type
DEPRECATED("Replace as<char*>() with as<const char*>()") as() const {
return as<const char *>();
}
template <typename T>
FORCE_INLINE bool is() const {
return Converter<T>::checkJson(*this);