include/boost/corosio/error.hpp

100.0% Lines (2/2) 100.0% List of functions (1/1) -% Branches (0/0)
error.hpp
f(x) Functions (1)
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2026 Michael Vandeberg
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/corosio
8 //
9
10 #ifndef BOOST_COROSIO_ERROR_HPP
11 #define BOOST_COROSIO_ERROR_HPP
12
13 #include <boost/corosio/detail/config.hpp>
14
15 #include <string>
16 #include <system_error>
17 #include <type_traits>
18
19 namespace boost::corosio {
20
21 /** Identifies failures corosio detects itself.
22
23 Codes the operating system reports keep their system category.
24 */
25 enum class error
26 {
27 /// The target object already holds an open handle.
28 already_open = 1
29 };
30
31 } // namespace boost::corosio
32
33 namespace std {
34 template<>
35 struct is_error_code_enum<::boost::corosio::error> : std::true_type
36 {};
37 } // namespace std
38
39 namespace boost::corosio {
40 namespace detail {
41
42 struct BOOST_COROSIO_SYMBOL_VISIBLE error_cat_type : std::error_category
43 {
44 BOOST_COROSIO_DECL char const* name() const noexcept override;
45 BOOST_COROSIO_DECL std::string message(int) const override;
46 constexpr error_cat_type() noexcept = default;
47 };
48
49 BOOST_COROSIO_DECL extern error_cat_type error_cat;
50
51 } // namespace detail
52
53 /** Create an `std::error_code` from a corosio error value.
54
55 @param ev The error value.
56 @return An `std::error_code` in corosio's category.
57 */
58 inline std::error_code
59 120x make_error_code(error ev) noexcept
60 {
61 120x return std::error_code{static_cast<int>(ev), detail::error_cat};
62 }
63
64 } // namespace boost::corosio
65
66 #endif
67