![]() |
boost::scope::error_code_checker — A predicate for checking whether an error code indicates error.
// In header: <boost/scope/error_code_checker.hpp> template<typename ErrorCode> class error_code_checker { public: // types typedef bool result_type; // Predicate result type. // public member functions explicit error_code_checker(ErrorCode &) noexcept; result_type operator()() const noexcept; };
The predicate captures a reference to an external error code object, which it tests for an error indication when called. The error code object must remain valid for the whole lifetime duration of the predicate.
For an error code object ec
, an expression !ec
must be valid, never throw exceptions, and return a value contextually convertible to bool
. If the returned value converts to false
, then this is taken as an error indication, and the predicate returns true
. Otherwise, the predicate returns false
.
A few examples of error code types:
std::error_code
or boost::system::error_code
,
std::expected
, boost::outcome_v2::basic_outcome
or boost::outcome_v2::basic_result
,
int
, where the value of 0 indicates no error,
bool
, where the value of false
indicates no error,
T*
, where a null pointer indicates no error.
error_code_checker
public member functionsexplicit error_code_checker(ErrorCode & ec) noexcept;Constructs the predicate.
Upon construction, the predicate saves a reference to the external error code object. The referenced object must remain valid for the whole lifetime duration of the predicate.
Throws: Nothing.
result_type operator()() const noexcept;Checks if the error code indicates error.
Throws: Nothing.
Returns: |
As if |