1// Copyright (c) 2023 Klemens D. Morgenstern
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5#ifndef BOOST_COBALT_ERROR_HPP
6#define BOOST_COBALT_ERROR_HPP
7
8#include <boost/cobalt/config.hpp>
9#include <boost/system/error_code.hpp>
10
11namespace boost::cobalt
12{
13
14enum class error
15{
16 moved_from,
17 detached,
18 completed_unexpected,
19 wait_not_ready,
20 already_awaited,
21 allocation_failed
22};
23
24
25struct cobalt_category_t final : system::error_category
26{
27 cobalt_category_t() : system::error_category(0x7d4c7b49d8a4fdull) {}
28
29
30 std::string message( int ev ) const override
31 {
32
33 return message(ev, nullptr, 0u);
34 }
35 char const * message( int ev, char * , std::size_t ) const noexcept override
36 {
37 switch (static_cast<error>(ev))
38 {
39 case error::moved_from:
40 return "moved from";
41 case error::detached:
42 return "detached";
43 case error::completed_unexpected:
44 return "completed unexpected";
45 case error::wait_not_ready:
46 return "wait not ready";
47 case error::already_awaited:
48 return "already awaited";
49 case error::allocation_failed:
50 return "allocation failed";
51 default:
52 return "unknown cobalt error";
53 }
54 }
55
56 const char * name() const BOOST_NOEXCEPT override
57 {
58 return "boost.cobalt";
59 }
60};
61
62BOOST_COBALT_DECL system::error_category & cobalt_category();
63BOOST_COBALT_DECL system::error_code make_error_code(error e);
64
65}
66
67template<> struct boost::system::is_error_code_enum<boost::cobalt::error>
68{
69 static const bool value = true;
70};
71
72#endif //BOOST_COBALT_ERROR_HPP
73

source code of boost/libs/cobalt/include/boost/cobalt/error.hpp