• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <filesystem>

    std::filesystem::directory_entry::コンストラクタ

    directory_entry() noexcept = default;                  // (1)
    directory_entry(const directory_entry&) = default;     // (2)
    directory_entry(directory_entry&&) noexcept = default; // (3)
    explicit directory_entry(const path& p);               // (4)
    directory_entry(const path& p, std::error_code& ec);   // (5)
    

    概要

    directory_entryオブジェクトを構築する。

    このクラスはdirectory_iteratorクラスをfriend宣言している。そのため、そのクラスはこれらのコンストラクタを介することなく、メンバ変数として保持するキャッシュを代入できる。

    • (1) : デフォルトコンストラクタ
    • (2) : コピーコンストラクタ
    • (3) : ムーブコンストラクタ
    • (4), (5) : パスを指定して構築するコンストラクタ

    効果

    • (4) : パスを*thisに保持し、refresh()を実行する
    • (5) : パスを*thisに保持し、refresh(ec)を実行する。エラー発生時には、path()メンバ関数が返す値はstd::filesystem::path{}となる

    例外

    #include <iostream>
    #include <filesystem>
    #include <fstream>
    
    namespace fs = std::filesystem;
    
    int main()
    {
      fs::create_directory("dir");
      std::ofstream{"dir/a.txt"};
    
      fs::directory_entry x{"dir/a.txt"};
      std::cout << x.path() << std::endl;
    }
    

    出力

    "dir/a.txt"
    

    バージョン

    言語

    • C++17

    処理系