...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Create result
storing a portable error
code.
Defined in header <boost/json/result_for.hpp>
template< class T>result_for
< T,value
>::type result_from_errno( int e,boost::source_location
const* loc) noexcept;
This function constructs a boost::system::result<T>
that stores boost::system::error_code
with value()
equal to e
and category()
equal to boost::system::generic_category()
.
The main use for this function is in implementation of functions returning
result
,
without including boost/json/system_error.hpp
or
even <system_error>
. In particular, it may be useful for
customizations of try_value_to
without creating a
physical dependency on Boost.JSON. For example:
#include <cerrno> #include <boost/assert/source_location.hpp> namespace boost { namespace json { class value; template<class T> struct try_value_to_tag; template<class T1, class T2> struct result_for; template <class T> typename result_for<T, value>::type result_from_errno(int e, boost::source_location const* loc) noexcept } } namespace mine { class my_class; ... template<class JsonValue> boost::json::result_for<my_class, JsonValue> tag_invoke(boost::json::try_value_to_tag<my_class>, const JsonValue& jv) { BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION; if( !jv.is_null() ) return boost::json::result_from_errno<my_class>(EINVAL, &loc); return my_class(); } }
Does not throw exceptions.
Type |
Description |
---|---|
|
The value type of returned |
Name |
Description |
---|---|
|
The error value. |
|
The error location. |
boost::system::error_code
with value()
equal to e
and category()
equal to boost::system::generic_category()
.
try_value_to_tag
,
try_value_to
,
result_for
,
boost::system::generic_category
, boost::source_location
.
Convenience header <boost/json.hpp>