Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:43

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