-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Closed
Labels
solution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation
Description
Currently the get<T> method requires that T is default constructible. Might it make sense to overload get so that it can take variadic arguments and construct the new object with a non-default constructor? For example - below is a minor variation of get. Any reason why this is a bad idea?
template<typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>,
detail::enable_if_t <
not std::is_same<basic_json_t, ValueType>::value and
detail::has_from_json<basic_json_t, ValueType>::value and
not detail::has_non_default_from_json<basic_json_t, ValueType>::value,
int> = 0, typename ...Types>
ValueType get(Types... args) const noexcept(noexcept(
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
{
// we cannot static_assert on ValueTypeCV being non-const, because
// there is support for get<const basic_json_t>(), which is why we
// still need the uncvref
static_assert(not std::is_reference<ValueTypeCV>::value,
"get() cannot be used with reference types, you might want to use get_ref()");
ValueType ret(args...); // Allows non-default constructors to be used
JSONSerializer<ValueType>::from_json(*this, ret);
return ret;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
solution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation