This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

3078. directory_entry, directory_iterator and recursive_directory_iterator perform needless path copies

Section: 31.12.10 [fs.class.directory.entry], 31.12.11 [fs.class.directory.iterator], 31.12.12 [fs.class.rec.dir.itr] Status: New Submitter: Gor Nishanov Opened: 2018-03-05 Last modified: 2019-04-02

Priority: 3

View all other issues in [fs.class.directory.entry].

View all issues with New status.

Discussion:

An implementation of directory_entry class is likely to store a filesystem::path as a member. Constructors and assign member functions take filesystem::path by const& thus forcing creation of a copy.

An implementation of directory_iterator class is likely to store a directory_entry or a path as a part of its state. Constructors take filesystem::path by const& thus forcing creation of a copy.

An implementation of recursive_directory_iterator class is likely to store a directory_entry or a path as a part of its state. Constructors take filesystem::path by const& thus forcing creation of a copy.

Suggested resolution:

Add overloads to directory_entry, directory_iterator, and recursive_directory_iterator that take filesystem::path by &&.

Make it unspecified in case an exception is thrown from those new members where an argument was moved from or not.

explicit directory_entry(const filesystem::path& p);
explicit directory_entry(filesystem::path&& p);
directory_entry(const filesystem::path& p, error_code& ec);
directory_entry(filesystem::path&& p, error_code& ec);

void directory_entry::assign(const filesystem::path& p);
void directory_entry::assign(filesystem::path&& p);
void directory_entry::assign(const filesystem::path& p, error_code& ec);
void directory_entry::assign(filesystem::path&& p, error_code& ec);

explicit directory_iterator(const path& p);
explicit directory_iterator(path&& p);
directory_iterator(const path& p, directory_options options);
directory_iterator(path&& p, directory_options options);
directory_iterator(const path& p, error_code& ec) noexcept;
directory_iterator(path&& p, error_code& ec) noexcept;
directory_iterator(const path& p, directory_options options, error_code& ec) noexcept;
directory_iterator(path&& p, directory_options options, error_code& ec) noexcept;

explicit recursive_directory_iterator(const path& p);
explicit recursive_directory_iterator(path&& p);
recursive_directory_iterator(const path& p, directory_options options);
recursive_directory_iterator(path&& p, directory_options options);
recursive_directory_iterator(const path& p, directory_options options, error_code& ec) noexcept;
recursive_directory_iterator(path&& p, directory_options options, error_code& ec) noexcept;
recursive_directory_iterator(const path& p, error_code& ec) noexcept;
recursive_directory_iterator(path&& p, error_code& ec) noexcept;

[2018-03-20 Priority set to 3 after discussion on the reflector.]

Proposed resolution: