Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:04

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___SYSTEM_ERROR_ERROR_CONDITION_H
0011 #define _LIBCPP___SYSTEM_ERROR_ERROR_CONDITION_H
0012 
0013 #include <__compare/ordering.h>
0014 #include <__config>
0015 #include <__functional/hash.h>
0016 #include <__functional/unary_function.h>
0017 #include <__system_error/errc.h>
0018 #include <__system_error/error_category.h>
0019 #include <string>
0020 
0021 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0022 #  pragma GCC system_header
0023 #endif
0024 
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026 
0027 template <class _Tp>
0028 struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum : public false_type {};
0029 
0030 #if _LIBCPP_STD_VER >= 17
0031 template <class _Tp>
0032 inline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
0033 #endif
0034 
0035 template <>
0036 struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc> : true_type {};
0037 
0038 #ifdef _LIBCPP_CXX03_LANG
0039 template <>
0040 struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx> : true_type {};
0041 #endif
0042 
0043 namespace __adl_only {
0044 // Those cause ADL to trigger but they are not viable candidates,
0045 // so they are never actually selected.
0046 void make_error_condition() = delete;
0047 } // namespace __adl_only
0048 
0049 class _LIBCPP_EXPORTED_FROM_ABI error_condition {
0050   int __val_;
0051   const error_category* __cat_;
0052 
0053 public:
0054   _LIBCPP_HIDE_FROM_ABI error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {}
0055 
0056   _LIBCPP_HIDE_FROM_ABI error_condition(int __val, const error_category& __cat) _NOEXCEPT
0057       : __val_(__val),
0058         __cat_(&__cat) {}
0059 
0060   template <class _Ep, __enable_if_t<is_error_condition_enum<_Ep>::value, int> = 0>
0061   _LIBCPP_HIDE_FROM_ABI error_condition(_Ep __e) _NOEXCEPT {
0062     using __adl_only::make_error_condition;
0063     *this = make_error_condition(__e);
0064   }
0065 
0066   _LIBCPP_HIDE_FROM_ABI void assign(int __val, const error_category& __cat) _NOEXCEPT {
0067     __val_ = __val;
0068     __cat_ = &__cat;
0069   }
0070 
0071   template <class _Ep, __enable_if_t<is_error_condition_enum<_Ep>::value, int> = 0>
0072   _LIBCPP_HIDE_FROM_ABI error_condition& operator=(_Ep __e) _NOEXCEPT {
0073     using __adl_only::make_error_condition;
0074     *this = make_error_condition(__e);
0075     return *this;
0076   }
0077 
0078   _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT {
0079     __val_ = 0;
0080     __cat_ = &generic_category();
0081   }
0082 
0083   _LIBCPP_HIDE_FROM_ABI int value() const _NOEXCEPT { return __val_; }
0084 
0085   _LIBCPP_HIDE_FROM_ABI const error_category& category() const _NOEXCEPT { return *__cat_; }
0086   string message() const;
0087 
0088   _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return __val_ != 0; }
0089 };
0090 
0091 inline _LIBCPP_HIDE_FROM_ABI error_condition make_error_condition(errc __e) _NOEXCEPT {
0092   return error_condition(static_cast<int>(__e), generic_category());
0093 }
0094 
0095 inline _LIBCPP_HIDE_FROM_ABI bool operator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT {
0096   return __x.category() == __y.category() && __x.value() == __y.value();
0097 }
0098 
0099 #if _LIBCPP_STD_VER <= 17
0100 
0101 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT {
0102   return !(__x == __y);
0103 }
0104 
0105 inline _LIBCPP_HIDE_FROM_ABI bool operator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT {
0106   return __x.category() < __y.category() || (__x.category() == __y.category() && __x.value() < __y.value());
0107 }
0108 
0109 #else // _LIBCPP_STD_VER <= 17
0110 
0111 inline _LIBCPP_HIDE_FROM_ABI strong_ordering
0112 operator<=>(const error_condition& __x, const error_condition& __y) noexcept {
0113   if (auto __c = __x.category() <=> __y.category(); __c != 0)
0114     return __c;
0115   return __x.value() <=> __y.value();
0116 }
0117 
0118 #endif // _LIBCPP_STD_VER <= 17
0119 
0120 template <>
0121 struct _LIBCPP_TEMPLATE_VIS hash<error_condition> : public __unary_function<error_condition, size_t> {
0122   _LIBCPP_HIDE_FROM_ABI size_t operator()(const error_condition& __ec) const _NOEXCEPT {
0123     return static_cast<size_t>(__ec.value());
0124   }
0125 };
0126 
0127 _LIBCPP_END_NAMESPACE_STD
0128 
0129 #endif // _LIBCPP___SYSTEM_ERROR_ERROR_CONDITION_H