1#ifndef _STDEX_SYSTEM_ERROR_H
2#define _STDEX_SYSTEM_ERROR_H
9#include "./type_traits.hpp"
17#ifdef __STDC_WANT_LIB_EXT1__
19#define __STDC_WANT_LIB_EXT1__ 1
36#ifdef _STDEX_NATIVE_CPP11_SUPPORT
38#define _STDEX_DELETED_FUNCTION =delete
39#define _STDEX_NOEXCEPT_FUNCTION noexcept
43#define _STDEX_DELETED_FUNCTION
44#define _STDEX_NOEXCEPT_FUNCTION throw()
55 address_family_not_supported = EAFNOSUPPORT,
57 address_family_not_supported = 102,
60 address_in_use = EADDRINUSE,
65 address_not_available = EADDRNOTAVAIL,
67 address_not_available = 101,
70 already_connected = EISCONN,
72 already_connected = 113,
74 argument_list_too_long = E2BIG,
75 argument_out_of_domain = EDOM,
77 bad_file_descriptor = EBADF,
79 bad_message = EBADMSG,
85 connection_aborted = ECONNABORTED,
87 connection_aborted = 106,
90 connection_already_in_progress = EALREADY,
92 connection_already_in_progress = 103,
95 connection_refused = ECONNREFUSED,
97 connection_refused = 107,
100 connection_reset = ECONNRESET,
102 connection_reset = 108,
104 cross_device_link = EXDEV,
106 destination_address_required = EDESTADDRREQ,
108 destination_address_required = 109,
110 device_or_resource_busy = EBUSY,
111 directory_not_empty = ENOTEMPTY,
112 executable_format_error = ENOEXEC,
113 file_exists = EEXIST,
114 file_too_large = EFBIG,
115 filename_too_long = ENAMETOOLONG,
117 function_not_supported = ENOSYS,
119 function_not_supported = 40,
122 host_unreachable = EHOSTUNREACH,
124 host_unreachable = 110,
127 identifier_removed = EIDRM,
129 identifier_removed = 111,
132 illegal_byte_sequence = EILSEQ,
134 illegal_byte_sequence = 42,
136 inappropriate_io_control_operation = ENOTTY,
138 invalid_argument = EINVAL,
139 invalid_seek = ESPIPE,
141 is_a_directory = EISDIR,
143 message_size = EMSGSIZE,
148 network_down = ENETDOWN,
153 network_reset = ENETRESET,
158 network_unreachable = ENETUNREACH,
160 network_unreachable = 118,
163 no_buffer_space = ENOBUFS,
165 no_buffer_space = 119,
167 no_child_process = ECHILD,
174 no_lock_available = ENOLCK,
176 no_lock_available = 39,
179 no_message_available = ENODATA,
181 no_message_available = 120,
189 no_protocol_option = ENOPROTOOPT,
191 no_protocol_option = 123,
193 no_space_on_device = ENOSPC,
195 no_stream_resources = ENOSR,
197 no_stream_resources = 124,
199 no_such_device_or_address = ENXIO,
200 no_such_device = ENODEV,
201 no_such_file_or_directory = ENOENT,
202 no_such_process = ESRCH,
203 not_a_directory = ENOTDIR,
205 not_a_socket = ENOTSOCK,
210 not_a_stream = ENOSTR,
215 not_connected = ENOTCONN,
219 not_enough_memory = ENOMEM,
221 not_supported = ENOTSUP,
226 operation_canceled = ECANCELED,
228 operation_canceled = 105,
231 operation_in_progress = EINPROGRESS,
233 operation_in_progress = 112,
235 operation_not_permitted = EPERM,
237 operation_not_supported = EOPNOTSUPP,
239 operation_not_supported = 130,
242 operation_would_block = EWOULDBLOCK,
244 operation_would_block = 140,
247 owner_dead = EOWNERDEAD,
251 permission_denied = EACCES,
253 protocol_error = EPROTO,
255 protocol_error = 134,
257#ifdef EPROTONOSUPPORT
258 protocol_not_supported = EPROTONOSUPPORT,
260 protocol_not_supported = 135,
262 read_only_file_system = EROFS,
264 resource_deadlock_would_occur = EDEADLK,
266 resource_deadlock_would_occur = 36,
268 resource_unavailable_try_again = EAGAIN,
269 result_out_of_range = ERANGE,
270#ifdef ENOTRECOVERABLE
271 state_not_recoverable = ENOTRECOVERABLE,
273 state_not_recoverable = 127,
276 stream_timeout = ETIME,
278 stream_timeout = 137,
281 text_file_busy = ETXTBSY,
283 text_file_busy = 139,
286 timed_out = ETIMEDOUT,
290 too_many_files_open_in_system = ENFILE,
291 too_many_files_open = EMFILE,
292 too_many_links = EMLINK,
294 too_many_symbolic_link_levels = ELOOP,
296 too_many_symbolic_link_levels = 114,
299 value_too_large = EOVERFLOW,
301 value_too_large = 132,
304 wrong_protocol_type = EPROTOTYPE
306 wrong_protocol_type = 136
321 operator const type&()
const
330 typedef errc generic_errno;
351 operator const type&()
const
361 template<
class _Enum>
362 struct is_error_code_enum
364 static const bool value =
false;
368 struct is_error_code_enum<io_errc>
370 static const bool value =
true;
374 struct is_error_code_enum<io_errc::type>
376 static const bool value =
true;
380 template<
class _Enum>
381 struct is_error_condition_enum
383 static const bool value =
false;
387 struct is_error_condition_enum<errc::type>
389 static const bool value =
true;
393 struct is_error_condition_enum<generic_errno>
395 static const bool value =
true;
399 class error_condition;
402 error_code make_error_code(errc::errc_t) _STDEX_NOEXCEPT_FUNCTION;
403 error_code make_error_code(io_errc) _STDEX_NOEXCEPT_FUNCTION;
404 error_condition make_error_condition(errc::errc_t) _STDEX_NOEXCEPT_FUNCTION;
405 error_condition make_error_condition(io_errc) _STDEX_NOEXCEPT_FUNCTION;
407 class error_category;
409 const error_category& generic_category() _STDEX_NOEXCEPT_FUNCTION;
410 const error_category& iostream_category() _STDEX_NOEXCEPT_FUNCTION;
411 const error_category& system_category() _STDEX_NOEXCEPT_FUNCTION;
427 static stdex::error_code _make_error_code(_Tp);
431 static stdex::error_condition _make_error_condition(_Tp);
439 error_category() _STDEX_NOEXCEPT_FUNCTION
442 virtual ~error_category() _STDEX_NOEXCEPT_FUNCTION
445 virtual const char* name() const _STDEX_NOEXCEPT_FUNCTION = 0;
452 virtual std::
string message(
int) const = 0;
455 virtual error_condition default_error_condition(
int val) const _STDEX_NOEXCEPT_FUNCTION;
457 virtual
bool equivalent(
int val, const error_condition &cond) const _STDEX_NOEXCEPT_FUNCTION;
459 virtual
bool equivalent(const error_code& code,
int) const _STDEX_NOEXCEPT_FUNCTION;
461 inline
bool operator<(const error_category &other) const _STDEX_NOEXCEPT_FUNCTION
463 return std::less<const error_category*>()(
this, &other);
466 inline bool operator==(
const error_category &other)
const _STDEX_NOEXCEPT_FUNCTION
468 return this == &other;
471 inline bool operator!=(
const error_category &other)
const _STDEX_NOEXCEPT_FUNCTION
473 return this != &other;
477 error_category(
const error_category&) _STDEX_DELETED_FUNCTION;
478 error_category& operator=(
const error_category&) _STDEX_DELETED_FUNCTION;
483 struct _error_condition_compare
486 const stdex::error_condition&()
const{
487 return reinterpret_cast<const error_condition&
>(*this);
492 class error_condition:
493 public detail::_error_condition_compare
497 const error_category *_cat;
499 typedef void(*unspecified_bool_type)();
500 static void unspecified_bool_true() {}
503 error_condition() _STDEX_NOEXCEPT_FUNCTION:
505 _cat(&generic_category())
508 error_condition(
int val,
const error_category &cat) _STDEX_NOEXCEPT_FUNCTION:
513 template<
class _ErrorCondEnum>
514 error_condition(
const _ErrorCondEnum& val) _STDEX_NOEXCEPT_FUNCTION
516 STATIC_ASSERT(
bool(is_error_condition_enum<_ErrorCondEnum>::value ==
true), value_should_be_error_condition_enum);
520 void assign(
int val,
const error_category &cat) _STDEX_NOEXCEPT_FUNCTION
526 template<
class _ErrorCondEnum>
527 typename enable_if<detail::_or_<is_error_condition_enum<_ErrorCondEnum>, is_same<error_condition, _ErrorCondEnum> >::value, error_condition&>::type
528 operator=(
const _ErrorCondEnum& val) _STDEX_NOEXCEPT_FUNCTION
530 return (*
this = _stdex_ADL::_make_error_condition(val));
533 void clear() _STDEX_NOEXCEPT_FUNCTION
535 assign(0, generic_category());
538 int value() const _STDEX_NOEXCEPT_FUNCTION {
return _value; }
540 const error_category& category() const _STDEX_NOEXCEPT_FUNCTION {
return *_cat; }
543 std::string message()
const
545 return category().message(value());
548 operator unspecified_bool_type() const _STDEX_NOEXCEPT_FUNCTION
550 return _value == 0 ? 0 : unspecified_bool_true;
553 bool operator!() const _STDEX_NOEXCEPT_FUNCTION
561 struct _error_code_compare
564 const stdex::error_code&()
const {
565 return reinterpret_cast<const error_code&
>(*this);
571 public detail::_error_code_compare
576 const error_category *_cat;
578 typedef void(*unspecified_bool_type)();
579 static void unspecified_bool_true() {}
582 error_code() _STDEX_NOEXCEPT_FUNCTION:
584 _cat(&system_category())
587 error_code(
int val,
const error_category& cat) _STDEX_NOEXCEPT_FUNCTION:
592 template<
class _ErrorCodeEnum>
593 error_code(
const _ErrorCodeEnum &val) _STDEX_NOEXCEPT_FUNCTION
595 STATIC_ASSERT(
bool(is_error_code_enum<_ErrorCodeEnum>::value ==
true), value_should_be_error_code_enum);
599 void assign(
int val,
const error_category& cat) _STDEX_NOEXCEPT_FUNCTION
605 void clear() _STDEX_NOEXCEPT_FUNCTION
607 assign(0, system_category());
610 template<
class _ErrorCodeEnum>
611 typename enable_if<detail::_or_<is_error_code_enum<_ErrorCodeEnum>, is_same<error_code, _ErrorCodeEnum> >::value, error_code&>::type
612 operator=(
const _ErrorCodeEnum& val) _STDEX_NOEXCEPT_FUNCTION
614 return (*
this = _stdex_ADL::_make_error_code(val));
617 int value() const _STDEX_NOEXCEPT_FUNCTION {
return _value; }
619 const error_category& category() const _STDEX_NOEXCEPT_FUNCTION {
return *_cat; }
621 error_condition default_error_condition() const _STDEX_NOEXCEPT_FUNCTION;
623 std::
string message()
const
625 return category().message(value());
628 operator unspecified_bool_type() const _STDEX_NOEXCEPT_FUNCTION
630 return _value == 0 ? 0 : unspecified_bool_true;
633 bool operator!() const _STDEX_NOEXCEPT_FUNCTION
640 public std::runtime_error
646 system_error(error_code ecode = error_code()):
647 std::runtime_error(ecode.message()),
651 system_error(error_code ecode,
const std::string &what):
652 std::runtime_error(what +
": " + ecode.message()),
656 system_error(error_code ecode,
const char *what):
657 std::runtime_error(std::string(what) + (
": " + ecode.message())),
661 system_error(
int val,
const error_category &ecat,
const char *what):
662 std::runtime_error(std::string(what) + (
": " + error_code(val, ecat).message())),
666 system_error(
int val,
const error_category &ecat):
667 std::runtime_error(error_code(val, ecat).message()),
671 system_error(
int val,
const error_category &ecat,
const std::string &what):
672 std::runtime_error(what +
": " + error_code(val, ecat).message()),
676 const error_code& code() const _STDEX_NOEXCEPT_FUNCTION {
return _code; }
682 struct _is_error_code
684 static const bool value =
686 typename remove_reference<
687 typename remove_cv<_Tp>::type>::type>::value == bool(
true) ||
688 is_same<detail::_error_code_compare,
689 typename remove_reference<
690 typename remove_cv<_Tp>::type>::type>::value == bool(
true);
694 struct _is_not_error_code:
695 _not_<_is_error_code<_Tp>>
699 struct _is_error_condition
701 static const bool value =
702 is_same<error_condition,
703 typename remove_reference<
704 typename remove_cv<_Tp>::type>::type>::value == bool(
true) ||
705 is_same<detail::_error_condition_compare,
706 typename remove_reference<
707 typename remove_cv<_Tp>::type>::type>::value == bool(
true);
711 struct _is_not_error_condition :
712 _not_<_is_error_condition<_Tp>>
716 struct _is_error_code_enum_or_class:
718 is_error_code_enum<_Tp>,
724 struct _is_error_code_enum_not_class:
726 is_error_code_enum<_Tp>,
727 _is_not_error_code<_Tp>
732 struct _is_error_condition_enum_or_class:
734 is_error_condition_enum<_Tp>,
735 _is_error_condition<_Tp>
740 struct _is_error_condition_enum_not_class:
742 is_error_condition_enum<_Tp>,
743 _is_not_error_condition<_Tp>
748 class _disabled_system_error_operator;
751 template<
class _LhsT>
755 typename conditional<
756 bool( detail::_is_error_code_enum_or_class<_LhsT>::value ==
bool(
true) ),
757 const detail::_error_code_compare&,
758 detail::_disabled_system_error_operator<__LINE__>>::type _rhs) _STDEX_NOEXCEPT_FUNCTION
764 const error_code& _lhs,
const error_code& _rhs) _STDEX_NOEXCEPT_FUNCTION
766 return (_lhs.category() < _rhs.category()
767 || (_lhs.category() == _rhs.category()
768 && _lhs.value() < _rhs.value()));
771 return lambdas::compare(_lhs, _rhs);
774 template<
class _RhsT>
777 typename conditional<
778 bool( detail::_is_error_code_enum_not_class<_RhsT>::value ==
bool(
true) ),
779 const detail::_error_code_compare&,
780 detail::_disabled_system_error_operator<__LINE__>>::type _lhs,
781 const _RhsT &_rhs) _STDEX_NOEXCEPT_FUNCTION
783 return stdex::operator<(_lhs, error_code(_rhs));
786 template<
class _LhsT>
790 typename conditional<
791 bool( detail::_is_error_condition_enum_or_class<_LhsT>::value ==
bool(
true) ),
792 const detail::_error_condition_compare&,
793 detail::_disabled_system_error_operator<__LINE__>>::type _rhs) _STDEX_NOEXCEPT_FUNCTION
799 const error_condition& _lhs,
const error_condition& _rhs) _STDEX_NOEXCEPT_FUNCTION
801 return (_lhs.category() < _rhs.category()
802 || (_lhs.category() == _rhs.category()
803 && _lhs.value() < _rhs.value()));
806 return lambdas::compare(_lhs, _rhs);
809 template<
class _RhsT>
812 typename conditional<
813 bool( detail::_is_error_condition_enum_not_class<_RhsT>::value ==
bool(
true) ),
814 const detail::_error_condition_compare&,
815 detail::_disabled_system_error_operator<__LINE__>>::type _lhs,
816 const _RhsT &_rhs) _STDEX_NOEXCEPT_FUNCTION
818 return stdex::operator<(_lhs, error_condition(_rhs));
832 template<
class _LhsT>
836 typename conditional<
837 bool( detail::_is_error_code_enum_or_class<_LhsT>::value ==
bool(
true) ),
838 const detail::_error_code_compare&,
839 detail::_disabled_system_error_operator<__LINE__>>::type _rhs) _STDEX_NOEXCEPT_FUNCTION
845 const error_code& _lhs,
const error_code& _rhs) _STDEX_NOEXCEPT_FUNCTION
847 return (_lhs.category() == _rhs.category()
848 && _lhs.value() == _rhs.value());
851 return lambdas::compare(_lhs, _rhs);
854 template<
class _RhsT>
857 typename conditional<
858 bool( detail::_is_error_code_enum_not_class<_RhsT>::value ==
bool(
true) ),
859 const detail::_error_code_compare&,
860 detail::_disabled_system_error_operator<__LINE__>>::type _lhs,
861 const _RhsT &_rhs) _STDEX_NOEXCEPT_FUNCTION
863 return stdex::operator==(_lhs, error_code(_rhs));
866 template<
class _LhsT>
870 typename conditional<
871 bool( detail::_is_error_code_enum_or_class<_LhsT>::value ==
bool(
true) ),
872 const detail::_error_condition_compare&,
873 detail::_disabled_system_error_operator<__LINE__>>::type _rhs) _STDEX_NOEXCEPT_FUNCTION
879 const error_code& _lhs,
const error_condition& _rhs) _STDEX_NOEXCEPT_FUNCTION
881 return (_lhs.category().equivalent(_lhs.value(), _rhs)
882 || _rhs.category().equivalent(_lhs, _rhs.value()));
885 return lambdas::compare(_lhs, _rhs);
888 template<
class _RhsT>
891 typename conditional<
892 bool( detail::_is_error_condition_enum_not_class<_RhsT>::value ==
bool(
true) ),
893 const detail::_error_code_compare&,
894 detail::_disabled_system_error_operator<__LINE__>>::type _lhs,
895 const _RhsT &_rhs) _STDEX_NOEXCEPT_FUNCTION
897 return stdex::operator==(_lhs, error_condition(_rhs));
900 template<
class _LhsT>
904 typename conditional<
905 bool( detail::_is_error_condition_enum_or_class<_LhsT>::value ==
bool(
true) ),
906 const detail::_error_code_compare&,
907 detail::_disabled_system_error_operator<__LINE__>>::type _rhs) _STDEX_NOEXCEPT_FUNCTION
913 const error_condition& _lhs,
const error_code& _rhs) _STDEX_NOEXCEPT_FUNCTION
915 return (_rhs.category().equivalent(_rhs.value(), _lhs)
916 || _lhs.category().equivalent(_rhs, _lhs.value()));
919 return lambdas::compare(_lhs, _rhs);
922 template<
class _RhsT>
925 typename conditional<
926 bool( detail::_is_error_code_enum_not_class<_RhsT>::value ==
bool(
true) ),
927 const detail::_error_condition_compare&,
928 detail::_disabled_system_error_operator<__LINE__>>::type _lhs,
929 const _RhsT &_rhs) _STDEX_NOEXCEPT_FUNCTION
931 return stdex::operator==(_lhs, error_code(_rhs));
936 template<
class _LhsT>
940 typename conditional<
941 bool( detail::_is_error_condition_enum_or_class<_LhsT>::value ==
bool(
true) ),
942 const detail::_error_condition_compare&,
943 detail::_disabled_system_error_operator<__LINE__>>::type _rhs) _STDEX_NOEXCEPT_FUNCTION
949 const error_condition& _lhs,
const error_condition& _rhs) _STDEX_NOEXCEPT_FUNCTION
951 return (_lhs.category() == _rhs.category()
952 && _lhs.value() == _rhs.value());
955 return lambdas::compare(_lhs, _rhs);
958 template<
class _RhsT>
961 typename conditional<
962 bool( detail::_is_error_condition_enum_not_class<_RhsT>::value ==
bool(
true) ),
963 const detail::_error_condition_compare&,
964 detail::_disabled_system_error_operator<__LINE__>>::type _lhs,
965 const _RhsT &_rhs) _STDEX_NOEXCEPT_FUNCTION
967 return stdex::operator==(_lhs, error_condition(_rhs));
977 template<
class _LhsT>
981 typename conditional<
982 bool( detail::_is_error_code_enum_or_class<_LhsT>::value ==
bool(
true) ),
983 const detail::_error_code_compare&,
984 detail::_disabled_system_error_operator<__LINE__>>::type _rhs) _STDEX_NOEXCEPT_FUNCTION
986 return !(_lhs == _rhs);
989 template<
class _RhsT>
992 typename conditional<
993 bool( detail::_is_error_code_enum_not_class<_RhsT>::value ==
bool(
true) ),
994 const detail::_error_code_compare&,
995 detail::_disabled_system_error_operator<__LINE__>>::type _lhs,
996 const _RhsT &_rhs) _STDEX_NOEXCEPT_FUNCTION
998 return !(_lhs == _rhs);
1001 template<
class _LhsT>
1005 typename conditional<
1006 bool( detail::_is_error_code_enum_or_class<_LhsT>::value ==
bool(
true) ),
1007 const detail::_error_condition_compare&,
1008 detail::_disabled_system_error_operator<__LINE__>>::type _rhs) _STDEX_NOEXCEPT_FUNCTION
1010 return !(_lhs == _rhs);
1013 template<
class _RhsT>
1016 typename conditional<
1017 bool( detail::_is_error_condition_enum_not_class<_RhsT>::value ==
bool(
true) ),
1018 const detail::_error_code_compare&,
1019 detail::_disabled_system_error_operator<__LINE__>>::type _lhs,
1020 const _RhsT &_rhs) _STDEX_NOEXCEPT_FUNCTION
1022 return !(_lhs == _rhs);
1025 template<
class _LhsT>
1029 typename conditional<
1030 bool( detail::_is_error_condition_enum_or_class<_LhsT>::value ==
bool(
true) ),
1031 const detail::_error_code_compare&,
1032 detail::_disabled_system_error_operator<__LINE__>>::type _rhs) _STDEX_NOEXCEPT_FUNCTION
1034 return !(_lhs == _rhs);
1037 template<
class _RhsT>
1040 typename conditional<
1041 bool( detail::_is_error_code_enum_not_class<_RhsT>::value ==
bool(
true) ),
1042 const detail::_error_condition_compare&,
1043 detail::_disabled_system_error_operator<__LINE__>>::type _lhs,
1044 const _RhsT &_rhs) _STDEX_NOEXCEPT_FUNCTION
1046 return !(_lhs == _rhs);
1049 template<
class _LhsT>
1053 typename conditional<
1054 bool( detail::_is_error_condition_enum_or_class<_LhsT>::value ==
bool(
true) ),
1055 const detail::_error_condition_compare&,
1056 detail::_disabled_system_error_operator<__LINE__>>::type _rhs) _STDEX_NOEXCEPT_FUNCTION
1058 return !(_lhs == _rhs);
1061 template<
class _RhsT>
1064 typename conditional<
1065 bool( detail::_is_error_condition_enum_not_class<_RhsT>::value ==
bool(
true) ),
1066 const detail::_error_condition_compare&,
1067 detail::_disabled_system_error_operator<__LINE__>>::type _lhs,
1068 const _RhsT &_rhs) _STDEX_NOEXCEPT_FUNCTION
1070 return !(_lhs == _rhs);
1081 inline error_condition
1082 error_category::default_error_condition(
int _Errval)
const _STDEX_NOEXCEPT_FUNCTION
1084 return (error_condition(_Errval, *
this));
1088 error_category::equivalent(
int _Errval,
1089 const error_condition& _Cond)
const _STDEX_NOEXCEPT_FUNCTION
1091 return (default_error_condition(_Errval) == _Cond);
1095 error_category::equivalent(
const error_code& _Code,
1096 int _Errval)
const _STDEX_NOEXCEPT_FUNCTION
1098 return (*
this == _Code.category() && _Code.value() == _Errval);
1102 inline error_condition error_code::default_error_condition() const _STDEX_NOEXCEPT_FUNCTION
1104 return (category().default_error_condition(value()));
1108 inline error_code make_error_code(errc::type _Errno) _STDEX_NOEXCEPT_FUNCTION
1110 return (error_code((
int) _Errno, generic_category()));
1113 inline error_code make_error_code(io_errc::type _Errno) _STDEX_NOEXCEPT_FUNCTION
1115 return (error_code((
int) _Errno, iostream_category()));
1119 inline error_condition make_error_condition(errc::type _Errno) _STDEX_NOEXCEPT_FUNCTION
1121 return (error_condition((
int) _Errno, generic_category()));
1124 inline error_condition make_error_condition(io_errc::type _Errno) _STDEX_NOEXCEPT_FUNCTION
1126 return (error_condition((
int) _Errno, iostream_category()));
1131 namespace system_error_detail
1133 template<
bool,
class>
1134 struct _has_conforming_strerror_s;
1135 struct _has_nonconforming_strerror_s;
1136 struct _has_conforming_strerrorlen_s;
1138 class _strerror_s_arg;
1140 class _strerrorlen_s_arg;
1148stdex::detail::system_error_detail::_strerror_s_arg
1150 stdex::detail::system_error_detail::_strerror_s_arg,
1151 stdex::detail::system_error_detail::_strerror_s_arg
1153stdex::detail::system_error_detail::_strerror_s_arg
1155 stdex::detail::system_error_detail::_strerror_s_arg,
1156 stdex::detail::system_error_detail::_strerror_s_arg,
1157 stdex::detail::system_error_detail::_strerror_s_arg
1159stdex::detail::system_error_detail::_strerrorlen_s_arg
1161 stdex::detail::system_error_detail::_strerrorlen_s_arg
1168 namespace system_error_detail
1171 static const char* _unknown_error()
1172 {
return "unknown error";}
1174 template<
bool,
bool,
class _DummyT>
1175 struct strerror_impl_helper
1177 static std::string call(_DummyT _Errcode)
1179 using namespace std;
1181 const char *result =
1184 return result ? result :
"";
1188 template<
class _DummyT>
1189 struct strerror_impl_helper<true, true, _DummyT>
1191 static std::string call(_DummyT _Errcode)
1193 using namespace std;
1197 size_t len = strerrorlen_s(_Errcode);
1203 ~_RAII() {
delete [] buf;}
1206 _tmp.buf =
new char[len + 1];
1207 if(0 == strerror_s(_tmp.buf, len + 1, _Errcode))
1214 template<
class _DummyT>
1215 struct strerror_impl_helper<true, false, _DummyT>
1217 static std::string call(_DummyT _Errcode)
1221 char buf[2048] = {0};
1223 if(0 == strerror_s(buf, _Errcode))
1229 class _strerror_s_arg
1231 typedef int return_type;
1232 char buf[
sizeof(return_type) * 14];
1233 _strerror_s_arg(...);
1234 operator return_type();
1236 template<
bool,
class>
1237 friend struct _has_conforming_strerror_s;
1238 friend struct _has_nonconforming_strerror_s;
1241 class _strerrorlen_s_arg
1243 typedef std::size_t return_type;
1244 char buf[
sizeof(return_type) * 12];
1245 _strerrorlen_s_arg(...);
1246 operator return_type();
1248 friend struct _has_conforming_strerrorlen_s;
1251 struct _has_conforming_strerrorlen_s
1253 static const bool value =
1255 strerrorlen_s(*_declptr<int>())
1256 ) !=
sizeof(_strerrorlen_s_arg);
1259 template<
bool,
class _T>
1260 struct _has_conforming_strerror_s
1262 static const bool value =
1264 strerror_s(_declptr<_T>(), *_declptr<std::size_t>(), *_declptr<int>())
1265 ) !=
sizeof(_strerror_s_arg);
1269 struct _has_conforming_strerror_s<true, _T>
1270 : stdex::false_type {};
1272 struct _has_nonconforming_strerror_s
1274 static const bool value =
1276 strerror_s(_declptr<_strerror_s_arg>()->buf, *_declptr<int>())
1277 ) !=
sizeof(_strerror_s_arg);
1281 stdex::bool_constant<
1282 _has_conforming_strerror_s<_has_nonconforming_strerror_s::value, char>::value ||
1283 _has_nonconforming_strerror_s::value
1286 struct strerror_impl:
1287 strerror_impl_helper<_has_strerror_s::value, _has_conforming_strerrorlen_s::value, int>
1290 static inline std::string _strerror(
int _errnum)
1292 std::string result =
1293 strerror_impl::call(_errnum);
1296 return _unknown_error();
1300 static inline bool _is_valid_errnum(
int _errnum)
1303 !strerror_impl::call(_errnum).empty();
1307 using system_error_detail::_strerror;
1308 using system_error_detail::_is_valid_errnum;
1311 class _generic_error_category
1312 :
public error_category
1315 _generic_error_category()
1319 virtual const char *name() const _STDEX_NOEXCEPT_FUNCTION
1324 virtual std::string message(
int _Errcode)
const
1326 return _strerror(_Errcode);
1330 class _io_stream_error_category
1331 :
public _generic_error_category
1334 _io_stream_error_category()
1338 virtual const char *name() const _STDEX_NOEXCEPT_FUNCTION
1340 return (
"iostream");
1343 virtual std::string message(
int _Errcode)
const
1345 if (_Errcode == (
int) io_errc::stream)
1346 return (
"iostream stream error");
1348 return (_generic_error_category::message(_Errcode));
1352 class _system_error_category
1353 :
public _generic_error_category
1356 _system_error_category()
1360 virtual const char *name() const _STDEX_NOEXCEPT_FUNCTION
1365 virtual std::string message(
int _Errcode)
const
1367 return _strerror(_Errcode);
1370 virtual error_condition
1371 default_error_condition(
int _Errval)
const _STDEX_NOEXCEPT_FUNCTION
1373 if (_is_valid_errnum(_Errval))
1374 return (error_condition(_Errval, generic_category()));
1376 return (error_condition(_Errval, system_category()));
1380 template<
class _Cat>
1381 struct _error_objects
1383 static _Cat &_object()
1385 static _Cat &_obj = *(
new _Cat());
1391 inline const error_category& generic_category() _STDEX_NOEXCEPT_FUNCTION
1393 return (detail::_error_objects<detail::_generic_error_category>::_object());
1396 inline const error_category& iostream_category() _STDEX_NOEXCEPT_FUNCTION
1398 return (detail::_error_objects<detail::_io_stream_error_category>::_object());
1401 inline const error_category& system_category() _STDEX_NOEXCEPT_FUNCTION
1403 return (detail::_error_objects<detail::_system_error_category>::_object());
1412 static stdex::error_code _make_error_code(_Tp _val)
1414 return make_error_code(_val);
1419 static stdex::error_condition _make_error_condition(_Tp _val)
1421 return make_error_condition(_val);
1425#undef _STDEX_DELETED_FUNCTION
1426#undef _STDEX_NOEXCEPT_FUNCTION