Library Documentation Index

Safe Numerics

PrevUpHomeNext

checked_result<typename R>

Description
Template Parameters
Notation
Valid Expressions
Header
Example of use
See Also

Description

checked_result is a wrapper class designed to hold 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. Note that this type is an internal feature of the library and shouldn't be exposed to library users because it has some unsafe behavior.

Template Parameters

The sole template parameter is the return type of some operation.

Parameter Default Type Requirements Description
R  

The value type.

Notation

Symbol Description
C checked_result<R>
c an instance of checked_result<R>
t an instance of checked_result<T> for some type T not necessarily the same as R
r An object of type R
EP ExceptionPolicy

Valid Expressions

All expressions are constexpr.

Expression Return Type Semantics
checked_result(r) checked_result<R> constructor with valid instance of R
checked_result(e, msg) checked_result<R> constructor with error information
static_cast<R>(c) R extract wrapped value - asserts if not possible
static_cast<const char *>(c) R extract wrapped value - asserts if not possible
c < t
c >= t
c > t
c <= t
c == t
c != t
boost::logic::tribool compare the wrapped values of two checked_result instances. If either one contains an invalid value, return boost::logic::tribool::indeterminant.
c.no_exception() bool true if checked_result contains a valid result
c.exception() bool true if checked_result contains an error condition
dispatch<EP>(c) void invoke exception in accordance exception_type value

Header

#include "checked_result.hpp"

Example of use

#include "checked_result.hpp"

template<class R>
checked_result<R>
constexpr modulus(
    const R & t,
    const R & u
) {
    if(0 == u)
        return checked_result<R>(
            exception_type::domain_error,
            "denominator is zero"
        );

    return t % u;
}

See Also

ExceptionPolicy


PrevUpHomeNext