Renamed template parameter and added some comments.

This commit is contained in:
Anthony VH 2021-01-09 17:45:56 +01:00
parent 1e825e4f92
commit c0a8b45bbb
3 changed files with 54 additions and 22 deletions

View File

@ -19,23 +19,37 @@ struct adl_serializer
This function is usually called by the `get()` function of the
@ref basic_json class (either explicit or via conversion operators).
@note This function is chosen for value types which can be default constructed.
@param[in] j JSON value to read from
@param[in,out] val value to write to
*/
template<typename BasicJsonType, typename U = ValueType>
static auto from_json(BasicJsonType && j, U& val) noexcept(
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
{
::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
}
template<typename BasicJsonType, typename U = ValueType>
/*!
@brief convert a JSON value to any value type
This function is usually called by the `get()` function of the
@ref basic_json class (either explicit or via conversion operators).
@note This function is chosen for value types which can not be default constructed.
@param[in] j JSON value to read from
@return copy of the JSON value, converted to @a ValueType
*/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<U> {})))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<U> {}))
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<TargetType> {})))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<TargetType> {}))
{
return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<U> {});
return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<TargetType> {});
}
/*!
@ -47,12 +61,12 @@ struct adl_serializer
@param[in,out] j JSON value to write to
@param[in] val value to read from
*/
template<typename BasicJsonType, typename U = ValueType>
static auto to_json(BasicJsonType& j, U && val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<U>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<U>(val)), void())
template<typename BasicJsonType, typename TargetType = ValueType>
static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
{
::nlohmann::to_json(j, std::forward<U>(val));
::nlohmann::to_json(j, std::forward<TargetType>(val));
}
};
} // namespace nlohmann

View File

@ -462,6 +462,8 @@ struct from_json_fn
return from_json(j, val);
}
// overload to pass calls to built-in from_json functions for non-default constructible STL
// types (e.g. std::array<X>, where X is not default constructible).
template<typename BasicJsonType, typename T>
auto operator()(const BasicJsonType& j, detail::tag<T> t) const
noexcept(noexcept(from_json(j, t)))

View File

@ -3959,6 +3959,8 @@ struct from_json_fn
return from_json(j, val);
}
// overload to pass calls to built-in from_json functions for non-default constructible STL
// types (e.g. std::array<X>, where X is not default constructible).
template<typename BasicJsonType, typename T>
auto operator()(const BasicJsonType& j, detail::tag<T> t) const
noexcept(noexcept(from_json(j, t)))
@ -4553,23 +4555,37 @@ struct adl_serializer
This function is usually called by the `get()` function of the
@ref basic_json class (either explicit or via conversion operators).
@note This function is chosen for value types which can be default constructed.
@param[in] j JSON value to read from
@param[in,out] val value to write to
*/
template<typename BasicJsonType, typename U = ValueType>
static auto from_json(BasicJsonType && j, U& val) noexcept(
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
{
::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
}
template<typename BasicJsonType, typename U = ValueType>
/*!
@brief convert a JSON value to any value type
This function is usually called by the `get()` function of the
@ref basic_json class (either explicit or via conversion operators).
@note This function is chosen for value types which can not be default constructed.
@param[in] j JSON value to read from
@return copy of the JSON value, converted to @a ValueType
*/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<U> {})))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<U> {}))
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<TargetType> {})))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<TargetType> {}))
{
return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<U> {});
return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::tag<TargetType> {});
}
/*!
@ -4581,12 +4597,12 @@ struct adl_serializer
@param[in,out] j JSON value to write to
@param[in] val value to read from
*/
template<typename BasicJsonType, typename U = ValueType>
static auto to_json(BasicJsonType& j, U && val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<U>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<U>(val)), void())
template<typename BasicJsonType, typename TargetType = ValueType>
static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
{
::nlohmann::to_json(j, std::forward<U>(val));
::nlohmann::to_json(j, std::forward<TargetType>(val));
}
};
} // namespace nlohmann