std_category.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED
  2. #define BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED
  3. // Support for interoperability between Boost.System and <system_error>
  4. //
  5. // Copyright 2018, 2021 Peter Dimov
  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/detail/error_category.hpp>
  12. #include <boost/config.hpp>
  13. #include <system_error>
  14. //
  15. namespace boost
  16. {
  17. namespace system
  18. {
  19. namespace detail
  20. {
  21. template<unsigned Id> struct id_wrapper {};
  22. class BOOST_SYMBOL_VISIBLE std_category: public std::error_category
  23. {
  24. private:
  25. boost::system::error_category const * pc_;
  26. public:
  27. boost::system::error_category const & original_category() const BOOST_NOEXCEPT
  28. {
  29. return *pc_;
  30. }
  31. public:
  32. template<unsigned Id>
  33. explicit std_category( boost::system::error_category const * pc, id_wrapper<Id> ): pc_( pc )
  34. {
  35. #if defined(_MSC_VER) && defined(_CPPLIB_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000
  36. // We used to assign to the protected _Addr member of std::error_category
  37. // here when Id != 0, but this should never happen now because this code
  38. // path is no longer used
  39. #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
  40. static_assert( Id == 0, "This constructor should only be called with Id == 0 under MS STL 14.0+" );
  41. #endif
  42. #endif
  43. }
  44. const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
  45. {
  46. return pc_->name();
  47. }
  48. std::string message( int ev ) const BOOST_OVERRIDE
  49. {
  50. return pc_->message( ev );
  51. }
  52. std::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT BOOST_OVERRIDE
  53. {
  54. return pc_->default_error_condition( ev );
  55. }
  56. inline bool equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
  57. inline bool equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
  58. };
  59. } // namespace detail
  60. } // namespace system
  61. } // namespace boost
  62. #endif // #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED