error_code.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. #ifndef BOOST_SYSTEM_DETAIL_ERROR_CODE_HPP_INCLUDED
  2. #define BOOST_SYSTEM_DETAIL_ERROR_CODE_HPP_INCLUDED
  3. // Copyright Beman Dawes 2006, 2007
  4. // Copyright Christoper Kohlhoff 2007
  5. // Copyright Peter Dimov 2017-2021
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See library home page at http://www.boost.org/libs/system
  11. #include <boost/system/is_error_code_enum.hpp>
  12. #include <boost/system/detail/error_category.hpp>
  13. #include <boost/system/detail/error_condition.hpp>
  14. #include <boost/system/detail/system_category.hpp>
  15. #include <boost/system/detail/system_category_impl.hpp>
  16. #include <boost/system/detail/interop_category.hpp>
  17. #include <boost/system/detail/enable_if.hpp>
  18. #include <boost/system/detail/is_same.hpp>
  19. #include <boost/system/detail/append_int.hpp>
  20. #include <boost/system/detail/snprintf.hpp>
  21. #include <boost/system/detail/config.hpp>
  22. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  23. # include <boost/system/detail/std_category.hpp>
  24. #endif
  25. #include <boost/assert/source_location.hpp>
  26. #include <boost/cstdint.hpp>
  27. #include <boost/config.hpp>
  28. #include <boost/config/workaround.hpp>
  29. #include <ostream>
  30. #include <new>
  31. #include <cstdio>
  32. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  33. # include <system_error>
  34. #endif
  35. #if defined(BOOST_GCC) && BOOST_GCC >= 40600 && BOOST_GCC < 70000
  36. # pragma GCC diagnostic push
  37. # pragma GCC diagnostic ignored "-Wstrict-aliasing"
  38. #endif
  39. namespace boost
  40. {
  41. namespace system
  42. {
  43. // class error_code
  44. // We want error_code to be a value type that can be copied without slicing
  45. // and without requiring heap allocation, but we also want it to have
  46. // polymorphic behavior based on the error category. This is achieved by
  47. // abstract base class error_category supplying the polymorphic behavior,
  48. // and error_code containing a pointer to an object of a type derived
  49. // from error_category.
  50. bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT;
  51. std::size_t hash_value( error_code const & ec );
  52. class error_code
  53. {
  54. private:
  55. friend bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT;
  56. friend std::size_t hash_value( error_code const & ec );
  57. private:
  58. struct data
  59. {
  60. int val_;
  61. const error_category * cat_;
  62. };
  63. union
  64. {
  65. data d1_;
  66. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  67. unsigned char d2_[ sizeof(std::error_code) ];
  68. #endif
  69. };
  70. // 0: default constructed, d1_ value initialized
  71. // 1: holds std::error_code in d2_
  72. // 2: holds error code in d1_, failed == false
  73. // 3: holds error code in d1_, failed == true
  74. // >3: pointer to source_location, failed_ in lsb
  75. boost::uintptr_t lc_flags_;
  76. private:
  77. char const* category_name() const BOOST_NOEXCEPT
  78. {
  79. // return category().name();
  80. if( lc_flags_ == 0 )
  81. {
  82. // must match detail::system_error_category::name()
  83. return "system";
  84. }
  85. else if( lc_flags_ == 1 )
  86. {
  87. // must match detail::interop_error_category::name()
  88. return "std:unknown";
  89. }
  90. else
  91. {
  92. return d1_.cat_->name();
  93. }
  94. }
  95. public:
  96. // constructors:
  97. #if !BOOST_WORKAROUND(BOOST_GCC, < 40800)
  98. BOOST_CONSTEXPR
  99. #endif
  100. error_code() BOOST_NOEXCEPT:
  101. d1_(), lc_flags_( 0 )
  102. {
  103. }
  104. BOOST_SYSTEM_CONSTEXPR error_code( int val, const error_category & cat ) BOOST_NOEXCEPT:
  105. d1_(), lc_flags_( 2 + detail::failed_impl( val, cat ) )
  106. {
  107. d1_.val_ = val;
  108. d1_.cat_ = &cat;
  109. }
  110. error_code( int val, const error_category & cat, source_location const * loc ) BOOST_NOEXCEPT:
  111. d1_(), lc_flags_( ( loc? reinterpret_cast<boost::uintptr_t>( loc ): 2 ) | +detail::failed_impl( val, cat ) )
  112. {
  113. d1_.val_ = val;
  114. d1_.cat_ = &cat;
  115. }
  116. template<class ErrorCodeEnum> BOOST_SYSTEM_CONSTEXPR error_code( ErrorCodeEnum e,
  117. typename detail::enable_if<
  118. is_error_code_enum<ErrorCodeEnum>::value
  119. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  120. || std::is_error_code_enum<ErrorCodeEnum>::value
  121. #endif
  122. >::type* = 0 ) BOOST_NOEXCEPT: d1_(), lc_flags_( 0 )
  123. {
  124. *this = make_error_code( e );
  125. }
  126. error_code( error_code const& ec, source_location const * loc ) BOOST_NOEXCEPT:
  127. d1_(), lc_flags_( 0 )
  128. {
  129. *this = ec;
  130. if( ec.lc_flags_ != 0 && ec.lc_flags_ != 1 )
  131. {
  132. lc_flags_ = ( loc? reinterpret_cast<boost::uintptr_t>( loc ): 2 ) | ( ec.lc_flags_ & 1 );
  133. }
  134. }
  135. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  136. error_code( std::error_code const& ec ) BOOST_NOEXCEPT:
  137. d1_(), lc_flags_( 0 )
  138. {
  139. #ifndef BOOST_NO_RTTI
  140. if( detail::std_category const* pc2 = dynamic_cast< detail::std_category const* >( &ec.category() ) )
  141. {
  142. *this = boost::system::error_code( ec.value(), pc2->original_category() );
  143. }
  144. else
  145. #endif
  146. {
  147. ::new( d2_ ) std::error_code( ec );
  148. lc_flags_ = 1;
  149. }
  150. }
  151. #endif
  152. // modifiers:
  153. BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
  154. {
  155. *this = error_code( val, cat );
  156. }
  157. void assign( int val, const error_category & cat, source_location const * loc ) BOOST_NOEXCEPT
  158. {
  159. *this = error_code( val, cat, loc );
  160. }
  161. void assign( error_code const& ec, source_location const * loc ) BOOST_NOEXCEPT
  162. {
  163. *this = error_code( ec, loc );
  164. }
  165. template<typename ErrorCodeEnum>
  166. BOOST_SYSTEM_CONSTEXPR typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value, error_code>::type &
  167. operator=( ErrorCodeEnum val ) BOOST_NOEXCEPT
  168. {
  169. *this = make_error_code( val );
  170. return *this;
  171. }
  172. BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
  173. {
  174. *this = error_code();
  175. }
  176. // observers:
  177. BOOST_SYSTEM_CONSTEXPR int value() const BOOST_NOEXCEPT
  178. {
  179. if( lc_flags_ != 1 )
  180. {
  181. return d1_.val_;
  182. }
  183. else
  184. {
  185. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  186. std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
  187. unsigned cv = static_cast<unsigned>( ec.value() );
  188. unsigned ch = static_cast<unsigned>( reinterpret_cast<boost::uintptr_t>( &ec.category() ) % 2097143 ); // 2^21-9, prime
  189. return static_cast<int>( cv + 1000 * ch );
  190. #else
  191. return -1;
  192. #endif
  193. }
  194. }
  195. BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_NOEXCEPT
  196. {
  197. if( lc_flags_ == 0 )
  198. {
  199. return system_category();
  200. }
  201. else if( lc_flags_ == 1 )
  202. {
  203. return detail::interop_category();
  204. }
  205. else
  206. {
  207. return *d1_.cat_;
  208. }
  209. }
  210. // deprecated?
  211. error_condition default_error_condition() const BOOST_NOEXCEPT
  212. {
  213. return category().default_error_condition( value() );
  214. }
  215. std::string message() const
  216. {
  217. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  218. if( lc_flags_ == 1 )
  219. {
  220. std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
  221. return ec.message();
  222. }
  223. #endif
  224. if( lc_flags_ == 0 )
  225. {
  226. return detail::system_error_category_message( value() );
  227. }
  228. else
  229. {
  230. return category().message( value() );
  231. }
  232. }
  233. char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
  234. {
  235. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  236. if( lc_flags_ == 1 )
  237. {
  238. std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
  239. #if !defined(BOOST_NO_EXCEPTIONS)
  240. try
  241. #endif
  242. {
  243. detail::snprintf( buffer, len, "%s", ec.message().c_str() );
  244. return buffer;
  245. }
  246. #if !defined(BOOST_NO_EXCEPTIONS)
  247. catch( ... )
  248. {
  249. detail::snprintf( buffer, len, "No message text available for error std:%s:%d", ec.category().name(), ec.value() );
  250. return buffer;
  251. }
  252. #endif
  253. }
  254. #endif
  255. if( lc_flags_ == 0 )
  256. {
  257. return detail::system_error_category_message( value(), buffer, len );
  258. }
  259. else
  260. {
  261. return category().message( value(), buffer, len );
  262. }
  263. }
  264. BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
  265. {
  266. if( lc_flags_ & 1 )
  267. {
  268. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  269. if( lc_flags_ == 1 )
  270. {
  271. std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
  272. return ec.value() != 0;
  273. }
  274. #endif
  275. return true;
  276. }
  277. else
  278. {
  279. return false;
  280. }
  281. }
  282. #if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
  283. BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error
  284. {
  285. return failed();
  286. }
  287. #else
  288. typedef void (*unspecified_bool_type)();
  289. static void unspecified_bool_true() {}
  290. BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
  291. {
  292. return failed()? unspecified_bool_true: 0;
  293. }
  294. BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
  295. {
  296. return !failed();
  297. }
  298. #endif
  299. bool has_location() const BOOST_NOEXCEPT
  300. {
  301. return lc_flags_ >= 4;
  302. }
  303. source_location const & location() const BOOST_NOEXCEPT
  304. {
  305. BOOST_STATIC_CONSTEXPR source_location loc;
  306. return lc_flags_ >= 4? *reinterpret_cast<source_location const*>( lc_flags_ &~ static_cast<boost::uintptr_t>( 1 ) ): loc;
  307. }
  308. // relationals:
  309. private:
  310. // private equality for use in error_category::equivalent
  311. friend class error_category;
  312. BOOST_SYSTEM_CONSTEXPR bool equals( int val, error_category const& cat ) const BOOST_NOEXCEPT
  313. {
  314. if( lc_flags_ == 0 )
  315. {
  316. return val == 0 && cat.id_ == detail::system_category_id;
  317. }
  318. else if( lc_flags_ == 1 )
  319. {
  320. return cat.id_ == detail::interop_category_id && val == value();
  321. }
  322. else
  323. {
  324. return val == d1_.val_ && cat == *d1_.cat_;
  325. }
  326. }
  327. public:
  328. // the more symmetrical non-member syntax allows enum
  329. // conversions work for both rhs and lhs.
  330. BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
  331. {
  332. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  333. bool s1 = lhs.lc_flags_ == 1;
  334. bool s2 = rhs.lc_flags_ == 1;
  335. if( s1 != s2 ) return false;
  336. if( s1 && s2 )
  337. {
  338. std::error_code const& e1 = *reinterpret_cast<std::error_code const*>( lhs.d2_ );
  339. std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( rhs.d2_ );
  340. return e1 == e2;
  341. }
  342. else
  343. #endif
  344. {
  345. return lhs.value() == rhs.value() && lhs.category() == rhs.category();
  346. }
  347. }
  348. BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
  349. {
  350. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  351. bool s1 = lhs.lc_flags_ == 1;
  352. bool s2 = rhs.lc_flags_ == 1;
  353. if( s1 < s2 ) return true;
  354. if( s2 < s1 ) return false;
  355. if( s1 && s2 )
  356. {
  357. std::error_code const& e1 = *reinterpret_cast<std::error_code const*>( lhs.d2_ );
  358. std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( rhs.d2_ );
  359. return e1 < e2;
  360. }
  361. else
  362. #endif
  363. {
  364. return lhs.category() < rhs.category() || (lhs.category() == rhs.category() && lhs.value() < rhs.value());
  365. }
  366. }
  367. BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
  368. {
  369. return !( lhs == rhs );
  370. }
  371. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  372. inline friend bool operator==( std::error_code const & lhs, error_code const & rhs ) BOOST_NOEXCEPT
  373. {
  374. return lhs == static_cast< std::error_code >( rhs );
  375. }
  376. inline friend bool operator==( error_code const & lhs, std::error_code const & rhs ) BOOST_NOEXCEPT
  377. {
  378. return static_cast< std::error_code >( lhs ) == rhs;
  379. }
  380. inline friend bool operator!=( std::error_code const & lhs, error_code const & rhs ) BOOST_NOEXCEPT
  381. {
  382. return !( lhs == rhs );
  383. }
  384. inline friend bool operator!=( error_code const & lhs, std::error_code const & rhs ) BOOST_NOEXCEPT
  385. {
  386. return !( lhs == rhs );
  387. }
  388. //
  389. template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
  390. inline friend bool operator==( error_code const & lhs, E rhs ) BOOST_NOEXCEPT
  391. {
  392. return lhs == make_error_condition( rhs );
  393. }
  394. template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
  395. inline friend bool operator==( E lhs, error_code const & rhs ) BOOST_NOEXCEPT
  396. {
  397. return make_error_condition( lhs ) == rhs;
  398. }
  399. template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
  400. inline friend bool operator!=( error_code const & lhs, E rhs ) BOOST_NOEXCEPT
  401. {
  402. return !( lhs == rhs );
  403. }
  404. template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
  405. inline friend bool operator!=( E lhs, error_code const & rhs ) BOOST_NOEXCEPT
  406. {
  407. return !( lhs == rhs );
  408. }
  409. //
  410. template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
  411. BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( error_code const & lhs, E rhs ) BOOST_NOEXCEPT
  412. {
  413. return lhs == make_error_code( rhs );
  414. }
  415. template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
  416. BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( E lhs, error_code const & rhs ) BOOST_NOEXCEPT
  417. {
  418. return make_error_code( lhs ) == rhs;
  419. }
  420. template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
  421. BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( error_code const & lhs, E rhs ) BOOST_NOEXCEPT
  422. {
  423. return !( lhs == rhs );
  424. }
  425. template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
  426. BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( E lhs, error_code const & rhs ) BOOST_NOEXCEPT
  427. {
  428. return !( lhs == rhs );
  429. }
  430. #if defined(BOOST_SYSTEM_CLANG_6)
  431. inline friend bool operator==( error_code const & lhs, std::error_condition const & rhs ) BOOST_NOEXCEPT
  432. {
  433. return static_cast< std::error_code >( lhs ) == rhs;
  434. }
  435. inline friend bool operator==( std::error_condition const & lhs, error_code const & rhs ) BOOST_NOEXCEPT
  436. {
  437. return lhs == static_cast< std::error_code >( rhs );
  438. }
  439. inline friend bool operator!=( error_code const & lhs, std::error_condition const & rhs ) BOOST_NOEXCEPT
  440. {
  441. return !( lhs == rhs );
  442. }
  443. inline friend bool operator!=( std::error_condition const & lhs, error_code const & rhs ) BOOST_NOEXCEPT
  444. {
  445. return !( lhs == rhs );
  446. }
  447. #endif
  448. // conversions
  449. operator std::error_code () const
  450. {
  451. if( lc_flags_ == 1 )
  452. {
  453. return *reinterpret_cast<std::error_code const*>( d2_ );
  454. }
  455. else if( lc_flags_ == 0 )
  456. {
  457. // This condition must be the same as the one in error_category_impl.hpp
  458. #if defined(BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY)
  459. return std::error_code( 0, boost::system::system_category() );
  460. #else
  461. return std::error_code();
  462. #endif
  463. }
  464. else
  465. {
  466. return std::error_code( d1_.val_, *d1_.cat_ );
  467. }
  468. }
  469. operator std::error_code ()
  470. {
  471. return const_cast<error_code const&>( *this );
  472. }
  473. template<class T,
  474. class E = typename detail::enable_if<detail::is_same<T, std::error_code>::value>::type>
  475. operator T& ()
  476. {
  477. if( lc_flags_ != 1 )
  478. {
  479. std::error_code e2( *this );
  480. ::new( d2_ ) std::error_code( e2 );
  481. lc_flags_ = 1;
  482. }
  483. return *reinterpret_cast<std::error_code*>( d2_ );
  484. }
  485. #if defined(BOOST_SYSTEM_CLANG_6)
  486. template<class T,
  487. class E = typename std::enable_if<std::is_same<T, std::error_code>::value>::type>
  488. operator T const& () = delete;
  489. #endif
  490. #endif
  491. std::string to_string() const
  492. {
  493. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  494. if( lc_flags_ == 1 )
  495. {
  496. std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( d2_ );
  497. std::string r( "std:" );
  498. r += e2.category().name();
  499. detail::append_int( r, e2.value() );
  500. return r;
  501. }
  502. else
  503. #endif
  504. {
  505. std::string r = category_name();
  506. detail::append_int( r, value() );
  507. return r;
  508. }
  509. }
  510. template<class Ch, class Tr>
  511. inline friend std::basic_ostream<Ch, Tr>&
  512. operator<< (std::basic_ostream<Ch, Tr>& os, error_code const & ec)
  513. {
  514. return os << ec.to_string().c_str();
  515. }
  516. std::string what() const
  517. {
  518. std::string r = message();
  519. r += " [";
  520. r += to_string();
  521. if( has_location() )
  522. {
  523. r += " at ";
  524. r += location().to_string();
  525. }
  526. r += "]";
  527. return r;
  528. }
  529. };
  530. inline bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
  531. {
  532. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  533. if( code.lc_flags_ == 1 )
  534. {
  535. return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
  536. }
  537. else
  538. #endif
  539. {
  540. return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
  541. }
  542. }
  543. inline bool operator==( const error_condition & condition, const error_code & code ) BOOST_NOEXCEPT
  544. {
  545. return code == condition;
  546. }
  547. inline bool operator!=( const error_code & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
  548. {
  549. return !( lhs == rhs );
  550. }
  551. inline bool operator!=( const error_condition & lhs, const error_code & rhs ) BOOST_NOEXCEPT
  552. {
  553. return !( lhs == rhs );
  554. }
  555. inline std::size_t hash_value( error_code const & ec )
  556. {
  557. #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
  558. if( ec.lc_flags_ == 1 )
  559. {
  560. std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( ec.d2_ );
  561. return std::hash<std::error_code>()( e2 );
  562. }
  563. #endif
  564. error_category const & cat = ec.category();
  565. boost::ulong_long_type id_ = cat.id_;
  566. if( id_ == 0 )
  567. {
  568. id_ = reinterpret_cast<boost::uintptr_t>( &cat );
  569. }
  570. boost::ulong_long_type hv = ( boost::ulong_long_type( 0xCBF29CE4 ) << 32 ) + 0x84222325;
  571. boost::ulong_long_type const prime = ( boost::ulong_long_type( 0x00000100 ) << 32 ) + 0x000001B3;
  572. // id
  573. hv ^= id_;
  574. hv *= prime;
  575. // value
  576. hv ^= static_cast<unsigned>( ec.value() );
  577. hv *= prime;
  578. return static_cast<std::size_t>( hv );
  579. }
  580. } // namespace system
  581. } // namespace boost
  582. #if defined(BOOST_GCC) && BOOST_GCC >= 40600 && BOOST_GCC < 70000
  583. # pragma GCC diagnostic pop
  584. #endif
  585. #endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CODE_HPP_INCLUDED