1
2// Copyright Oliver Kowalke 2013.
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#include "boost/fiber/exceptions.hpp"
8
9namespace boost {
10namespace fibers {
11
12class future_error_category : public std::error_category {
13public:
14 const char* name() const noexcept override {
15 return "fiber-future";
16 }
17
18 std::error_condition default_error_condition( int ev) const noexcept override {
19 switch ( static_cast< future_errc >( ev) ) {
20 case future_errc::broken_promise:
21 return std::error_condition{
22 static_cast< int >( future_errc::broken_promise),
23 future_category() };
24 case future_errc::future_already_retrieved:
25 return std::error_condition{
26 static_cast< int >( future_errc::future_already_retrieved),
27 future_category() };
28 case future_errc::promise_already_satisfied:
29 return std::error_condition{
30 static_cast< int >( future_errc::promise_already_satisfied),
31 future_category() };
32 case future_errc::no_state:
33 return std::error_condition{
34 static_cast<
35 int >( future_errc::no_state),
36 future_category() };
37 default:
38 return std::error_condition{ ev, * this };
39 }
40 }
41
42 bool equivalent( std::error_code const& code, int condition) const noexcept override {
43 return * this == code.category() &&
44 static_cast< int >( default_error_condition( ev: code.value() ).value() ) == condition;
45 }
46
47 std::string message( int ev) const override {
48 switch ( static_cast< future_errc >( ev) ) {
49 case future_errc::broken_promise:
50 return std::string{ "The associated promise has been destructed prior "
51 "to the associated state becoming ready." };
52 case future_errc::future_already_retrieved:
53 return std::string{ "The future has already been retrieved from "
54 "the promise or packaged_task." };
55 case future_errc::promise_already_satisfied:
56 return std::string{ "The state of the promise has already been set." };
57 case future_errc::no_state:
58 return std::string{ "Operation not permitted on an object without "
59 "an associated state." };
60 }
61 return std::string{ "unspecified future_errc value\n" };
62 }
63};
64
65BOOST_FIBERS_DECL
66std::error_category const& future_category() noexcept {
67 static fibers::future_error_category cat;
68 return cat;
69}
70
71}}
72

source code of boost/libs/fiber/src/future.cpp