最終更新日時(UTC):
が更新

履歴 編集

function
<system_error>

std::error_condition::コンストラクタ(C++11)

error_condition() noexcept;                                   // (1)

error_condition(int val, const error_category& cat) noexcept; // (2)

template <class ErrorConditionEnum>
error_condition(ErrorConditionEnum e) noexcept;               // (3)

error_conditionオブジェクトの構築

  • (1) : デフォルトコンストラクタ
  • (2) : エラー値とエラーカテゴリを受け取って構築する。
  • (3) : is_error_condition_enum<ErrorCodeEnum>::value == trueとなる型のエラー値を受け取って構築する。

効果

例外

投げない

備考

  • (3) : is_error_condition_enumfalseとなる場合、この関数はオーバーロード解決から除外される。

#include <iostream>
#include <system_error>

int main()
{
  // デフォルトコンストラクタ
  std::cout << "default ctor" << std::endl;
  {
    std::error_condition ec;

    if (ec) {
      std::cout << "error" << std::endl;
    }
    else {
      std::cout << "success" << std::endl;
    }

    std::cout << ec.value() << std::endl;
    std::cout << ec.category().name() << std::endl;
  }

  // エラー値とエラーカテゴリを受け取って構築
  std::cout << std::endl << "value & category ctor" << std::endl;
  {
    std::error_condition ec(static_cast<int>(std::errc::invalid_argument),
                            std::generic_category());

    if (ec) {
      std::cout << "error" << std::endl;
    }
    else {
      std::cout << "success" << std::endl;
    }

    std::cout << ec.value() << std::endl;
    std::cout << ec.category().name() << std::endl;
  }

  // is_error_condition_enumが特殊化された型のエラー値を受け取って構築
  std::cout << std::endl << "ErrorConditionEnum ctor" << std::endl;
  {
    std::error_condition ec(std::errc::invalid_argument);

    if (ec) {
      std::cout << "error" << std::endl;
    }
    else {
      std::cout << "success" << std::endl;
    }

    std::cout << ec.value() << std::endl;
    std::cout << ec.category().name() << std::endl;
  }
}

出力

default ctor
success
0
generic

value & category ctor
error
22
generic

ErrorConditionEnum ctor
error
22
generic

バージョン

言語

  • C++11

処理系

参照