From 019a4057a38239a755e810fb3696766cd4ead8c7 Mon Sep 17 00:00:00 2001 From: Dmitry Arkhipov Date: Thu, 26 Feb 2026 12:52:21 +0300 Subject: [PATCH 1/2] use result::unsafe_value where appropriate --- example/use_allocator.cpp | 2 +- include/boost/json/detail/value_to.hpp | 15 ++++++++------- include/boost/json/impl/value.ipp | 8 ++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/example/use_allocator.cpp b/example/use_allocator.cpp index c3bc8f9a1..a86c8bdc3 100644 --- a/example/use_allocator.cpp +++ b/example/use_allocator.cpp @@ -60,7 +60,7 @@ tag_invoke( try_value_to_tag, const value& jv, const use_allocator_t& auto elem_res = try_value_to( val, full_ctx ); if( elem_res.has_error() ) return {boost::system::in_place_error, elem_res.error()}; - *ins++ = std::move(*elem_res); + *ins++ = std::move(elem_res.unsafe_value()); } return result; } diff --git a/include/boost/json/detail/value_to.hpp b/include/boost/json/detail/value_to.hpp index 25a827971..7788841a6 100644 --- a/include/boost/json/detail/value_to.hpp +++ b/include/boost/json/detail/value_to.hpp @@ -238,7 +238,7 @@ value_to_impl( return {boost::system::in_place_error, elem_res.error()}; *ins++ = value_type{ key_type(kv.key()), - std::move(*elem_res)}; + std::move(elem_res.unsafe_value())}; } return res; } @@ -276,7 +276,7 @@ value_to_impl( auto elem_res = try_value_to>( val, ctx ); if( elem_res.has_error() ) return {boost::system::in_place_error, elem_res.error()}; - *ins++ = std::move(*elem_res); + *ins++ = std::move(elem_res.unsafe_value()); } return result; } @@ -401,7 +401,7 @@ struct to_described_member # pragma GCC diagnostic pop #endif if( member_res ) - (*res).* D::pointer = std::move(*member_res); + (*res).* D::pointer = std::move(member_res.unsafe_value()); else res = {boost::system::in_place_error, member_res.error()}; } @@ -543,7 +543,8 @@ struct alternative_converter if( attempt ) { using cat = variant_construction_category; - res = initialize_variant( std::move(*attempt), cat() ); + res = initialize_variant( + std::move(attempt.unsafe_value()), cat() ); } } }; @@ -637,7 +638,7 @@ value_to_impl( auto res = tag_invoke(try_value_to_tag(), jv); if( res.has_error() ) throw_system_error( res.error() ); - return std::move(*res); + return std::move(res.unsafe_value()); } template< @@ -655,7 +656,7 @@ value_to_impl( auto res = tag_invoke( try_value_to_tag(), jv, Sup::get(ctx) ); if( res.has_error() ) throw_system_error( res.error() ); - return std::move(*res); + return std::move(res.unsafe_value()); } template< @@ -676,7 +677,7 @@ value_to_impl( auto res = tag_invoke(try_value_to_tag(), jv, Sup::get(ctx), ctx); if( res.has_error() ) throw_system_error( res.error() ); - return std::move(*res); + return std::move(res.unsafe_value()); } //---------------------------------------------------------- diff --git a/include/boost/json/impl/value.ipp b/include/boost/json/impl/value.ipp index 1317674a3..5d136dbe5 100644 --- a/include/boost/json/impl/value.ipp +++ b/include/boost/json/impl/value.ipp @@ -531,7 +531,7 @@ value::try_at(string_view key) noexcept auto r = try_as_object(); if( !r ) return r.error(); - return r->try_at(key); + return r.unsafe_value().try_at(key); } boost::system::result @@ -540,7 +540,7 @@ value::try_at(string_view key) const noexcept auto r = try_as_object(); if( !r ) return r.error(); - return r->try_at(key); + return r.unsafe_value().try_at(key); } boost::system::result @@ -549,7 +549,7 @@ value::try_at(std::size_t pos) noexcept auto r = try_as_array(); if( !r ) return r.error(); - return r->try_at(pos); + return r.unsafe_value().try_at(pos); } boost::system::result @@ -558,7 +558,7 @@ value::try_at(std::size_t pos) const noexcept auto r = try_as_array(); if( !r ) return r.error(); - return r->try_at(pos); + return r.unsafe_value().try_at(pos); } object const& From 9e0d94d507cd66ae9702160eec6b97629c466ed5 Mon Sep 17 00:00:00 2001 From: Dmitry Arkhipov Date: Mon, 25 May 2026 16:50:58 +0300 Subject: [PATCH 2/2] some explicit result checking is removed --- include/boost/json/detail/value_to.hpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/include/boost/json/detail/value_to.hpp b/include/boost/json/detail/value_to.hpp index 7788841a6..66c3858c7 100644 --- a/include/boost/json/detail/value_to.hpp +++ b/include/boost/json/detail/value_to.hpp @@ -635,10 +635,7 @@ mp11::mp_if_c< !mp11::mp_valid::value, T> value_to_impl( user_conversion_tag, value_to_tag, value const& jv, Ctx const& ) { - auto res = tag_invoke(try_value_to_tag(), jv); - if( res.has_error() ) - throw_system_error( res.error() ); - return std::move(res.unsafe_value()); + return tag_invoke(try_value_to_tag(), jv).value(); } template< @@ -653,10 +650,7 @@ mp11::mp_if_c< value_to_impl( context_conversion_tag, value_to_tag, value const& jv, Ctx const& ctx ) { - auto res = tag_invoke( try_value_to_tag(), jv, Sup::get(ctx) ); - if( res.has_error() ) - throw_system_error( res.error() ); - return std::move(res.unsafe_value()); + return tag_invoke( try_value_to_tag(), jv, Sup::get(ctx) ).value(); } template< @@ -674,10 +668,7 @@ value_to_impl( value const& jv, Ctx const& ctx ) { - auto res = tag_invoke(try_value_to_tag(), jv, Sup::get(ctx), ctx); - if( res.has_error() ) - throw_system_error( res.error() ); - return std::move(res.unsafe_value()); + return tag_invoke(try_value_to_tag(), jv, Sup::get(ctx), ctx).value(); } //----------------------------------------------------------