make from_json SFINAE-correct
This commit is contained in:
parent
f7971f04a5
commit
4b4bbceebf
4 changed files with 16 additions and 56 deletions
|
@ -20,8 +20,10 @@ struct adl_serializer
|
|||
@param[in,out] val value to write to
|
||||
*/
|
||||
template<typename BasicJsonType, typename ValueType>
|
||||
static void from_json(BasicJsonType&& j, ValueType& val) noexcept(
|
||||
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
|
||||
static auto from_json(BasicJsonType&& j, ValueType& 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);
|
||||
}
|
||||
|
|
|
@ -350,35 +350,13 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
|
|||
|
||||
struct from_json_fn
|
||||
{
|
||||
private:
|
||||
template<typename BasicJsonType, typename T>
|
||||
auto call(const BasicJsonType& j, T& val, priority_tag<1> /*unused*/) const
|
||||
auto operator()(const BasicJsonType& j, T& val) const
|
||||
noexcept(noexcept(from_json(j, val)))
|
||||
-> decltype(from_json(j, val), void())
|
||||
{
|
||||
return from_json(j, val);
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename T>
|
||||
void call(const BasicJsonType& /*unused*/, T& /*unused*/, priority_tag<0> /*unused*/) const noexcept
|
||||
{
|
||||
static_assert(sizeof(BasicJsonType) == 0,
|
||||
"could not find from_json() method in T's namespace");
|
||||
#ifdef _MSC_VER
|
||||
// MSVC does not show a stacktrace for the above assert
|
||||
using decayed = uncvref_t<T>;
|
||||
static_assert(sizeof(typename decayed::force_msvc_stacktrace) == 0,
|
||||
"forcing MSVC stacktrace to show which T we're talking about.");
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
template<typename BasicJsonType, typename T>
|
||||
void operator()(const BasicJsonType& j, T& val) const
|
||||
noexcept(noexcept(std::declval<from_json_fn>().call(j, val, priority_tag<1> {})))
|
||||
{
|
||||
return call(j, val, priority_tag<1> {});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1344,35 +1344,13 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
|
|||
|
||||
struct from_json_fn
|
||||
{
|
||||
private:
|
||||
template<typename BasicJsonType, typename T>
|
||||
auto call(const BasicJsonType& j, T& val, priority_tag<1> /*unused*/) const
|
||||
auto operator()(const BasicJsonType& j, T& val) const
|
||||
noexcept(noexcept(from_json(j, val)))
|
||||
-> decltype(from_json(j, val), void())
|
||||
{
|
||||
return from_json(j, val);
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename T>
|
||||
void call(const BasicJsonType& /*unused*/, T& /*unused*/, priority_tag<0> /*unused*/) const noexcept
|
||||
{
|
||||
static_assert(sizeof(BasicJsonType) == 0,
|
||||
"could not find from_json() method in T's namespace");
|
||||
#ifdef _MSC_VER
|
||||
// MSVC does not show a stacktrace for the above assert
|
||||
using decayed = uncvref_t<T>;
|
||||
static_assert(sizeof(typename decayed::force_msvc_stacktrace) == 0,
|
||||
"forcing MSVC stacktrace to show which T we're talking about.");
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
template<typename BasicJsonType, typename T>
|
||||
void operator()(const BasicJsonType& j, T& val) const
|
||||
noexcept(noexcept(std::declval<from_json_fn>().call(j, val, priority_tag<1> {})))
|
||||
{
|
||||
return call(j, val, priority_tag<1> {});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -11112,8 +11090,10 @@ struct adl_serializer
|
|||
@param[in,out] val value to write to
|
||||
*/
|
||||
template<typename BasicJsonType, typename ValueType>
|
||||
static void from_json(BasicJsonType&& j, ValueType& val) noexcept(
|
||||
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
|
||||
static auto from_json(BasicJsonType&& j, ValueType& 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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue