File: equivalent2.cc

package info (click to toggle)
c%2B%2B-annotations 11.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,244 kB
  • sloc: cpp: 21,698; makefile: 1,505; ansic: 165; sh: 121; perl: 90
file content (31 lines) | stat: -rw-r--r-- 1,297 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//#define XERR
#include "category.ih"

// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0824r1.html:
// Two error_code instances compare equal if and only if they represent the
// same error enumerator in the same domain.
    // Each "error domain" is represented in code by an object of type
// std::error_category.

// compare `condition' to an error condition constructed from the
// error condition constructed from the category matching the provided
// error code

//equiv
bool Category::equivalent(int ev, error_condition const &condition)
                                                        const noexcept
{
    if (ev == 0)                                    // no error? then
        return condition.category() == *this and    // categories must
               not static_cast<bool>(condition);    // be equal and
                                                    // condition must
                                                    // indicate no error

    auto iter = s_map.find(as<CatErr>(ev));     // find ev's Cond

    return iter == s_map.end()?
                false                           // no such CatErr
            :                                   // or compare conditions
                condition == make_error_condition(iter->second.cond);
}
//=