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

履歴 編集

function
<filesystem>

std::filesystem::is_other(C++17)

namespace std::filesystem {
  bool is_other(file_status s) noexcept;                      // (1)
  bool is_other(const path& p);                               // (2)
  bool is_other(const path& p, std::error_code& ec) noexcept; // (3)
}

概要

指定されたパスが存在していない、もしくはシステム依存の種別のファイルを指しているかを確認する。

戻り値

例外

  • (1) : 投げない
  • (2) : ファイルシステムがエラーを報告する場合がある。エラーが発生した場合は、std::filesystem::filesystem_error例外を送出する
  • (3) : 投げない

Linux環境の例

#include <cassert>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  // (1)
  // 取得済みのファイル状態を使用して、システム依存のファイルかを確認
  assert(fs::is_other(fs::status("/dev/urandom")));

  // (2)
  // パスを指定して、システム依存のファイルかを確認。
  assert(fs::is_other("/dev/urandom"));
  assert(fs::is_other("/dev/null"));

  // (3)
  // エラー情報を例外ではなくerror_codeで受け取る
  std::error_code ec;
  bool result = fs::is_other("/dev/urandom", ec);
  assert(!ec);
  assert(result);
}

出力

バージョン

言語

  • C++17

処理系