Debian Codegraph @

yo/advancedtemplates/examples/errcode/category/equivalent2.cc

raw
1 //#define XERR
2 #include "category.ih"
3
4 // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0824r1.html:
5 // Two error_code instances compare equal if and only if they represent the
6 // same error enumerator in the same domain.
7 // Each "error domain" is represented in code by an object of type
8 // std::error_category.
9
10 // compare `condition' to an error condition constructed from the
11 // error condition constructed from the category matching the provided
12 // error code
13
14 //equiv
15 bool Category::equivalent(int ev, error_condition const &condition)
16 const noexcept
17 {
18 if (ev == 0) // no error? then
19 return condition.category() == *this and // categories must
20 not static_cast<bool>(condition); // be equal and
21 // condition must
22 // indicate no error
23
24 auto iter = s_map.find(as<CatErr>(ev)); // find ev's Cond
25
26 return iter == s_map.end()?
27 false // no such CatErr
28 : // or compare conditions
29 condition == make_error_condition(iter->second.cond);
30 }
31 //=