Add helper to ease disambiguation

This commit is contained in:
Martchus 2017-10-27 15:48:55 +02:00
parent ef6a91076f
commit 31c37a8ee4
1 changed files with 17 additions and 0 deletions

View File

@ -81,6 +81,23 @@ template <typename Type> Type JSONSerializable<Type>::fromJson(const std::string
return Reflector::fromJson<Type>(json.data(), json.size());
}
/*!
* \brief Helps to disambiguate when inheritance is used.
*/
template <typename Type, Traits::EnableIf<std::is_base_of<JSONSerializable<Type>, Type>>...> JSONSerializable<Type> &as(Type &serializable)
{
return static_cast<JSONSerializable<Type> &>(serializable);
}
/*!
* \brief Helps to disambiguate when inheritance is used.
*/
template <typename Type, Traits::EnableIf<std::is_base_of<JSONSerializable<Type>, Type>>...>
const JSONSerializable<Type> &as(const Type &serializable)
{
return static_cast<const JSONSerializable<Type> &>(serializable);
}
} // namespace ReflectiveRapidJSON
#endif // REFLECTIVE_RAPIDJSON_JSON_SERIALIZABLE_H