summaryrefslogtreecommitdiff
path: root/boost/system/error_code.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/system/error_code.hpp')
-rw-r--r--boost/system/error_code.hpp1376
1 files changed, 694 insertions, 682 deletions
diff --git a/boost/system/error_code.hpp b/boost/system/error_code.hpp
index c70ea04b5e..d0c27353ad 100644
--- a/boost/system/error_code.hpp
+++ b/boost/system/error_code.hpp
@@ -1,944 +1,956 @@
-// boost/system/error_code.hpp -------------------------------------------------------//
+#ifndef BOOST_SYSTEM_ERROR_CODE_HPP_INCLUDED
+#define BOOST_SYSTEM_ERROR_CODE_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018
-
+//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-
+//
// See library home page at http://www.boost.org/libs/system
-#ifndef BOOST_SYSTEM_ERROR_CODE_HPP
-#define BOOST_SYSTEM_ERROR_CODE_HPP
-
-#include <boost/system/config.hpp>
+#include <boost/system/api_config.hpp>
+#include <boost/system/detail/config.hpp>
#include <boost/cstdint.hpp>
-#include <boost/assert.hpp>
-#include <boost/noncopyable.hpp>
-#include <boost/utility/enable_if.hpp>
+#include <boost/config.hpp>
#include <ostream>
#include <string>
-#include <stdexcept>
#include <functional>
+#include <cstring>
// TODO: undef these macros if not already defined
#include <boost/cerrno.hpp>
-#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
-# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
+#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
+# include <system_error>
#endif
-#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR
-#include <system_error>
+#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
+# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
#endif
-#include <boost/config/abi_prefix.hpp> // must be the last #include
+namespace boost
+{
-#ifndef BOOST_SYSTEM_NOEXCEPT
-#define BOOST_SYSTEM_NOEXCEPT BOOST_NOEXCEPT
-#endif
+namespace system
+{
-#if !defined(BOOST_NO_CXX14_CONSTEXPR)
-# define BOOST_SYSTEM_HAS_CONSTEXPR
-#endif
+class error_code; // values defined by the operating system
+class error_condition; // portable generic values defined below, but ultimately
+ // based on the POSIX standard
-#if defined(__GNUC__) && (__GNUC__ == 7 && __GNUC_MINOR__ < 4) && __cplusplus >= 201700L
-// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83835
-# undef BOOST_SYSTEM_HAS_CONSTEXPR
-#endif
+// "Concept" helpers
-#if defined(__clang__) && defined(_MSC_VER) && defined(_CPPLIB_VER)
-// Clang on Windows with MSVC headers, the constructor of std::error_category
-// is not constexpr at least up to VS2017 15.7.x (_MSVC_STL_UPDATE 201803)
-# undef BOOST_SYSTEM_HAS_CONSTEXPR
-#endif
+template<class T> struct is_error_code_enum
+{
+ static const bool value = false;
+};
-#if defined(__clang__) && defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 40900
-// The constructor of std::error_category is not constexpr in libstdc++ 4.8
-# undef BOOST_SYSTEM_HAS_CONSTEXPR
-#endif
+template<class T> struct is_error_condition_enum
+{
+ static const bool value = false;
+};
-#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
-# define BOOST_SYSTEM_CONSTEXPR constexpr
-#else
-# define BOOST_SYSTEM_CONSTEXPR
-#endif
+// Generic error_conditions
-namespace boost
+namespace errc
{
- namespace system
- {
-
- class error_code; // values defined by the operating system
- class error_condition; // portable generic values defined below, but ultimately
- // based on the POSIX standard
-
- // "Concept" helpers -------------------------------------------------------------//
-
- template< class T >
- struct is_error_code_enum { static const bool value = false; };
-
- template< class T >
- struct is_error_condition_enum { static const bool value = false; };
-
- // generic error_conditions ------------------------------------------------------//
-
- namespace errc
- {
- enum errc_t
- {
- success = 0,
- address_family_not_supported = EAFNOSUPPORT,
- address_in_use = EADDRINUSE,
- address_not_available = EADDRNOTAVAIL,
- already_connected = EISCONN,
- argument_list_too_long = E2BIG,
- argument_out_of_domain = EDOM,
- bad_address = EFAULT,
- bad_file_descriptor = EBADF,
- bad_message = EBADMSG,
- broken_pipe = EPIPE,
- connection_aborted = ECONNABORTED,
- connection_already_in_progress = EALREADY,
- connection_refused = ECONNREFUSED,
- connection_reset = ECONNRESET,
- cross_device_link = EXDEV,
- destination_address_required = EDESTADDRREQ,
- device_or_resource_busy = EBUSY,
- directory_not_empty = ENOTEMPTY,
- executable_format_error = ENOEXEC,
- file_exists = EEXIST,
- file_too_large = EFBIG,
- filename_too_long = ENAMETOOLONG,
- function_not_supported = ENOSYS,
- host_unreachable = EHOSTUNREACH,
- identifier_removed = EIDRM,
- illegal_byte_sequence = EILSEQ,
- inappropriate_io_control_operation = ENOTTY,
- interrupted = EINTR,
- invalid_argument = EINVAL,
- invalid_seek = ESPIPE,
- io_error = EIO,
- is_a_directory = EISDIR,
- message_size = EMSGSIZE,
- network_down = ENETDOWN,
- network_reset = ENETRESET,
- network_unreachable = ENETUNREACH,
- no_buffer_space = ENOBUFS,
- no_child_process = ECHILD,
- no_link = ENOLINK,
- no_lock_available = ENOLCK,
- no_message_available = ENODATA,
- no_message = ENOMSG,
- no_protocol_option = ENOPROTOOPT,
- no_space_on_device = ENOSPC,
- no_stream_resources = ENOSR,
- no_such_device_or_address = ENXIO,
- no_such_device = ENODEV,
- no_such_file_or_directory = ENOENT,
- no_such_process = ESRCH,
- not_a_directory = ENOTDIR,
- not_a_socket = ENOTSOCK,
- not_a_stream = ENOSTR,
- not_connected = ENOTCONN,
- not_enough_memory = ENOMEM,
- not_supported = ENOTSUP,
- operation_canceled = ECANCELED,
- operation_in_progress = EINPROGRESS,
- operation_not_permitted = EPERM,
- operation_not_supported = EOPNOTSUPP,
- operation_would_block = EWOULDBLOCK,
- owner_dead = EOWNERDEAD,
- permission_denied = EACCES,
- protocol_error = EPROTO,
- protocol_not_supported = EPROTONOSUPPORT,
- read_only_file_system = EROFS,
- resource_deadlock_would_occur = EDEADLK,
- resource_unavailable_try_again = EAGAIN,
- result_out_of_range = ERANGE,
- state_not_recoverable = ENOTRECOVERABLE,
- stream_timeout = ETIME,
- text_file_busy = ETXTBSY,
- timed_out = ETIMEDOUT,
- too_many_files_open_in_system = ENFILE,
- too_many_files_open = EMFILE,
- too_many_links = EMLINK,
- too_many_symbolic_link_levels = ELOOP,
- value_too_large = EOVERFLOW,
- wrong_protocol_type = EPROTOTYPE
- };
-
- } // namespace errc
-
-# ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
- namespace posix = errc;
- namespace posix_error = errc;
-# endif
-
- template<> struct is_error_condition_enum<errc::errc_t>
- { static const bool value = true; };
+enum errc_t
+{
+ success = 0,
+ address_family_not_supported = EAFNOSUPPORT,
+ address_in_use = EADDRINUSE,
+ address_not_available = EADDRNOTAVAIL,
+ already_connected = EISCONN,
+ argument_list_too_long = E2BIG,
+ argument_out_of_domain = EDOM,
+ bad_address = EFAULT,
+ bad_file_descriptor = EBADF,
+ bad_message = EBADMSG,
+ broken_pipe = EPIPE,
+ connection_aborted = ECONNABORTED,
+ connection_already_in_progress = EALREADY,
+ connection_refused = ECONNREFUSED,
+ connection_reset = ECONNRESET,
+ cross_device_link = EXDEV,
+ destination_address_required = EDESTADDRREQ,
+ device_or_resource_busy = EBUSY,
+ directory_not_empty = ENOTEMPTY,
+ executable_format_error = ENOEXEC,
+ file_exists = EEXIST,
+ file_too_large = EFBIG,
+ filename_too_long = ENAMETOOLONG,
+ function_not_supported = ENOSYS,
+ host_unreachable = EHOSTUNREACH,
+ identifier_removed = EIDRM,
+ illegal_byte_sequence = EILSEQ,
+ inappropriate_io_control_operation = ENOTTY,
+ interrupted = EINTR,
+ invalid_argument = EINVAL,
+ invalid_seek = ESPIPE,
+ io_error = EIO,
+ is_a_directory = EISDIR,
+ message_size = EMSGSIZE,
+ network_down = ENETDOWN,
+ network_reset = ENETRESET,
+ network_unreachable = ENETUNREACH,
+ no_buffer_space = ENOBUFS,
+ no_child_process = ECHILD,
+ no_link = ENOLINK,
+ no_lock_available = ENOLCK,
+ no_message_available = ENODATA,
+ no_message = ENOMSG,
+ no_protocol_option = ENOPROTOOPT,
+ no_space_on_device = ENOSPC,
+ no_stream_resources = ENOSR,
+ no_such_device_or_address = ENXIO,
+ no_such_device = ENODEV,
+ no_such_file_or_directory = ENOENT,
+ no_such_process = ESRCH,
+ not_a_directory = ENOTDIR,
+ not_a_socket = ENOTSOCK,
+ not_a_stream = ENOSTR,
+ not_connected = ENOTCONN,
+ not_enough_memory = ENOMEM,
+ not_supported = ENOTSUP,
+ operation_canceled = ECANCELED,
+ operation_in_progress = EINPROGRESS,
+ operation_not_permitted = EPERM,
+ operation_not_supported = EOPNOTSUPP,
+ operation_would_block = EWOULDBLOCK,
+ owner_dead = EOWNERDEAD,
+ permission_denied = EACCES,
+ protocol_error = EPROTO,
+ protocol_not_supported = EPROTONOSUPPORT,
+ read_only_file_system = EROFS,
+ resource_deadlock_would_occur = EDEADLK,
+ resource_unavailable_try_again = EAGAIN,
+ result_out_of_range = ERANGE,
+ state_not_recoverable = ENOTRECOVERABLE,
+ stream_timeout = ETIME,
+ text_file_busy = ETXTBSY,
+ timed_out = ETIMEDOUT,
+ too_many_files_open_in_system = ENFILE,
+ too_many_files_open = EMFILE,
+ too_many_links = EMLINK,
+ too_many_symbolic_link_levels = ELOOP,
+ value_too_large = EOVERFLOW,
+ wrong_protocol_type = EPROTOTYPE
+};
- // --------------------------------------------------------------------------------//
+} // namespace errc
- // Operating system specific interfaces ------------------------------------------//
+#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
+namespace posix = errc;
+namespace posix_error = errc;
- // The interface is divided into general and system-specific portions to
- // meet these requirements:
- //
- // * Code calling an operating system API can create an error_code with
- // a single category (system_category), even for POSIX-like operating
- // systems that return some POSIX errno values and some native errno
- // values. This code should not have to pay the cost of distinguishing
- // between categories, since it is not yet known if that is needed.
- //
- // * Users wishing to write system-specific code should be given enums for
- // at least the common error cases.
- //
- // * System specific code should fail at compile time if moved to another
- // operating system.
+#endif
- // The system specific portions of the interface are located in headers
- // with names reflecting the operating system. For example,
- //
- // <boost/system/cygwin_error.hpp>
- // <boost/system/linux_error.hpp>
- // <boost/system/windows_error.hpp>
- //
- // These headers are effectively empty for compiles on operating systems
- // where they are not applicable.
+template<> struct is_error_condition_enum<errc::errc_t>
+{
+ static const bool value = true;
+};
- // --------------------------------------------------------------------------------//
+// class error_category
#ifdef BOOST_MSVC
-#pragma warning(push)
+#pragma warning( push )
// 'this' : used in base member initializer list
-#pragma warning(disable: 4355)
+#pragma warning( disable: 4355 )
#endif
- // class error_category ------------------------------------------------//
-
- class error_category : public noncopyable
- {
-#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR
+std::size_t hash_value( error_code const & ec );
- private:
+class BOOST_SYMBOL_VISIBLE error_category
+{
+private:
- class std_category: public std::error_category
- {
- private:
+ friend std::size_t hash_value( error_code const & ec );
- boost::system::error_category const * pc_;
+#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
+public:
- public:
+ error_category( error_category const & ) = delete;
+ error_category& operator=( error_category const & ) = delete;
- BOOST_SYSTEM_CONSTEXPR explicit std_category( boost::system::error_category const * pc ): pc_( pc )
- {
- }
+#else
+private:
- virtual const char * name() const BOOST_NOEXCEPT
- {
- return pc_->name();
- }
+ error_category( error_category const & );
+ error_category& operator=( error_category const & );
- virtual std::string message( int ev ) const
- {
- return pc_->message( ev );
- }
+#endif
- virtual std::error_condition default_error_condition( int ev ) const
- BOOST_NOEXCEPT;
- virtual bool equivalent( int code, const std::error_condition & condition ) const
- BOOST_NOEXCEPT;
- virtual bool equivalent( const std::error_code & code, int condition ) const
- BOOST_NOEXCEPT;
- };
+private:
- std_category std_cat_;
+ boost::ulong_long_type id_;
- public:
+protected:
- BOOST_SYSTEM_CONSTEXPR error_category() BOOST_SYSTEM_NOEXCEPT: std_cat_( this ) {}
+#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS)
- operator std::error_category const & () const BOOST_SYSTEM_NOEXCEPT
- {
- // do not map generic to std::generic on purpose; occasionally,
- // there are two std::generic categories in a program, which leads
- // to error codes/conditions mysteriously not being equal to themselves
- return std_cat_;
- }
+ ~error_category() = default;
#else
- // to maintain ABI compatibility between 03 and 11,
- // define a class with the same layout
+ // We'd like to make the destructor protected, to make code that deletes
+ // an error_category* not compile; unfortunately, doing the below makes
+ // the destructor user-provided and hence breaks use after main, as the
+ // categories may get destroyed before code that uses them
- private:
+ // ~error_category() {}
- class std_category
- {
- private:
-
- boost::system::error_category const * pc_;
+#endif
- public:
+ BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 )
+ {
+ }
- BOOST_SYSTEM_CONSTEXPR explicit std_category( boost::system::error_category const * pc ): pc_( pc )
- {
- }
+ explicit BOOST_SYSTEM_CONSTEXPR error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id )
+ {
+ }
- virtual ~std_category() {}
+public:
- virtual const char * name() const BOOST_NOEXCEPT
- {
- return pc_->name();
- }
+ virtual const char * name() const BOOST_NOEXCEPT = 0;
- // we can't define message, because (1) it returns an std::string,
- // which can be different between 03 and 11, and (2) on mingw, there
- // are actually two `message` functions, not one, so it doesn't work
- // even if we do
+ virtual error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT;
+ virtual bool equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT;
+ virtual bool equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT;
- // neither can we define default_error_condition or equivalent
+ virtual std::string message( int ev ) const = 0;
+ virtual char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT;
- // if these functions are called, it will crash, but that's still
- // better than the alternative of having the class layout change
- };
+ virtual bool failed( int ev ) const BOOST_NOEXCEPT;
- std_category std_cat_;
+ BOOST_SYSTEM_CONSTEXPR bool operator==( const error_category & rhs ) const BOOST_NOEXCEPT
+ {
+ return rhs.id_ == 0? this == &rhs: id_ == rhs.id_;
+ }
- public:
+ BOOST_SYSTEM_CONSTEXPR bool operator!=( const error_category & rhs ) const BOOST_NOEXCEPT
+ {
+ return !( *this == rhs );
+ }
- BOOST_SYSTEM_CONSTEXPR error_category() BOOST_SYSTEM_NOEXCEPT: std_cat_( this ) {}
+ BOOST_SYSTEM_CONSTEXPR bool operator<( const error_category & rhs ) const BOOST_NOEXCEPT
+ {
+ if( id_ < rhs.id_ )
+ {
+ return true;
+ }
-#endif
+ if( id_ > rhs.id_ )
+ {
+ return false;
+ }
- public:
- virtual ~error_category(){}
+ if( rhs.id_ != 0 )
+ {
+ return false; // equal
+ }
- virtual const char * name() const BOOST_SYSTEM_NOEXCEPT = 0;
- virtual std::string message( int ev ) const = 0;
- inline virtual error_condition default_error_condition( int ev ) const
- BOOST_SYSTEM_NOEXCEPT;
- inline virtual bool equivalent( int code,
- const error_condition & condition ) const
- BOOST_SYSTEM_NOEXCEPT;
- inline virtual bool equivalent( const error_code & code,
- int condition ) const BOOST_SYSTEM_NOEXCEPT;
- };
+ return std::less<error_category const *>()( this, &rhs );
+ }
- BOOST_SYSTEM_CONSTEXPR inline bool operator==( const error_category & lhs,
- const error_category & rhs ) BOOST_SYSTEM_NOEXCEPT
- { return &lhs == &rhs; }
+#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
- BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_category & lhs,
- const error_category & rhs ) BOOST_SYSTEM_NOEXCEPT
- { return &lhs != &rhs; }
+ operator std::error_category const & () const;
- inline bool operator<( const error_category & lhs,
- const error_category & rhs ) BOOST_SYSTEM_NOEXCEPT
- { return std::less<const error_category*>()( &lhs, &rhs ); }
+#endif
+};
#ifdef BOOST_MSVC
-#pragma warning(pop)
+#pragma warning( pop )
#endif
- // predefined error categories ---------------------------------------------------//
+// predefined error categories
namespace detail
{
-#ifdef BOOST_ERROR_CODE_HEADER_ONLY
-# define BOOST_SYSTEM_DECL_
-#else
-# define BOOST_SYSTEM_DECL_ BOOST_SYSTEM_DECL
-#endif
-
-class generic_error_category: public error_category
+class BOOST_SYMBOL_VISIBLE generic_error_category: public error_category
{
public:
// clang++ 3.8 and below: initialization of const object
// requires a user-provided default constructor
- BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_SYSTEM_NOEXCEPT
+ BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_NOEXCEPT:
+ error_category( ( boost::ulong_long_type( 0xB2AB117A ) << 32 ) + 0x257EDF0D )
{
}
- const char * name() const BOOST_SYSTEM_NOEXCEPT
+ const char * name() const BOOST_NOEXCEPT
{
return "generic";
}
- BOOST_SYSTEM_DECL_ std::string message( int ev ) const;
+ std::string message( int ev ) const;
+ char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT;
};
-class system_error_category: public error_category
+class BOOST_SYMBOL_VISIBLE system_error_category: public error_category
{
public:
- BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_SYSTEM_NOEXCEPT
+ BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_NOEXCEPT:
+ error_category( ( boost::ulong_long_type( 0x8FAFD21E ) << 32 ) + 0x25C5E09B )
{
}
- const char * name() const BOOST_SYSTEM_NOEXCEPT
+ const char * name() const BOOST_NOEXCEPT
{
return "system";
}
- BOOST_SYSTEM_DECL_ std::string message( int ev ) const;
- BOOST_SYSTEM_DECL_ error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT;
-};
+ error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT;
-#undef BOOST_SYSTEM_DECL_
+ std::string message( int ev ) const;
+ char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT;
+};
} // namespace detail
-#define BOOST_SYSTEM_REQUIRE_CONST_INIT
+// generic_category(), system_category()
-#if defined(__has_cpp_attribute)
-#if __has_cpp_attribute(clang::require_constant_initialization)
-# undef BOOST_SYSTEM_REQUIRE_CONST_INIT
-# define BOOST_SYSTEM_REQUIRE_CONST_INIT [[clang::require_constant_initialization]]
-#endif
-#endif
-
-#if defined(BOOST_ERROR_CODE_HEADER_ONLY)
-
-# if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
+#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
namespace detail
{
template<class T> struct cat_holder
{
- static system_error_category system_category_instance;
- static generic_error_category generic_category_instance;
+ BOOST_SYSTEM_REQUIRE_CONST_INIT static constexpr system_error_category system_category_instance{};
+ BOOST_SYSTEM_REQUIRE_CONST_INIT static constexpr generic_error_category generic_category_instance{};
};
-template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT system_error_category cat_holder<T>::system_category_instance;
-template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT generic_error_category cat_holder<T>::generic_category_instance;
+template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT constexpr system_error_category cat_holder<T>::system_category_instance;
+template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT constexpr generic_error_category cat_holder<T>::generic_category_instance;
} // namespace detail
-constexpr const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
+constexpr error_category const & system_category() BOOST_NOEXCEPT
{
return detail::cat_holder<void>::system_category_instance;
}
-constexpr const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
+constexpr error_category const & generic_category() BOOST_NOEXCEPT
{
return detail::cat_holder<void>::generic_category_instance;
}
-# else
+#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
-inline const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
+inline error_category const & system_category() BOOST_NOEXCEPT
{
static const detail::system_error_category system_category_instance;
return system_category_instance;
}
-inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
+inline error_category const & generic_category() BOOST_NOEXCEPT
{
static const detail::generic_error_category generic_category_instance;
return generic_category_instance;
}
-# endif
-
-#elif defined(BOOST_SYSTEM_HAS_CONSTEXPR)
-
-namespace detail
-{
+#endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
-#if defined(BOOST_SYSTEM_SOURCE)
+// deprecated synonyms
-// clang++ requires a strictly matching declaration
-BOOST_SYSTEM_DECL extern system_error_category system_category_instance;
-BOOST_SYSTEM_DECL extern generic_error_category generic_category_instance;
-
-#else
+#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
-extern system_error_category system_category_instance;
-extern generic_error_category generic_category_instance;
+inline const error_category & get_system_category() { return system_category(); }
+inline const error_category & get_generic_category() { return generic_category(); }
+inline const error_category & get_posix_category() { return generic_category(); }
+static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED = generic_category();
+static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED = generic_category();
+static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED = system_category();
#endif
-} // namespace detail
+// enable_if
-constexpr const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
+namespace detail
{
- return detail::system_category_instance;
-}
-constexpr const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
+template<bool C, class T = void> struct enable_if
{
- return detail::generic_category_instance;
-}
-
-#else
+ typedef T type;
+};
-namespace detail
+template<class T> struct enable_if<false, T>
{
+};
-BOOST_SYSTEM_DECL const error_category & system_category_ncx() BOOST_SYSTEM_NOEXCEPT;
-BOOST_SYSTEM_DECL const error_category & generic_category_ncx() BOOST_SYSTEM_NOEXCEPT;
+// failed_impl
-} // namespace detail
+#if !defined(BOOST_SYSTEM_HAS_CONSTEXPR)
-inline const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
+inline bool failed_impl( int ev, error_category const & cat )
{
- return detail::system_category_ncx();
+ return cat.failed( ev );
}
-inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
+#else
+
+BOOST_SYSTEM_CONSTEXPR inline bool failed_impl( int ev, error_category const & cat )
{
- return detail::generic_category_ncx();
+ if( cat == system_category() || cat == generic_category() )
+ {
+ return ev != 0;
+ }
+ else
+ {
+ return cat.failed( ev );
+ }
}
#endif
- // deprecated synonyms ------------------------------------------------------------//
+} // namespace detail
+
+// class error_condition
-#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
- inline const error_category & get_system_category() { return system_category(); }
- inline const error_category & get_generic_category() { return generic_category(); }
- inline const error_category & get_posix_category() { return generic_category(); }
- static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED
- = generic_category();
- static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED
- = generic_category();
- static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED
- = system_category();
-#endif
+// error_conditions are portable, error_codes are system or library specific
- // class error_condition ---------------------------------------------------------//
+class error_condition
+{
+private:
- // error_conditions are portable, error_codes are system or library specific
+ int val_;
+ bool failed_;
+ error_category const * cat_;
- class error_condition
+public:
+
+ // constructors:
+
+ BOOST_SYSTEM_CONSTEXPR error_condition() BOOST_NOEXCEPT:
+ val_( 0 ), failed_( false ), cat_( &generic_category() )
{
- public:
+ }
- // constructors:
- BOOST_SYSTEM_CONSTEXPR error_condition() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&generic_category()) {}
- BOOST_SYSTEM_CONSTEXPR error_condition( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
- : m_val(val), m_cat(&cat) {}
+ BOOST_SYSTEM_CONSTEXPR error_condition( int val, const error_category & cat ) BOOST_NOEXCEPT:
+ val_( val ), failed_( detail::failed_impl( val, cat ) ), cat_( &cat )
+ {
+ }
- template <class ErrorConditionEnum>
- error_condition(ErrorConditionEnum e,
- typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum> >::type*
- = 0) BOOST_SYSTEM_NOEXCEPT
- {
- *this = make_error_condition(e);
- }
+ template<class ErrorConditionEnum> BOOST_SYSTEM_CONSTEXPR error_condition( ErrorConditionEnum e,
+ typename detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value>::type* = 0) BOOST_NOEXCEPT
+ {
+ *this = make_error_condition( e );
+ }
- // modifiers:
+ // modifiers:
- BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
- {
- m_val = val;
- m_cat = &cat;
- }
+ BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
+ {
+ val_ = val;
+ failed_ = detail::failed_impl( val, cat );
+ cat_ = &cat;
+ }
- template<typename ErrorConditionEnum>
- typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum>,
- error_condition>::type &
- operator=( ErrorConditionEnum val ) BOOST_SYSTEM_NOEXCEPT
- {
- *this = make_error_condition(val);
+ template<typename ErrorConditionEnum>
+ BOOST_SYSTEM_CONSTEXPR typename detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value, error_condition>::type &
+ operator=( ErrorConditionEnum val ) BOOST_NOEXCEPT
+ {
+ *this = make_error_condition( val );
return *this;
- }
+ }
+
+ BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
+ {
+ val_ = 0;
+ failed_ = false;
+ cat_ = &generic_category();
+ }
+
+ // observers:
+
+ BOOST_SYSTEM_CONSTEXPR int value() const BOOST_NOEXCEPT
+ {
+ return val_;
+ }
+
+ BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_NOEXCEPT
+ {
+ return *cat_;
+ }
+
+ std::string message() const
+ {
+ return cat_->message( value() );
+ }
- BOOST_SYSTEM_CONSTEXPR void clear() BOOST_SYSTEM_NOEXCEPT
- {
- m_val = 0;
- m_cat = &generic_category();
- }
+ char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
+ {
+ return cat_->message( value(), buffer, len );
+ }
- // observers:
- BOOST_SYSTEM_CONSTEXPR int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; }
- BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; }
- std::string message() const { return m_cat->message(value()); }
+ BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
+ {
+ return failed_;
+ }
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
- BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_SYSTEM_NOEXCEPT // true if error
- {
- return m_val != 0;
- }
+ BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error
+ {
+ return failed_;
+ }
#else
- typedef void (*unspecified_bool_type)();
- static void unspecified_bool_true() {}
+ typedef void (*unspecified_bool_type)();
+ static void unspecified_bool_true() {}
- BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_SYSTEM_NOEXCEPT // true if error
- {
- return m_val == 0 ? 0 : unspecified_bool_true;
- }
+ BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
+ {
+ return failed_? unspecified_bool_true: 0;
+ }
- BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_SYSTEM_NOEXCEPT // true if no error
- {
- return m_val == 0;
- }
+ BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
+ {
+ return !failed_;
+ }
#endif
- // relationals:
- // the more symmetrical non-member syntax allows enum
- // conversions work for both rhs and lhs.
- BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_condition & lhs,
- const error_condition & rhs ) BOOST_SYSTEM_NOEXCEPT
- {
- return lhs.m_cat == rhs.m_cat && lhs.m_val == rhs.m_val;
- }
-
- inline friend bool operator<( const error_condition & lhs,
- const error_condition & rhs ) BOOST_SYSTEM_NOEXCEPT
- // the more symmetrical non-member syntax allows enum
- // conversions work for both rhs and lhs.
- {
- return lhs.m_cat < rhs.m_cat
- || (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val);
- }
-
-#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR
-
- operator std::error_condition () const BOOST_SYSTEM_NOEXCEPT
- {
- return std::error_condition( value(), category() );
- }
+ // relationals:
+ // the more symmetrical non-member syntax allows enum
+ // conversions work for both rhs and lhs.
-#endif
+ BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
+ {
+ return lhs.val_ == rhs.val_ && *lhs.cat_ == *rhs.cat_;
+ }
- private:
- int m_val;
- const error_category * m_cat;
-
- };
-
- // class error_code --------------------------------------------------------------//
-
- // We want error_code to be a value type that can be copied without slicing
- // and without requiring heap allocation, but we also want it to have
- // polymorphic behavior based on the error category. This is achieved by
- // abstract base class error_category supplying the polymorphic behavior,
- // and error_code containing a pointer to an object of a type derived
- // from error_category.
- class error_code
- {
- public:
-
- // constructors:
- BOOST_SYSTEM_CONSTEXPR error_code() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&system_category()) {}
- BOOST_SYSTEM_CONSTEXPR error_code( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
- : m_val(val), m_cat(&cat) {}
-
- template <class ErrorCodeEnum>
- error_code(ErrorCodeEnum e,
- typename boost::enable_if<is_error_code_enum<ErrorCodeEnum> >::type* = 0)
- BOOST_SYSTEM_NOEXCEPT
- {
- *this = make_error_code(e);
- }
-
- // modifiers:
- BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
- {
- m_val = val;
- m_cat = &cat;
- }
-
- template<typename ErrorCodeEnum>
- typename boost::enable_if<is_error_code_enum<ErrorCodeEnum>, error_code>::type &
- operator=( ErrorCodeEnum val ) BOOST_SYSTEM_NOEXCEPT
- {
- *this = make_error_code(val);
- return *this;
- }
+ BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
+ {
+ return *lhs.cat_ < *rhs.cat_ || ( *lhs.cat_ == *rhs.cat_ && lhs.val_ < rhs.val_ );
+ }
- BOOST_SYSTEM_CONSTEXPR void clear() BOOST_SYSTEM_NOEXCEPT
- {
- m_val = 0;
- m_cat = &system_category();
- }
+#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
- // observers:
- BOOST_SYSTEM_CONSTEXPR int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; }
- BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; }
- error_condition default_error_condition() const BOOST_SYSTEM_NOEXCEPT
- { return m_cat->default_error_condition(value()); }
- std::string message() const { return m_cat->message(value()); }
+ operator std::error_condition () const
+ {
+ return std::error_condition( value(), category() );
+ }
-#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
+#endif
+};
- BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_SYSTEM_NOEXCEPT // true if error
- {
- return m_val != 0;
- }
+// class error_code
-#else
+// We want error_code to be a value type that can be copied without slicing
+// and without requiring heap allocation, but we also want it to have
+// polymorphic behavior based on the error category. This is achieved by
+// abstract base class error_category supplying the polymorphic behavior,
+// and error_code containing a pointer to an object of a type derived
+// from error_category.
- typedef void (*unspecified_bool_type)();
- static void unspecified_bool_true() {}
+class error_code
+{
+private:
- BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_SYSTEM_NOEXCEPT // true if error
- {
- return m_val == 0 ? 0 : unspecified_bool_true;
- }
+ int val_;
+ bool failed_;
+ const error_category * cat_;
- BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_SYSTEM_NOEXCEPT // true if no error
- {
- return m_val == 0;
- }
+public:
-#endif
+ // constructors:
- // relationals:
- BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs,
- const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT
- // the more symmetrical non-member syntax allows enum
- // conversions work for both rhs and lhs.
- {
- return lhs.m_cat == rhs.m_cat && lhs.m_val == rhs.m_val;
- }
-
- inline friend bool operator<( const error_code & lhs,
- const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT
- // the more symmetrical non-member syntax allows enum
- // conversions work for both rhs and lhs.
- {
- return lhs.m_cat < rhs.m_cat
- || (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val);
- }
-
-#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR
-
- operator std::error_code () const BOOST_SYSTEM_NOEXCEPT
- {
- return std::error_code( value(), category() );
- }
+ BOOST_SYSTEM_CONSTEXPR error_code() BOOST_NOEXCEPT:
+ val_( 0 ), failed_( false ), cat_( &system_category() )
+ {
+ }
-#endif
+ BOOST_SYSTEM_CONSTEXPR error_code( int val, const error_category & cat ) BOOST_NOEXCEPT:
+ val_( val ), failed_( detail::failed_impl( val, cat ) ), cat_( &cat )
+ {
+ }
- private:
- int m_val;
- const error_category * m_cat;
+ template<class ErrorCodeEnum> BOOST_SYSTEM_CONSTEXPR error_code( ErrorCodeEnum e,
+ typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value>::type* = 0 ) BOOST_NOEXCEPT
+ {
+ *this = make_error_code( e );
+ }
- };
+ // modifiers:
- // predefined error_code object used as "throw on error" tag
-# ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
- BOOST_SYSTEM_DECL extern error_code throws;
-# endif
+ BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
+ {
+ val_ = val;
+ failed_ = detail::failed_impl( val, cat );
+ cat_ = &cat;
+ }
- // Moving from a "throws" object to a "throws" function without breaking
- // existing code is a bit of a problem. The workaround is to place the
- // "throws" function in namespace boost rather than namespace boost::system.
+ template<typename ErrorCodeEnum>
+ BOOST_SYSTEM_CONSTEXPR typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value, error_code>::type &
+ operator=( ErrorCodeEnum val ) BOOST_NOEXCEPT
+ {
+ *this = make_error_code( val );
+ return *this;
+ }
- } // namespace system
-
- namespace detail
- {
- // Misuse of the error_code object is turned into a noisy failure by
- // poisoning the reference. This particular implementation doesn't
- // produce warnings or errors from popular compilers, is very efficient
- // (as determined by inspecting generated code), and does not suffer
- // from order of initialization problems. In practice, it also seems
- // cause user function error handling implementation errors to be detected
- // very early in the development cycle.
- inline system::error_code* throws()
+ BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
{
- // See github.com/boostorg/system/pull/12 by visigoth for why the return
- // is poisoned with nonzero rather than (0). A test, test_throws_usage(),
- // has been added to error_code_test.cpp, and as visigoth mentioned it
- // fails on clang for release builds with a return of 0 but works fine
- // with (1).
- // Since the undefined behavior sanitizer (-fsanitize=undefined) does not
- // allow a reference to be formed to the unaligned address of (1), we use
- // (8) instead.
- return reinterpret_cast<system::error_code*>(8);
+ val_ = 0;
+ failed_ = false;
+ cat_ = &system_category();
}
- }
- inline system::error_code& throws()
- { return *detail::throws(); }
+ // observers:
- namespace system
- {
- // non-member functions ------------------------------------------------//
+ BOOST_SYSTEM_CONSTEXPR int value() const BOOST_NOEXCEPT
+ {
+ return val_;
+ }
- BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_code & lhs,
- const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT
+ BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_NOEXCEPT
{
- return !(lhs == rhs);
+ return *cat_;
}
- BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_condition & lhs,
- const error_condition & rhs ) BOOST_SYSTEM_NOEXCEPT
+ error_condition default_error_condition() const BOOST_NOEXCEPT
{
- return !(lhs == rhs);
+ return cat_->default_error_condition( value() );
}
- inline bool operator==( const error_code & code,
- const error_condition & condition ) BOOST_SYSTEM_NOEXCEPT
+ std::string message() const
{
- return code.category().equivalent( code.value(), condition )
- || condition.category().equivalent( code, condition.value() );
+ return cat_->message( value() );
}
- inline bool operator!=( const error_code & lhs,
- const error_condition & rhs ) BOOST_SYSTEM_NOEXCEPT
+ char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
{
- return !(lhs == rhs);
+ return cat_->message( value(), buffer, len );
}
- inline bool operator==( const error_condition & condition,
- const error_code & code ) BOOST_SYSTEM_NOEXCEPT
+ BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
{
- return condition.category().equivalent( code, condition.value() )
- || code.category().equivalent( code.value(), condition );
+ return failed_;
}
- inline bool operator!=( const error_condition & lhs,
- const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT
+#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
+
+ BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error
{
- return !(lhs == rhs);
+ return failed_;
}
- // TODO: both of these may move elsewhere, but the LWG hasn't spoken yet.
+#else
- template <class charT, class traits>
- inline std::basic_ostream<charT,traits>&
- operator<< (std::basic_ostream<charT,traits>& os, error_code ec)
+ typedef void (*unspecified_bool_type)();
+ static void unspecified_bool_true() {}
+
+ BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
{
- os << ec.category().name() << ':' << ec.value();
- return os;
+ return failed_? unspecified_bool_true: 0;
}
- inline std::size_t hash_value( const error_code & ec )
+ BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
{
- return static_cast<std::size_t>(ec.value())
- + reinterpret_cast<std::size_t>(&ec.category());
+ return !failed_;
}
- // make_* functions for errc::errc_t ---------------------------------------------//
+#endif
+
+ // relationals:
- namespace errc
- {
- // explicit conversion:
- inline error_code make_error_code( errc_t e ) BOOST_SYSTEM_NOEXCEPT
- { return error_code( e, generic_category() ); }
+ // the more symmetrical non-member syntax allows enum
+ // conversions work for both rhs and lhs.
- // implicit conversion:
- inline error_condition make_error_condition( errc_t e ) BOOST_SYSTEM_NOEXCEPT
- { return error_condition( e, generic_category() ); }
+ BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
+ {
+ return lhs.val_ == rhs.val_ && *lhs.cat_ == *rhs.cat_;
}
- // error_category default implementation -----------------------------------------//
-
- error_condition error_category::default_error_condition( int ev ) const
- BOOST_SYSTEM_NOEXCEPT
+ BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
- return error_condition( ev, *this );
+ return *lhs.cat_ < *rhs.cat_ || ( *lhs.cat_ == *rhs.cat_ && lhs.val_ < rhs.val_ );
}
- bool error_category::equivalent( int code,
- const error_condition & condition ) const BOOST_SYSTEM_NOEXCEPT
+#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
+
+ operator std::error_code () const
{
- return default_error_condition( code ) == condition;
+ return std::error_code( value(), category() );
}
- bool error_category::equivalent( const error_code & code,
- int condition ) const BOOST_SYSTEM_NOEXCEPT
+#endif
+};
+
+} // namespace system
+
+// boost::throws()
+
+namespace detail
+{
+
+// Misuse of the error_code object is turned into a noisy failure by
+// poisoning the reference. This particular implementation doesn't
+// produce warnings or errors from popular compilers, is very efficient
+// (as determined by inspecting generated code), and does not suffer
+// from order of initialization problems. In practice, it also seems
+// cause user function error handling implementation errors to be detected
+// very early in the development cycle.
+
+inline system::error_code* throws()
+{
+ // See github.com/boostorg/system/pull/12 by visigoth for why the return
+ // is poisoned with nonzero rather than (0). A test, test_throws_usage(),
+ // has been added to error_code_test.cpp, and as visigoth mentioned it
+ // fails on clang for release builds with a return of 0 but works fine
+ // with (1).
+ // Since the undefined behavior sanitizer (-fsanitize=undefined) does not
+ // allow a reference to be formed to the unaligned address of (1), we use
+ // (8) instead.
+
+ return reinterpret_cast<system::error_code*>(8);
+}
+
+} // namespace detail
+
+inline system::error_code& throws()
+{
+ return *detail::throws();
+}
+
+// non-member functions of error_code and error_condition
+
+namespace system
+{
+
+BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
+{
+ return !( lhs == rhs );
+}
+
+BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
+{
+ return !( lhs == rhs );
+}
+
+inline bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
+{
+ return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
+}
+
+inline bool operator!=( const error_code & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
+{
+ return !( lhs == rhs );
+}
+
+inline bool operator==( const error_condition & condition, const error_code & code ) BOOST_NOEXCEPT
+{
+ return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
+}
+
+inline bool operator!=( const error_condition & lhs, const error_code & rhs ) BOOST_NOEXCEPT
+{
+ return !( lhs == rhs );
+}
+
+template <class charT, class traits>
+ inline std::basic_ostream<charT,traits>&
+ operator<< (std::basic_ostream<charT,traits>& os, error_code ec)
+{
+ os << ec.category().name() << ':' << ec.value();
+ return os;
+}
+
+inline std::size_t hash_value( error_code const & ec )
+{
+ error_category const & cat = ec.category();
+
+ boost::ulong_long_type id = cat.id_;
+
+ if( id == 0 )
{
- return *this == code.category() && code.value() == condition;
+ id = reinterpret_cast<boost::ulong_long_type>( &cat );
}
-#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR
+ boost::ulong_long_type hv = ( boost::ulong_long_type( 0xCBF29CE4 ) << 32 ) + 0x84222325;
+ boost::ulong_long_type const prime = ( boost::ulong_long_type( 0x00000100 ) << 32 ) + 0x000001B3;
+
+ // id
+
+ hv ^= id;
+ hv *= prime;
+
+ // value
- inline std::error_condition error_category::std_category::default_error_condition(
- int ev ) const BOOST_NOEXCEPT
+ hv ^= static_cast<unsigned>( ec.value() );
+ hv *= prime;
+
+ return static_cast<std::size_t>( hv );
+}
+
+// make_* functions for errc::errc_t
+
+namespace errc
+{
+
+// explicit conversion:
+BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) BOOST_NOEXCEPT
+{
+ return error_code( e, generic_category() );
+}
+
+// implicit conversion:
+BOOST_SYSTEM_CONSTEXPR inline error_condition make_error_condition( errc_t e ) BOOST_NOEXCEPT
+{
+ return error_condition( e, generic_category() );
+}
+
+} // namespace errc
+
+// error_category default implementation
+
+inline error_condition error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
+{
+ return error_condition( ev, *this );
+}
+
+inline bool error_category::equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT
+{
+ return default_error_condition( code ) == condition;
+}
+
+inline bool error_category::equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT
+{
+ return *this == code.category() && code.value() == condition;
+}
+
+inline char const * error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
+{
+ if( len == 0 )
{
- return pc_->default_error_condition( ev );
+ return buffer;
}
- inline bool error_category::std_category::equivalent( int code,
- const std::error_condition & condition ) const BOOST_NOEXCEPT
+ if( len == 1 )
{
- if( condition.category() == *this )
- {
- boost::system::error_condition bn( condition.value(), *pc_ );
- return pc_->equivalent( code, bn );
- }
- else if( condition.category() == std::generic_category()
- || condition.category() == boost::system::generic_category() )
- {
- boost::system::error_condition bn( condition.value(),
- boost::system::generic_category() );
+ buffer[0] = 0;
+ return buffer;
+ }
- return pc_->equivalent( code, bn );
- }
-#ifndef BOOST_NO_RTTI
- else if( std_category const* pc2 = dynamic_cast< std_category const* >(
- &condition.category() ) )
- {
- boost::system::error_condition bn( condition.value(), *pc2->pc_ );
- return pc_->equivalent( code, bn );
- }
+#if !defined(BOOST_NO_EXCEPTIONS)
+ try
#endif
- else
- {
- return default_error_condition( code ) == condition;
- }
- }
-
- inline bool error_category::std_category::equivalent( const std::error_code & code,
- int condition ) const BOOST_NOEXCEPT
- {
- if( code.category() == *this )
- {
- boost::system::error_code bc( code.value(), *pc_ );
- return pc_->equivalent( bc, condition );
- }
- else if( code.category() == std::generic_category()
- || code.category() == boost::system::generic_category() )
- {
- boost::system::error_code bc( code.value(),
- boost::system::generic_category() );
-
- return pc_->equivalent( bc, condition );
- }
-#ifndef BOOST_NO_RTTI
- else if( std_category const* pc2 = dynamic_cast< std_category const* >(
- &code.category() ) )
- {
- boost::system::error_code bc( code.value(), *pc2->pc_ );
- return pc_->equivalent( bc, condition );
- }
-#endif
- else if( *pc_ == boost::system::generic_category() )
- {
- return std::generic_category().equivalent( code, condition );
- }
- else
- {
- return false;
- }
- }
+ {
+ std::string m = this->message( ev );
+
+# if defined( BOOST_MSVC )
+# pragma warning( push )
+# pragma warning( disable: 4996 )
+# elif defined(__clang__) && defined(__has_warning)
+# pragma clang diagnostic push
+# if __has_warning("-Wdeprecated-declarations")
+# pragma clang diagnostic ignored "-Wdeprecated-declarations"
+# endif
+# endif
+
+ std::strncpy( buffer, m.c_str(), len - 1 );
+ buffer[ len-1 ] = 0;
+# if defined( BOOST_MSVC )
+# pragma warning( pop )
+# elif defined(__clang__) && defined(__has_warning)
+# pragma clang diagnostic pop
+# endif
+
+ return buffer;
+ }
+#if !defined(BOOST_NO_EXCEPTIONS)
+ catch( ... )
+ {
+ return "Message text unavailable";
+ }
#endif
+}
+
+inline bool error_category::failed( int ev ) const BOOST_NOEXCEPT
+{
+ return ev != 0;
+}
+
+} // namespace system
- } // namespace system
} // namespace boost
-#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+// generic_error_category implementation
-# ifdef BOOST_ERROR_CODE_HEADER_ONLY
-# include <boost/system/detail/error_code.ipp>
-# endif
+#include <boost/system/detail/generic_category.hpp>
+
+inline std::string boost::system::detail::generic_error_category::message( int ev ) const
+{
+ return generic_error_category_message( ev );
+}
+
+inline char const * boost::system::detail::generic_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
+{
+ return generic_error_category_message( ev, buffer, len );
+}
+
+// system_error_category implementation
+
+#if defined(BOOST_WINDOWS_API)
+
+#include <boost/system/detail/system_category_win32.hpp>
+
+inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
+{
+ return system_category_default_error_condition_win32( ev );
+}
+
+inline std::string boost::system::detail::system_error_category::message( int ev ) const
+{
+ return system_category_message_win32( ev );
+}
+
+inline char const * boost::system::detail::system_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
+{
+ return system_category_message_win32( ev, buffer, len );
+}
+
+#else // #if defined(BOOST_WINDOWS_API)
+
+#include <boost/system/detail/system_category_posix.hpp>
+
+inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
+{
+ return system_category_default_error_condition_posix( ev );
+}
+
+inline std::string boost::system::detail::system_error_category::message( int ev ) const
+{
+ return generic_error_category_message( ev );
+}
+
+inline char const * boost::system::detail::system_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
+{
+ return generic_error_category_message( ev, buffer, len );
+}
+
+#endif // #if defined(BOOST_WINDOWS_API)
+
+// interoperability with std::error_code, std::error_condition
+
+#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
+
+#include <boost/system/detail/std_interoperability.hpp>
+
+inline boost::system::error_category::operator std::error_category const & () const
+{
+ return boost::system::detail::to_std_category( *this );
+}
+
+#endif // #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
-#endif // BOOST_SYSTEM_ERROR_CODE_HPP
+#endif // BOOST_SYSTEM_ERROR_CODE_HPP_INCLUDED