std::filesystem::directory_iterator::directory_iterator
提供: cppreference.com
<tbody>
</tbody>
directory_iterator() noexcept; |
(1) | (C++17以上) |
explicit directory_iterator( const std::filesystem::path& p ); |
(2) | (C++17以上) |
directory_iterator( const std::filesystem::path& p, std::filesystem::directory_options options); |
(3) | (C++17以上) |
directory_iterator( const std::filesystem::path& p, std::error_code& ec ); |
(4) | (C++17以上) |
directory_iterator( const std::filesystem::path& p, std::filesystem::directory_options options, std::error_code& ec ); |
(5) | (C++17以上) |
directory_iterator( const directory_iterator& ) = default; |
(6) | (C++17以上) |
directory_iterator( directory_iterator&& ) = default; |
(7) | (C++17以上) |
新しいディレクトリイテレータを構築します。
1) 終端イテレータを構築します。
2)
p が表すディレクトリの最初のディレクトリエントリを参照するディレクトリイテレータを構築します。 p の参照先が存在しない、またはディレクトリでない場合、 std::filesystem::filesystem_error が投げられます。3) (2) と同じですが、
options に std::filesystem::directory_options::skip_permission_denied が設定されていて、構築時にパーミッション拒否エラーが発生した場合、終端イテレータを構築し、エラーは報告しません。4)
p が表すディレクトリの最初のディレクトリエントリを参照するディレクトリイテレータを構築します。 p の参照先が存在しない、またはディレクトリでない場合、終端イテレータを構築し、 ec を設定します。5) (4) と同じですが、
options に std::filesystem::directory_options::skip_permission_denied が設定されていて、構築時にパーミッション拒否エラーが発生した場合、終端イテレータを構築し、エラーは報告しません。引数
| This section is incomplete |
例外
2-5)
std::error_code& 引数を取らないオーバーロードは、ベースとなる OS の API でエラーが発生した場合、第1パス引数に p、エラーコード引数に OS のエラーコードを指定して構築された filesystem_error を投げます。 std::error_code& 引数を取るオーバーロードは、 OS の API 呼び出しが失敗した場合、その引数を OS の API のエラーコードに設定し、エラーが発生しない場合は ec.clear() を実行します。 noexcept 指定のないあらゆるオーバーロードは、メモリ確保に失敗した場合 std::bad_alloc を投げる可能性があります。ノート
カレントディレクトリをイテレートするには、 directory_iterator("") ではなく、 directory_iterator(".") のようにイテレータを構築してください。
欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
| DR | 適用先 | 発行時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 3013 | C++17 | error_code overload marked noexcept but can allocate memory
|
noexcept removed |