checked_result<R>Descriptionchecked_result is a special kind of variant class designed to hold
the result of some operation. It can hold either the result of the
operation or information on why the operation failed to produce a valid
result. It is similar to other types proposed for and/or included to the
C++ standard library or Boost such as expected,
variant, optional and outcome. In
some circumstances it may be referred to as a "monad".All instances of checked_result<R> are
immutable. That is, once constructed, they cannot be altered.There is no default constructor.checked_result<R> is never empty.Binary operations supported by type R are guaranteed to be
supported by checked_result<R>.Binary operations can be invoked on a pair of
checked_result<R> instances if and only if the
underlying type (R) is identical for both instances. They will
return a value of type checked_result<R>.Unary operations can be invoked on
checked_result<R> instances. They will return a
value of type checked_result<R>.Comparison operations will return a
boost::logic::tribool. Other binary operations will a
value of the same type as the arguments.Think of checked<R> as an "extended" version of R
which can hold all the values that R can hold in addition other "special
values". For example, consider checked<int>.NotationSymbolDescriptionRUnderlying typerAn instance of type Rc, c1, c2an instance of checked_result<R>tan instance of checked_result<T> for some type T not
necessarily the same as ReAn instance of type safe_numerics_errormsgAn instance of type const char *OSA type convertible to std::basic_ostreamosAn instance of type convertible to std::basic_ostreamTemplate ParametersR must model the type requirements of NumericParameterDescriptionRUnderlying typeModel ofNumericValid ExpressionsAll expressions are constexpr.ExpressionReturn TypeSemanticschecked_result(r)checked_result<R>constructor with valid instance of Rchecked_result<R>(t)checked_result<R>constructor with checked_result<T>
where T is not R. T must be convertible to R.checked_result(e, msg)checked_result<R>constructor with error informationstatic_cast<R>(c)Rextract wrapped value - compile time error if not
possiblestatic_cast<safe_numerics_error>(c)safe_numerics_errorextract wrapped value - may return safe_numerics_error::success
if there is no errorstatic_cast<const char *>(c)const char *returns pointer to the included error messagec.exception()booltrue if checked_result contains an error
condition.c1 < c2c1 >= c2c1 > c2c1 <= c2c1 == c2c1 != c2boost::logic::triboolcompare the wrapped values of two checked_result
instances. If the values are such that the result of such a
comparison cannot be reasonably defined, The result of the
comparison is
boost::logic::tribool::indeterminant.c1 + c2c1 - c2c1 * c2c1 / c2c1 % c2c1 | c2c1 & c2c1 ^ c2c1 << c2c1 >> c2checked_result<R>returns a new instance of
checked_result<R>.os << cOSwrites result to output stream. If the result is an error
it writes the string corresponding to the error message.
Otherwise, it writes the numeric value resulting from the
operation. Returns reference to output stream.Example of useSee AlsoExceptionPolicyHeader#include
<boost/numeric/safe_numerics/checked_result.hpp>#include
<boost/numeric/safe_numerics/checked_result_operations.hpp>