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)
7 #include "boost/fiber/exceptions.hpp"
12 class future_error_category
: public std::error_category
{
14 const char* name() const noexcept override
{
15 return "fiber-future";
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
),
24 case future_errc::future_already_retrieved
:
25 return std::error_condition
{
26 static_cast< int >( future_errc::future_already_retrieved
),
28 case future_errc::promise_already_satisfied
:
29 return std::error_condition
{
30 static_cast< int >( future_errc::promise_already_satisfied
),
32 case future_errc::no_state
:
33 return std::error_condition
{
35 int >( future_errc::no_state
),
38 return std::error_condition
{ ev
, * this };
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( code
.value() ).value() ) == condition
;
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." };
61 return std::string
{ "unspecified future_errc value\n" };
66 std::error_category
const& future_category() noexcept
{
67 static fibers::future_error_category cat
;