Conversation
|
I appreciate the work. But the points you raise do suggest concerns. I need to think about this. Regarding
|
|
As you've noted in your comments, as currently implemented, and may return different values for some values where An alternative implementation, rather than doing the check first with A simple implementation might be using T_type_traits = json_type_traits<basic_json,T>;
JSONCONS_TRY
{
T val = T_type_traits::as(*this);
return val;
}
JSONCONS_CATCH(...)
{
return static_cast<T>(std::forward<U>(default_value));
}Relying on It would be helpful if |
|
I definitely agree that try/catch isn't a great solution. Even for users who have exceptions enabled, the performance impact could be significant (especially since such a function isn't typically expected to be expensive). Other options including applying |
Implements feature request from #589.
Some caveats/things to consider:
get_value_orsort of has an ambiguous name: it isn't clear that it is getting the value of a member as opposed to the value of the current object (whichas_ordoes)as_orshould probably be marked noexcept, but I'm not entirely sure whether something else could throw.Other things I've noticed:
as(basic_json.hpp:3288), it is implemented asinstead of returning from
json_type_traits::as()directly. I've copied this behavior for as_or, but I'm wondering if this is something intentional.