...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
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. // construct/copy/destruct explicit error_code_checker(ErrorCode &) noexcept; // public member functions 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.