std_category.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 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. static_assert( Id == 0, "This constructor should only be called with Id == 0 under MS STL 14.0+" );
  40. #endif
  41. }
  42. const char * name() const noexcept BOOST_OVERRIDE
  43. {
  44. return pc_->name();
  45. }
  46. std::string message( int ev ) const BOOST_OVERRIDE
  47. {
  48. return pc_->message( ev );
  49. }
  50. std::error_condition default_error_condition( int ev ) const noexcept BOOST_OVERRIDE
  51. {
  52. return pc_->default_error_condition( ev );
  53. }
  54. inline bool equivalent( int code, const std::error_condition & condition ) const noexcept BOOST_OVERRIDE;
  55. inline bool equivalent( const std::error_code & code, int condition ) const noexcept BOOST_OVERRIDE;
  56. };
  57. } // namespace detail
  58. } // namespace system
  59. } // namespace boost
  60. #endif // #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED