Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
system_error491 linesDownload Raw Back to include
1// -*- C++ -*-2//===---------------------------- system_error ----------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX_SYSTEM_ERROR11#define _LIBCUDACXX_SYSTEM_ERROR12 13/*14    system_error synopsis15 16namespace std17{18 19class error_category20{21public:22    virtual ~error_category() noexcept;23 24    constexpr error_category();25    error_category(const error_category&) = delete;26    error_category& operator=(const error_category&) = delete;27 28    virtual const char* name() const noexcept = 0;29    virtual error_condition default_error_condition(int ev) const noexcept;30    virtual bool equivalent(int code, const error_condition& condition) const noexcept;31    virtual bool equivalent(const error_code& code, int condition) const noexcept;32    virtual string message(int ev) const = 0;33 34    bool operator==(const error_category& rhs) const noexcept;35    bool operator!=(const error_category& rhs) const noexcept;36    bool operator<(const error_category& rhs) const noexcept;37};38 39const error_category& generic_category() noexcept;40const error_category& system_category() noexcept;41 42template <class T> struct is_error_code_enum43    : public false_type {};44 45template <class T> struct is_error_condition_enum46    : public false_type {};47 48template <class _Tp>49inline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++1750 51template <class _Tp>52inline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++1753 54class error_code55{56public:57    // constructors:58    error_code() noexcept;59    error_code(int val, const error_category& cat) noexcept;60    template <class ErrorCodeEnum>61        error_code(ErrorCodeEnum e) noexcept;62 63    // modifiers:64    void assign(int val, const error_category& cat) noexcept;65    template <class ErrorCodeEnum>66        error_code& operator=(ErrorCodeEnum e) noexcept;67    void clear() noexcept;68 69    // observers:70    int value() const noexcept;71    const error_category& category() const noexcept;72    error_condition default_error_condition() const noexcept;73    string message() const;74    explicit operator bool() const noexcept;75};76 77// non-member functions:78bool operator<(const error_code& lhs, const error_code& rhs) noexcept;79template <class charT, class traits>80    basic_ostream<charT,traits>&81    operator<<(basic_ostream<charT,traits>& os, const error_code& ec);82 83class error_condition84{85public:86    // constructors:87    error_condition() noexcept;88    error_condition(int val, const error_category& cat) noexcept;89    template <class ErrorConditionEnum>90        error_condition(ErrorConditionEnum e) noexcept;91 92    // modifiers:93    void assign(int val, const error_category& cat) noexcept;94    template <class ErrorConditionEnum>95        error_condition& operator=(ErrorConditionEnum e) noexcept;96    void clear() noexcept;97 98    // observers:99    int value() const noexcept;100    const error_category& category() const noexcept;101    string message() const noexcept;102    explicit operator bool() const noexcept;103};104 105bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;106 107class system_error108    : public runtime_error109{110public:111    system_error(error_code ec, const string& what_arg);112    system_error(error_code ec, const char* what_arg);113    system_error(error_code ec);114    system_error(int ev, const error_category& ecat, const string& what_arg);115    system_error(int ev, const error_category& ecat, const char* what_arg);116    system_error(int ev, const error_category& ecat);117 118    const error_code& code() const noexcept;119    const char* what() const noexcept;120};121 122template <> struct is_error_condition_enum<errc>123    : true_type { }124 125error_code make_error_code(errc e) noexcept;126error_condition make_error_condition(errc e) noexcept;127 128// Comparison operators:129bool operator==(const error_code& lhs, const error_code& rhs) noexcept;130bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;131bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;132bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;133bool operator!=(const error_code& lhs, const error_code& rhs) noexcept;134bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;135bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;136bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;137 138template <> struct hash<std::error_code>;139template <> struct hash<std::error_condition>;140 141}  // std142 143*/144 145#include <__errc>146#include <type_traits>147#include <stdexcept>148#include <__functional_base>149#include <string>150 151#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)152#  pragma GCC system_header153#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)154#  pragma clang system_header155#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)156#  pragma system_header157#endif // no system header158 159_LIBCUDACXX_BEGIN_NAMESPACE_STD160 161// is_error_code_enum162 163template <class _Tp>164struct _LIBCUDACXX_TEMPLATE_VIS is_error_code_enum165    : public false_type {};166 167#if _LIBCUDACXX_STD_VER > 14168template <class _Tp>169_LIBCUDACXX_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value;170#endif171 172// is_error_condition_enum173 174template <class _Tp>175struct _LIBCUDACXX_TEMPLATE_VIS is_error_condition_enum176    : public false_type {};177 178#if _LIBCUDACXX_STD_VER > 14179template <class _Tp>180_LIBCUDACXX_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;181#endif182 183template <>184struct _LIBCUDACXX_TEMPLATE_VIS is_error_condition_enum<errc>185    : true_type { };186 187#ifdef _LIBCUDACXX_HAS_NO_STRONG_ENUMS188template <>189struct _LIBCUDACXX_TEMPLATE_VIS is_error_condition_enum<errc::__lx>190    : true_type { };191#endif192 193class _LIBCUDACXX_TYPE_VIS error_condition;194class _LIBCUDACXX_TYPE_VIS error_code;195 196// class error_category197 198class _LIBCUDACXX_HIDDEN __do_message;199 200class _LIBCUDACXX_TYPE_VIS error_category201{202public:203    virtual ~error_category() noexcept;204 205#if defined(_LIBCUDACXX_BUILDING_LIBRARY) && \206    defined(_LIBCUDACXX_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)207    error_category() noexcept;208#else209    _LIBCUDACXX_INLINE_VISIBILITY210    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 error_category() noexcept = default;211#endif212private:213    error_category(const error_category&);// = delete;214    error_category& operator=(const error_category&);// = delete;215 216public:217    virtual const char* name() const noexcept = 0;218    virtual error_condition default_error_condition(int __ev) const noexcept;219    virtual bool equivalent(int __code, const error_condition& __condition) const noexcept;220    virtual bool equivalent(const error_code& __code, int __condition) const noexcept;221    virtual string message(int __ev) const = 0;222 223    _LIBCUDACXX_INLINE_VISIBILITY224    bool operator==(const error_category& __rhs) const noexcept {return this == &__rhs;}225 226    _LIBCUDACXX_INLINE_VISIBILITY227    bool operator!=(const error_category& __rhs) const noexcept {return !(*this == __rhs);}228 229    _LIBCUDACXX_INLINE_VISIBILITY230    bool operator< (const error_category& __rhs) const noexcept {return this < &__rhs;}231 232    friend class _LIBCUDACXX_HIDDEN __do_message;233};234 235class _LIBCUDACXX_HIDDEN __do_message236    : public error_category237{238public:239    virtual string message(int ev) const;240};241 242_LIBCUDACXX_FUNC_VIS const error_category& generic_category() noexcept;243_LIBCUDACXX_FUNC_VIS const error_category& system_category() noexcept;244 245class _LIBCUDACXX_TYPE_VIS error_condition246{247    int __val_;248    const error_category* __cat_;249public:250    _LIBCUDACXX_INLINE_VISIBILITY251    error_condition() noexcept : __val_(0), __cat_(&generic_category()) {}252 253    _LIBCUDACXX_INLINE_VISIBILITY254    error_condition(int __val, const error_category& __cat) noexcept255        : __val_(__val), __cat_(&__cat) {}256 257    template <class _Ep>258        _LIBCUDACXX_INLINE_VISIBILITY259        error_condition(_Ep __e,260              typename enable_if<is_error_condition_enum<_Ep>::value>::type* = 0261                                                                     ) noexcept262            {*this = make_error_condition(__e);}263 264    _LIBCUDACXX_INLINE_VISIBILITY265    void assign(int __val, const error_category& __cat) noexcept266    {267        __val_ = __val;268        __cat_ = &__cat;269    }270 271    template <class _Ep>272        _LIBCUDACXX_INLINE_VISIBILITY273        typename enable_if274        <275            is_error_condition_enum<_Ep>::value,276            error_condition&277        >::type278        operator=(_Ep __e) noexcept279            {*this = make_error_condition(__e); return *this;}280 281    _LIBCUDACXX_INLINE_VISIBILITY282    void clear() noexcept283    {284        __val_ = 0;285        __cat_ = &generic_category();286    }287 288    _LIBCUDACXX_INLINE_VISIBILITY289    int value() const noexcept {return __val_;}290 291    _LIBCUDACXX_INLINE_VISIBILITY292    const error_category& category() const noexcept {return *__cat_;}293    string message() const;294 295    _LIBCUDACXX_INLINE_VISIBILITY296        _LIBCUDACXX_EXPLICIT297        operator bool() const noexcept {return __val_ != 0;}298};299 300inline _LIBCUDACXX_INLINE_VISIBILITY301error_condition302make_error_condition(errc __e) noexcept303{304    return error_condition(static_cast<int>(__e), generic_category());305}306 307inline _LIBCUDACXX_INLINE_VISIBILITY308bool309operator<(const error_condition& __x, const error_condition& __y) noexcept310{311    return __x.category() < __y.category()312        || (__x.category() == __y.category() && __x.value() < __y.value());313}314 315// error_code316 317class _LIBCUDACXX_TYPE_VIS error_code318{319    int __val_;320    const error_category* __cat_;321public:322    _LIBCUDACXX_INLINE_VISIBILITY323    error_code() noexcept : __val_(0), __cat_(&system_category()) {}324 325    _LIBCUDACXX_INLINE_VISIBILITY326    error_code(int __val, const error_category& __cat) noexcept327        : __val_(__val), __cat_(&__cat) {}328 329    template <class _Ep>330        _LIBCUDACXX_INLINE_VISIBILITY331        error_code(_Ep __e,332                   typename enable_if<is_error_code_enum<_Ep>::value>::type* = 0333                                                                     ) noexcept334            {*this = make_error_code(__e);}335 336    _LIBCUDACXX_INLINE_VISIBILITY337    void assign(int __val, const error_category& __cat) noexcept338    {339        __val_ = __val;340        __cat_ = &__cat;341    }342 343    template <class _Ep>344        _LIBCUDACXX_INLINE_VISIBILITY345        typename enable_if346        <347            is_error_code_enum<_Ep>::value,348            error_code&349        >::type350        operator=(_Ep __e) noexcept351            {*this = make_error_code(__e); return *this;}352 353    _LIBCUDACXX_INLINE_VISIBILITY354    void clear() noexcept355    {356        __val_ = 0;357        __cat_ = &system_category();358    }359 360    _LIBCUDACXX_INLINE_VISIBILITY361    int value() const noexcept {return __val_;}362 363    _LIBCUDACXX_INLINE_VISIBILITY364    const error_category& category() const noexcept {return *__cat_;}365 366    _LIBCUDACXX_INLINE_VISIBILITY367    error_condition default_error_condition() const noexcept368        {return __cat_->default_error_condition(__val_);}369 370    string message() const;371 372    _LIBCUDACXX_INLINE_VISIBILITY373        _LIBCUDACXX_EXPLICIT374        operator bool() const noexcept {return __val_ != 0;}375};376 377inline _LIBCUDACXX_INLINE_VISIBILITY378error_code379make_error_code(errc __e) noexcept380{381    return error_code(static_cast<int>(__e), generic_category());382}383 384inline _LIBCUDACXX_INLINE_VISIBILITY385bool386operator<(const error_code& __x, const error_code& __y) noexcept387{388    return __x.category() < __y.category()389        || (__x.category() == __y.category() && __x.value() < __y.value());390}391 392inline _LIBCUDACXX_INLINE_VISIBILITY393bool394operator==(const error_code& __x, const error_code& __y) noexcept395{396    return __x.category() == __y.category() && __x.value() == __y.value();397}398 399inline _LIBCUDACXX_INLINE_VISIBILITY400bool401operator==(const error_code& __x, const error_condition& __y) noexcept402{403    return __x.category().equivalent(__x.value(), __y)404        || __y.category().equivalent(__x, __y.value());405}406 407inline _LIBCUDACXX_INLINE_VISIBILITY408bool409operator==(const error_condition& __x, const error_code& __y) noexcept410{411    return __y == __x;412}413 414inline _LIBCUDACXX_INLINE_VISIBILITY415bool416operator==(const error_condition& __x, const error_condition& __y) noexcept417{418    return __x.category() == __y.category() && __x.value() == __y.value();419}420 421inline _LIBCUDACXX_INLINE_VISIBILITY422bool423operator!=(const error_code& __x, const error_code& __y) noexcept424{return !(__x == __y);}425 426inline _LIBCUDACXX_INLINE_VISIBILITY427bool428operator!=(const error_code& __x, const error_condition& __y) noexcept429{return !(__x == __y);}430 431inline _LIBCUDACXX_INLINE_VISIBILITY432bool433operator!=(const error_condition& __x, const error_code& __y) noexcept434{return !(__x == __y);}435 436inline _LIBCUDACXX_INLINE_VISIBILITY437bool438operator!=(const error_condition& __x, const error_condition& __y) noexcept439{return !(__x == __y);}440 441template <>442struct _LIBCUDACXX_TEMPLATE_VIS hash<error_code>443    : public __unary_function<error_code, size_t>444{445    _LIBCUDACXX_INLINE_VISIBILITY446    size_t operator()(const error_code& __ec) const noexcept447    {448        return static_cast<size_t>(__ec.value());449    }450};451 452template <>453struct _LIBCUDACXX_TEMPLATE_VIS hash<error_condition>454    : public __unary_function<error_condition, size_t>455{456    _LIBCUDACXX_INLINE_VISIBILITY457    size_t operator()(const error_condition& __ec) const noexcept458    {459        return static_cast<size_t>(__ec.value());460    }461};462 463// system_error464 465class _LIBCUDACXX_TYPE_VIS system_error466    : public runtime_error467{468    error_code __ec_;469public:470    system_error(error_code __ec, const string& __what_arg);471    system_error(error_code __ec, const char* __what_arg);472    system_error(error_code __ec);473    system_error(int __ev, const error_category& __ecat, const string& __what_arg);474    system_error(int __ev, const error_category& __ecat, const char* __what_arg);475    system_error(int __ev, const error_category& __ecat);476    ~system_error() noexcept;477 478    _LIBCUDACXX_INLINE_VISIBILITY479    const error_code& code() const noexcept {return __ec_;}480 481private:482    static string __init(const error_code&, string);483};484 485_LIBCUDACXX_NORETURN _LIBCUDACXX_FUNC_VIS486void __throw_system_error(int ev, const char* what_arg);487 488_LIBCUDACXX_END_NAMESPACE_STD489 490#endif  // _LIBCUDACXX_SYSTEM_ERROR491 
codekingpro/portable-devtools · Team Ai