函式
<future>

std::make_error_condition (future_errc)

error_code make_error_condition (future_errc e) noexcept;
建立錯誤條件
future_errc 列舉值 e (屬於 future_category) 建立一個 error_condition 物件。

它返回的結果與
1
error_condition(static_cast<int>(e),future_category());

error_condition 的建構函式接收 future_errc 型別引數時,會呼叫此過載。

引數

e
future_errc 型別的列舉值。

返回值

代表列舉值 eerror_condition 物件。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// std::future_errc example:
#include <iostream>     // std::cerr
#include <future>       // std::promise, std::future_error, std::future_errc

int main ()
{
  std::promise<int> prom;

  try {
    prom.get_future();
    prom.get_future();   // throws std::future_error with future_already_retrieved
  }
  catch (std::future_error& e) {
    if (e.code() == std::make_error_condition(std::future_errc::future_already_retrieved))
    std::cerr << "[future already retrieved]\n";
    else std::cerr << "[unknown exception]\n";
  }

  return 0;
}

輸出 (stderr)

[future already retrieved]


異常安全

無異常保證:此函式從不丟擲異常。

另見