|
|
|
Table 124 — Enum class copy_options
Option group controlling copy_file function effects for existing target files
Constant
Meaning
none
(Default) Error; file already exists.
skip_existing
Do not overwrite existing file, do not report an error.
overwrite_existing
Overwrite the existing file.
update_existing
Overwrite the existing file if it is older than the replacement file.
Option group controlling copy function effects for sub-directories
Constant
Meaning
none
(Default) Do not copy sub-directories.
recursive
Recursively copy sub-directories and their contents.
Option group controlling copy function effects for symbolic links
Constant
Meaning
none
(Default) Follow symbolic links.
copy_symlinks
Copy symbolic links as symbolic links rather than copying the files
that they point to.
skip_symlinks
Ignore symbolic links.
Option group controlling copy function effects for choosing the form of copying
Constant
Meaning
none
(Default) Copy content.
directories_only
Copy directory structure only, do not copy non-directory files.
create_symlinks
Make symbolic links instead of copies of files. The source path shall
be an absolute path unless the destination path is in the current
directory.
create_hard_links Make hard links instead of copies of files.
Table 125 — Enum class perms
Name
Value
POSIX
Definition or notes
(octal)
macro
none
0
There are no permissions set for the file.
owner_read
0400
S_IRUSR
Read permission, owner
owner_write
0200
S_IWUSR
Write permission, owner
owner_exec
0100
S_IXUSR
Execute/search permission, owner
owner_all
0700
S_IRWXU
Read, write, execute/search by owner;
owner_read | owner_write | owner_exec
group_read
040
S_IRGRP
Read permission, group
group_write
020
S_IWGRP
Write permission, group
group_exec
010
S_IXGRP
Execute/search permission, group
group_all
070
S_IRWXG
Read, write, execute/search by group;
group_read | group_write | group_exec
others_read
04
S_IROTH
Read permission, others
others_write
02
S_IWOTH
Write permission, others
others_exec
01
S_IXOTH
Execute/search permission, others
others_all
07
S_IRWXO
Read, write, execute/search by others;
others_read | others_write | others_exec
all
0777
owner_all | group_all | others_all
set_uid
04000
S_ISUID
Set-user-ID on execution
set_gid
02000
S_ISGID
Set-group-ID on execution
sticky_bit
01000
S_ISVTX
Operating system dependent.
mask
07777
all | set_uid | set_gid | sticky_bit
unknown
0xFFFF
The permissions are not known, such as when a file_-
status object is created without specifying the per-
missions
§
30.11.10
1132
Table 126 — Enum class perm_options
Name
Meaning
replace
permissions shall replace the file’s permission bits with perm
add
permissions shall replace the file’s permission bits with the bitwise OR of
perm and the file’s current permission bits.
remove
permissions shall replace the file’s permission bits with the bitwise AND
of the complement of perm and the file’s current permission bits.
nofollow
permissions shall change the permissions of a symbolic link itself rather
than the permissions of the file the link resolves to.
Table 127 — Enum class directory_options
Name
Meaning
none
(Default) Skip directory symlinks, permission de-
nied is an error.
follow_directory_symlink Follow rather than skip directory symlinks.
skip_permission_denied
Skip directories that would otherwise result in per-
mission denied.
file_status() noexcept : file_status(file_type::none) {}
explicit file_status(file_type ft,
perms prms = perms::unknown) noexcept;
file_status(const file_status&) noexcept = default;
file_status(file_status&&) noexcept = default;
~file_status();
// assignments
file_status& operator=(const file_status&) noexcept = default;
file_status& operator=(file_status&&) noexcept = default;
// 30.11.10.3, modifiers
void
type(file_type ft) noexcept;
void
permissions(perms prms) noexcept;
// 30.11.10.2, observers
file_type type() const noexcept;
perms
permissions() const noexcept;
};
}
1
An object of type file_status stores information about the type and permissions of a file.
30.11.10.1
file_status constructors
[fs.file_status.cons]
explicit file_status(file_type ft, perms prms = perms::unknown) noexcept;
1
Postconditions: type() == ft and permissions() == prms.
30.11.10.2
file_status observers
[fs.file_status.obs]
file_type type() const noexcept;
1
Returns: The value of type() specified by the postconditions of the most recent call to a constructor,
operator=, or type(file_type) function.
perms permissions() const noexcept;
2
Returns: The value of permissions() specified by the postconditions of the most recent call to a
constructor, operator=, or permissions(perms) function.
§ 30.11.10.2
1133
30.11.10.3
file_status modifiers
[fs.file_status.mods]
void type(file_type ft) noexcept;
1
Postconditions: type() == ft.
void permissions(perms prms) noexcept;
2
Postconditions: permissions() == prms.
30.11.11
Class directory_entry
[fs.class.directory_entry]
namespace std::filesystem {
class directory_entry {
public:
// 30.11.11.1, constructors and destructor
directory_entry() noexcept = default;
directory_entry(const directory_entry&) = default;
directory_entry(directory_entry&&) noexcept = default;
explicit directory_entry(const filesystem::path& p);
directory_entry(const filesystem::path& p, error_code& ec);
~directory_entry();
// assignments
directory_entry& operator=(const directory_entry&) = default;
directory_entry& operator=(directory_entry&&) noexcept = default;
// 30.11.11.2, modifiers
void assign(const filesystem::path& p);
void assign(const filesystem::path& p, error_code& ec);
void replace_filename(const filesystem::path& p);
void replace_filename(const filesystem::path& p, error_code&
ec);
void refresh();
void refresh(error_code& ec) noexcept;
// 30.11.11.3, observers
const filesystem::path& path() const noexcept;
operator const filesystem::path&() const noexcept;
bool exists() const;
bool exists(error_code& ec) const noexcept;
bool is_block_file() const;
bool is_block_file(error_code& ec) const noexcept;
bool is_character_file() const;
bool is_character_file(error_code& ec) const noexcept;
bool is_directory() const;
bool is_directory(error_code& ec) const noexcept;
bool is_fifo() const;
bool is_fifo(error_code& ec) const noexcept;
bool is_other() const;
bool is_other(error_code& ec) const noexcept;
bool is_regular_file() const;
bool is_regular_file(error_code& ec) const noexcept;
bool is_socket() const;
bool is_socket(error_code& ec) const noexcept;
bool is_symlink() const;
bool is_symlink(error_code& ec) const noexcept;
uintmax_t file_size() const;
uintmax_t file_size(error_code& ec) const noexcept;
uintmax_t hard_link_count() const;
uintmax_t hard_link_count(error_code& ec) const noexcept;
file_time_type last_write_time() const;
file_time_type last_write_time(error_code& ec) const noexcept;
file_status status() const;
file_status status(error_code& ec) const noexcept;
file_status symlink_status() const;
file_status symlink_status(error_code& ec) const noexcept;
§
30.11.11
1134
bool operator< (const directory_entry& rhs) const noexcept;
bool operator==(const directory_entry& rhs) const noexcept;
bool operator!=(const directory_entry& rhs) const noexcept;
bool operator<=(const directory_entry& rhs) const noexcept;
bool operator> (const directory_entry& rhs) const noexcept;
bool operator>=(const directory_entry& rhs) const noexcept;
private:
filesystem::path pathobject;
// exposition only
friend class directory_iterator; // exposition only
};
}
1
A directory_entry object stores a path object and may store additional objects for file attributes such as
hard link count, status, symlink status, file size, and last write time.
2
Implementations should store such additional file attributes during directory iteration if their values are avail-
able and storing the values would allow the implementation to eliminate file system accesses by directory_-
entry observer functions (30.11.14). Such stored file attribute values are said to be cached.
3
[ Note: For purposes of exposition, class directory_iterator (30.11.12) is shown above as a friend of class
directory_entry. Friendship allows the directory_iterator implementation to cache already available
attribute values directly into a directory_entry object without the cost of an unneeded call to refresh().
— end note ]
4
[ Example:
using namespace std::filesystem;
// use possibly cached last write time to minimize disk accesses
for (auto&& x : directory_iterator("."))
{
std::cout << x.path() << " " << x.last_write_time() << std::endl;
}
// call refresh() to refresh a stale cache
for (auto&& x : directory_iterator("."))
{
lengthy_function(x.path());
// cache becomes stale
x.refresh();
std::cout << x.path() << " " << x.last_write_time() << std::endl;
}
On implementations that do not cache the last write time, both loops will result in a potentially expensive
call to the std::filesystem::last_write_time function. On implementations that do cache the last write
time, the first loop will use the cached value and so will not result in a potentially expensive call to the
std::filesystem::last_write_time function. The code is portable to any implementation, regardless of
whether or not it employs caching.
— end example ]
30.11.11.1
directory_entry constructors
[fs.dir.entry.cons]
explicit directory_entry(const filesystem::path& p);
directory_entry(const filesystem::path& p, error_code& ec);
1
Effects: Constructs an object of type directory_entry, then refresh() or refresh(ec), respectively.
2
Postconditions: path() == p if no error occurs, otherwise path() == filesystem::path().
3
Throws: As specified in 30.11.6.
30.11.11.2
directory_entry modifiers
[fs.dir.entry.mods]
void assign(const filesystem::path& p);
void assign(const filesystem::path& p, error_code& ec);
1
Effects: Equivalent to pathobject = p, then refresh() or refresh(ec), respectively. If an error
occurs, the values of any cached attributes are unspecified.
2
Throws: As specified in 30.11.6.
§ 30.11.11.2
1135
void replace_filename(const filesystem::path& p);
void replace_filename(const filesystem::path& p, error_code& ec);
3
Effects: Equivalent to pathobject.replace_filename(p), then refresh() or refresh(ec), respec-
tively. If an error occurs, the values of any cached attributes are unspecified.
Throws: As specified in 30.11.6.
void refresh();
void refresh(error_code& ec) noexcept;
4
Effects: Stores the current values of any cached attributes of the file p resolves to. If an error occurs,
an error is reported (30.11.6) and the values of any cached attributes are unspecified.
5
Throws: As specified in 30.11.6.
6
[ Note: Implementations of directory_iterator (30.11.12) are prohibited from directly or indirectly
calling the refresh function since it must access the external file system, and the objective of caching
is to avoid unnecessary file system accesses.
— end note ]
30.11.11.3
directory_entry observers
[fs.dir.entry.obs]
1
Unqualified function names in the Returns: elements of the directory_entry observers described below
refer to members of the std::filesystem namespace.
const filesystem::path& path() const noexcept;
operator const filesystem::path&() const noexcept;
2
Returns: pathobject.
bool
exists() const;
bool
exists(error_code& ec) const noexcept;
3
Returns: exists(this->status()) or exists(this->status(ec)), respectively.
4
Throws: As specified in 30.11.6.
bool
is_block_file() const;
bool
is_block_file(error_code& ec) const noexcept;
5
Returns: is_block_file(this->status()) or is_block_file(this->status(ec)), respectively.
6
Throws: As specified in 30.11.6.
bool
is_character_file() const;
bool
is_character_file(error_code& ec) const noexcept;
7
Returns: is_character_file(this->status()) or is_character_file(this->status(ec)), respec-
tively.
8
Throws: As specified in 30.11.6.
bool
is_directory() const;
bool
is_directory(error_code& ec) const noexcept;
9
Returns: is_directory(this->status()) or is_directory(this->status(ec)), respectively.
10
Throws: As specified in 30.11.6.
bool
is_fifo() const;
bool
is_fifo(error_code& ec) const noexcept;
11
Returns: is_fifo(this->status()) or is_fifo(this->status(ec)), respectively.
12
Throws: As specified in 30.11.6.
bool
is_other() const;
bool
is_other(error_code& ec) const noexcept;
13
Returns: is_other(this->status()) or is_other(this->status(ec)), respectively.
14
Throws: As specified in 30.11.6.
bool
is_regular_file() const;
§ 30.11.11.3
1136
bool is_regular_file(error_code& ec) const noexcept;
15
Returns: is_regular_file(this->status()) or is_regular_file(this->status(ec)), respective-
ly.
16
Throws: As specified in 30.11.6.
bool is_socket() const;
bool is_socket(error_code& ec) const noexcept;
17
Returns: is_socket(this->status()) or is_socket(this->status(ec)), respectively.
18
Throws: As specified in 30.11.6.
bool is_symlink() const;
bool is_symlink(error_code& ec) const noexcept;
19
Returns: is_symlink(this->symlink_status()) or is_symlink(this->symlink_status(ec)), re-
spectively.
20
Throws: As specified in 30.11.6.
uintmax_t file_size() const;
uintmax_t file_size(error_code& ec) const noexcept;
21
Returns: If cached, the file size attribute value. Otherwise, file_size(path()) or file_size(path(),
ec), respectively.
22
Throws: As specified in 30.11.6.
uintmax_t hard_link_count() const;
uintmax_t hard_link_count(error_code& ec) const noexcept;
23
Returns: If cached, the hard link count attribute value. Otherwise, hard_link_count(path()) or
hard_link_count(path(), ec), respectively.
24
Throws: As specified in 30.11.6.
file_time_type last_write_time() const;
file_time_type last_write_time(error_code& ec) const noexcept;
25
Returns: If cached, the last write time attribute value. Otherwise, last_write_time(path()) or
last_write_time(path(), ec), respectively.
26
Throws: As specified in 30.11.6.
file_status status() const;
file_status status(error_code& ec) const noexcept;
27
Returns: If cached, the status attribute value. Otherwise, status(path()) or status(path(), ec),
respectively.
28
Throws: As specified in 30.11.6.
file_status symlink_status() const;
file_status symlink_status(error_code& ec) const noexcept;
29
Returns: If cached, the symlink status attribute value. Otherwise, symlink_status(path()) or
symlink_status(path(), ec), respectively.
30
Throws: As specified in 30.11.6.
bool operator==(const directory_entry& rhs) const noexcept;
31
Returns: pathobject == rhs.pathobject.
bool operator!=(const directory_entry& rhs) const noexcept;
32
Returns: pathobject != rhs.pathobject.
bool operator< (const directory_entry& rhs) const noexcept;
33
Returns: pathobject < rhs.pathobject.
§ 30.11.11.3
1137
bool operator<=(const directory_entry& rhs) const noexcept;
34
Returns: pathobject <= rhs.pathobject.
bool operator> (const directory_entry& rhs) const noexcept;
35
Returns: pathobject > rhs.pathobject.
bool operator>=(const directory_entry& rhs) const noexcept;
36
Returns: pathobject >= rhs.pathobject.
30.11.12
Class directory_iterator
[fs.class.directory_iterator]
1
An object of type directory_iterator provides an iterator for a sequence of directory_entry elements
representing the path and any cached attribute values (30.11.11) for each file in
a directory or in an
implementation-defined directory-like file type. [ Note: For iteration into sub-directories, see class recursive_-
directory_iterator (30.11.13).
— end note ]
namespace std::filesystem {
class directory_iterator {
public:
using iterator_category = input_iterator_tag;
using value_type
= directory_entry;
using difference_type
= ptrdiff_t;
using pointer
= const directory_entry*;
using reference
= const directory_entry&;
// 30.11.12.1, member functions
directory_iterator() noexcept;
explicit directory_iterator(const path& p);
directory_iterator(const path& p, directory_options options);
directory_iterator(const path& p, error_code& ec) noexcept;
directory_iterator(const path& p, directory_options options,
error_code& ec) noexcept;
directory_iterator(const directory_iterator& rhs);
directory_iterator(directory_iterator&& rhs) noexcept;
~directory_iterator();
directory_iterator& operator=(const directory_iterator& rhs);
directory_iterator& operator=(directory_iterator&& rhs) noexcept;
const directory_entry& operator*() const;
const directory_entry* operator->() const;
directory_iterator&
operator++();
directory_iterator&
increment(error_code& ec) noexcept;
// other members as required by 27.2.3, input iterators
};
}
2
directory_iterator satisfies the requirements of an input iterator (27.2.3).
3
If an iterator of type directory_iterator reports an error or is advanced past the last directory element,
that iterator shall become equal to the end iterator value. The directory_iterator default constructor
shall create an iterator equal to the end iterator value, and this shall be the only valid iterator for the end
condition.
4
The end iterator is not dereferenceable.
5
Two end iterators are always equal. An end iterator shall not be equal to a non-end iterator.
6
The result of calling the path() member of the directory_entry object obtained by dereferencing a
directory_iterator is a reference to a path object composed of the directory argument from which the
iterator was constructed with filename of the directory entry appended as if by operator/=.
7
Directory iteration shall not yield directory entries for the current (dot) and parent (dot-dot) directories.
8
The order of directory entries obtained by dereferencing successive increments of a directory_iterator is
unspecified.
§ 30.11.12
1138
9
Constructors and non-const directory_iterator member functions store the values of any cached at-
tributes (30.11.11) in the directory_entry element returned by operator*(). directory_iterator mem-
ber functions shall not directly or indirectly call any directory_entry refresh function. [ Note: The exact
mechanism for storing cached attribute values is not exposed to users. For exposition, class directory_-
iterator is shown in 30.11.11 as a friend of class directory_entry.
— end note ]
10
[Note: Programs performing directory iteration may wish to test if the path obtained by dereferencing a
directory iterator actually exists. It could be a symbolic link to a non-existent file. Programs recursively
walking directory trees for purposes of removing and renaming entries may wish to avoid following symbolic
links.
— end note ]
11
[ Note: If a file is removed from or added to a directory after the construction of a directory_iterator for
the directory, it is unspecified whether or not subsequently incrementing the iterator will ever result in an
iterator referencing the removed or added directory entry. See POSIX readdir_r.
— end note ]
30.11.12.1
directory_iterator members
[fs.dir.itr.members]
directory_iterator() noexcept;
1
Effects: Constructs the end iterator.
explicit directory_iterator(const path& p);
directory_iterator(const path& p, directory_options options);
directory_iterator(const path& p, error_code& ec) noexcept;
directory_iterator(const path& p, directory_options options, error_code& ec) noexcept;
2
Effects: For the directory that p resolves to, constructs an iterator for the first element in a sequence of
directory_entry elements representing the files in the directory, if any; otherwise the end iterator.
However, if
(options & directory_options::skip_permission_denied) != directory_options::none
and construction encounters an error indicating that permission to access p is denied, constructs the
end iterator and does not report an error.
3
Throws: As specified in 30.11.6.
4
[ Note: To iterate over the current directory, use directory_iterator(".") rather than directory_-
iterator(""). — end note ]
directory_iterator(const directory_iterator& rhs);
directory_iterator(directory_iterator&& rhs) noexcept;
5
Effects: Constructs an object of class directory_iterator.
6
Postconditions: *this has the original value of rhs.
directory_iterator& operator=(const directory_iterator& rhs);
directory_iterator& operator=(directory_iterator&& rhs) noexcept;
7
Effects: If *this and rhs are the same object, the member has no effect.
8
Postconditions: *this has the original value of rhs.
9
Returns: *this.
directory_iterator& operator++();
directory_iterator& increment(error_code& ec) noexcept;
10
Effects: As specified for the prefix increment operation of Input iterators (27.2.3).
11
Returns: *this.
12
Throws: As specified in 30.11.6.
30.11.12.2
directory_iterator non-member functions
[fs.dir.itr.nonmembers]
1
These functions enable range access for directory_iterator.
directory_iterator begin(directory_iterator iter) noexcept;
2
Returns: iter.
§ 30.11.12.2
1139
directory_iterator end(const directory_iterator&) noexcept;
3
Returns: directory_iterator().
30.11.13
Class recursive_directory_iterator
[fs.class.rec.dir.itr]
1
An object of type recursive_directory_iterator provides an iterator for a sequence of directory_entry
elements representing the files in a directory or in an implementation-defined directory-like file type, and its
sub-directories.
namespace std::filesystem {
class recursive_directory_iterator {
public:
using iterator_category = input_iterator_tag;
using value_type
= directory_entry;
using difference_type
= ptrdiff_t;
using pointer
= const directory_entry*;
using reference
= const directory_entry&;
// 30.11.13.1, constructors and destructor
recursive_directory_iterator() noexcept;
explicit recursive_directory_iterator(const path& p);
recursive_directory_iterator(const path& p, directory_options options);
recursive_directory_iterator(const path& p, directory_options options,
error_code& ec) noexcept;
recursive_directory_iterator(const path& p, error_code& ec) noexcept;
recursive_directory_iterator(const recursive_directory_iterator& rhs);
recursive_directory_iterator(recursive_directory_iterator&& rhs) noexcept;
~recursive_directory_iterator();
// 30.11.13.1, observers
directory_options options() const;
int
depth() const;
bool
recursion_pending() const;
const directory_entry& operator*() const;
const directory_entry* operator->() const;
// 30.11.13.1, modifiers
recursive_directory_iterator&
operator=(const recursive_directory_iterator& rhs);
recursive_directory_iterator&
operator=(recursive_directory_iterator&& rhs) noexcept;
recursive_directory_iterator& operator++();
recursive_directory_iterator& increment(error_code& ec) noexcept;
void pop();
void pop(error_code& ec);
void disable_recursion_pending();
// other members as required by 27.2.3, input iterators
};
}
2
Calling options, depth, recursion_pending, pop or disable_recursion_pending on an iterator that is
not dereferenceable results in undefined behavior.
3
The behavior of a recursive_directory_iterator is the same as a directory_iterator unless otherwise
specified.
4
[ Note: If the directory structure being iterated over contains cycles then the end iterator may be unreachable.
— end note ]
§ 30.11.13
1140
30.11.13.1
recursive_directory_iterator members
[fs.rec.dir.itr.members]
recursive_directory_iterator() noexcept;
1
Effects: Constructs the end iterator.
explicit recursive_directory_iterator(const path& p);
recursive_directory_iterator(const path& p, directory_options options);
recursive_directory_iterator(const path& p, directory_options options, error_code& ec) noexcept;
recursive_directory_iterator(const path& p, error_code& ec) noexcept;
2
Effects: Constructs a iterator representing the first entry in the directory p resolves to, if any; otherwise,
the end iterator. However, if
(options & directory_options::skip_permission_denied) != directory_options::none
and construction encounters an error indicating that permission to access p is denied, constructs the
end iterator and does not report an error.
3
Postconditions: options() == options for the signatures with a directory_options argument,
otherwise options() == directory_options::none.
4
Throws: As specified in 30.11.6.
5
[Note: To iterate over the current directory, use recursive_directory_iterator(".") rather than
recursive_directory_iterator(""). — end note ]
6
[ Note: By default, recursive_directory_iterator does not follow directory symlinks. To follow di-
rectory symlinks, specify options as directory_options::follow_directory_symlink — end note ]
recursive_directory_iterator(const recursive_directory_iterator& rhs);
7
Effects: Constructs an object of class recursive_directory_iterator.
8
Postconditions:
(8.1)
—
options() == rhs.options()
(8.2)
—
depth() == rhs.depth()
(8.3)
—
recursion_pending() == rhs.recursion_pending()
recursive_directory_iterator(recursive_directory_iterator&& rhs) noexcept;
9
Effects: Constructs an object of class recursive_directory_iterator.
10
Postconditions: options(), depth(), and recursion_pending() have the values that rhs.options(),
rhs.depth(), and rhs.recursion_pending(), respectively, had before the function call.
recursive_directory_iterator& operator=(const recursive_directory_iterator& rhs);
11
Effects: If *this and rhs are the same object, the member has no effect.
12
Postconditions:
(12.1)
—
options() == rhs.options()
(12.2)
—
depth() == rhs.depth()
(12.3)
—
recursion_pending() == rhs.recursion_pending()
13
Returns: *this.
recursive_directory_iterator& operator=(recursive_directory_iterator&& rhs) noexcept;
14
Effects: If *this and rhs are the same object, the member has no effect.
15
Postconditions: options(), depth(), and recursion_pending() have the values that rhs.options(),
rhs.depth(), and rhs.recursion_pending(), respectively, had before the function call.
16
Returns: *this.
directory_options options() const;
17
Returns: The value of the argument passed to the constructor for the options parameter, if present,
otherwise directory_options::none.
18
Throws: Nothing.
§ 30.11.13.1
1141
int depth() const;
19
Returns: The current depth of the directory tree being traversed. [ Note: The initial directory is depth
0, its immediate subdirectories are depth 1, and so forth.
— end note ]
20
Throws: Nothing.
bool recursion_pending() const;
21
Returns: true if disable_recursion_pending() has not been called subsequent to the prior construc-
tion or increment operation, otherwise false.
22
Throws: Nothing.
recursive_directory_iterator& operator++();
recursive_directory_iterator& increment(error_code& ec) noexcept;
23
Effects: As specified for the prefix increment operation of Input iterators (27.2.3), except that:
(23.1)
—
If there are no more entries at the current depth, then if depth() != 0 iteration over the parent
directory resumes; otherwise *this = recursive_directory_iterator().
(23.2)
—
Otherwise if
recursion_pending() && is_directory((*this)->status()) &&
(!is_symlink((*this)->symlink_status()) ||
(options() & directory_options::follow_directory_symlink) != directory_options::none)
then either directory (*this)->path() is recursively iterated into or, if
(options() & directory_options::skip_permission_denied) != directory_options::none
and an error occurs indicating that permission to access directory (*this)->path() is denied,
then directory (*this)->path() is treated as an empty directory and no error is reported.
24
Returns: *this.
25
Throws: As specified in 30.11.6.
void pop();
void pop(error_code& ec);
26
Effects: If depth() == 0, set *this to recursive_directory_iterator(). Otherwise, cease iteration
of the directory currently being iterated over, and continue iteration over the parent directory.
27
Throws: As specified in 30.11.6.
void disable_recursion_pending();
28
Postconditions: recursion_pending() == false.
29
[ Note: disable_recursion_pending() is used to prevent unwanted recursion into a directory.
— end
note ]
30.11.13.2
recursive_directory_iterator non-member functions
[fs.rec.dir.itr.nonmembers]
1
These functions enable use of recursive_directory_iterator with range-based for statements.
recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
2
Returns: iter.
recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
3
Returns: recursive_directory_iterator().
30.11.14
Filesystem operation functions
[fs.op.funcs]
1
Filesystem operation functions query or modify files, including directories, in external storage.
2
[Note: Because hardware failures, network failures, file system races (30.11.2.3), and many other kinds of
errors occur frequently in file system operations, users should be aware that any filesystem operation function,
no matter how apparently innocuous, may encounter an error; see 30.11.6.
— end note ]
30.11.14.1
Absolute
[fs.op.absolute]
path absolute(const path& p);
§ 30.11.14.1
1142
path absolute(const path& p, error_code& ec);
1
Effects: Composes an absolute path referencing the same file system location as p according to the
operating system (30.11.2.2).
2
Returns: The composed path. The signature with argument ec returns path() if an error occurs.
3
[ Note: For the returned path, rp, rp.is_absolute() is true unless an error occurs.
— end note ]
4
Throws: As specified in 30.11.6.
5
[Note: To resolve symlinks, or perform other sanitization which might require queries to secondary
storage, such as hard disks, consider canonical (30.11.14.2).
— end note ]
6
[Note: Implementations are strongly encouraged to not query secondary storage, and not consider
!exists(p) an error.
— end note ]
7
[Example: For POSIX-based operating systems, absolute(p) is simply current_path()/p. For
Windows-based operating systems, absolute might have the same semantics as GetFullPathNameW.
— end example ]
30.11.14.2
Canonical
[fs.op.canonical]
path canonical(const path& p);
path canonical(const path& p, error_code& ec);
1
Effects: Converts p to an absolute path that has no symbolic link, dot, or dot-dot elements in its
pathname in the generic format.
2
Returns: A path that refers to the same file system object as absolute(p). The signature with
argument ec returns path() if an error occurs.
3
Throws: As specified in 30.11.6.
4
Remarks: !exists(p) is an error.
30.11.14.3
Copy
[fs.op.copy]
void
copy(const path& from, const path& to);
1
Effects: Equivalent to copy(from, to, copy_options::none).
void
copy(const path& from, const path& to, error_code& ec) noexcept;
2
Effects: Equivalent to copy(from, to, copy_options::none, ec).
void
copy(const path& from, const path& to, copy_options options);
void
copy(const path& from, const path& to, copy_options options,
error_code& ec) noexcept;
3
Requires: At most one element from each option group (30.11.9.3) is set in options.
4
Effects: Before the first use of f and t:
(4.1)
—
If
(options & copy_options::create_symlinks) != copy_options::none ||
(options & copy_options::skip_symlinks) != copy_options::none
then auto f = symlink_status(from) and if needed auto t = symlink_status(to).
(4.2)
—
Otherwise, if
(options & copy_options::copy_symlinks) != copy_options::none
then auto f = symlink_status(from) and if needed auto t = status(to).
(4.3)
—
Otherwise, auto f = status(from) and if needed auto t = status(to).
Effects are then as follows:
(4.4)
—
If f.type() or t.type() is an implementation-defined file type (30.11.9.2), then the effects are
implementation-defined.
(4.5)
—
Otherwise, an error is reported as specified in 30.11.6 if:
(4.5.1)
—
exists(f) is false, or
(4.5.2)
—
equivalent(from, to) is true, or
§ 30.11.14.3
1143
(4.5.3)
—
is_other(f) || is_other(t) is true, or
(4.5.4)
—
is_directory(f) && is_regular_file(t) is true.
(4.6)
—
Otherwise, if is_symlink(f), then:
(4.6.1)
—
If (options & copy_options::skip_symlinks) != copy_options::none then return.
(4.6.2)
—
Otherwise if
!exists(t) && (options & copy_options::copy_symlinks) != copy_options::none
then copy_symlink(from, to).
(4.6.3)
—
Otherwise report an error as specified in 30.11.6.
(4.7)
—
Otherwise, if is_regular_file(f), then:
(4.7.1)
—
If (options & copy_options::directories_only) != copy_options::none, then return.
(4.7.2)
—
Otherwise, if (options & copy_options::create_symlinks)
!= copy_options::none,
then create a symbolic link to the source file.
(4.7.3)
—
Otherwise, if (options & copy_options::create_hard_links) != copy_options::none,
then create a hard link to the source file.
(4.7.4)
—
Otherwise, if is_directory(t), then copy_file(from, to/from.filename(), options).
(4.7.5)
—
Otherwise, copy_file(from, to, options).
(4.8)
—
Otherwise, if
is_directory(f) &&
((options & copy_options::recursive) != copy_options::none ||
options == copy_options::none)
then:
(4.8.1)
—
If exists(t) is false, then create_directory(to, from).
(4.8.2)
—
Then, iterate over the files in from, as if by
for (const directory_entry& x : directory_iterator(from))
copy(x.path(), to/x.path().filename(), options | copy_options::unspecified )
(4.9)
—
Otherwise, for the signature with argument ec, ec.clear().
(4.10)
—
Otherwise, no effects.
5
Throws: As specified in 30.11.6.
6
Remarks: For the signature with argument ec, any library functions called by the implementation shall
have an error_code argument if applicable.
7
[ Example: Given this directory structure:
/dir1
file1
file2
dir2
file3
Calling copy("/dir1", "/dir3") would result in:
/dir1
file1
file2
dir2
file3
/dir3
file1
file2
Alternatively, calling copy("/dir1", "/dir3", copy_options::recursive) would result in:
/dir1
file1
file2
dir2
§
30.11.14.3
1144
file3
/dir3
file1
file2
dir2
file3
— end example ]
30.11.14.4
Copy file
[fs.op.copy_file]
bool
copy_file(const path& from, const path& to);
bool
copy_file(const path& from, const path& to, error_code& ec) noexcept;
1
Returns: copy_file(from, to, copy_options::none) or
copy_file(from, to, copy_options::none, ec), respectively.
2
Throws: As specified in 30.11.6.
bool
copy_file(const path& from, const path& to, copy_options options);
bool
copy_file(const path& from, const path& to, copy_options options,
error_code& ec) noexcept;
3
Requires: At most one element from each option group (30.11.9.3) is set in options.
4
Effects: As follows:
(4.1)
—
Report a file already exists error as specified in 30.11.6 if:
(4.1.1)
—
is_regular_file(from) is false, or
(4.1.2)
—
exists(to) is true and is_regular_file(to) is false, or
(4.1.3)
—
exists(to) is true and equivalent(from, to) is true, or
(4.1.4)
—
exists(to) is true and
(options & (copy_options::skip_existing |
copy_options::overwrite_existing |
copy_options::update_existing)) == copy_options::none
(4.2)
—
Otherwise, copy the contents and attributes of the file from resolves to, to the file to resolves to,
if:
(4.2.1)
—
exists(to) is false, or
(4.2.2)
—
(options & copy_options::overwrite_existing) != copy_options::none, or
(4.2.3)
—
(options & copy_options::update_existing)
!= copy_options::none and from is
more recent than to, determined as if by use of the last_write_time function (30.11.14.25).
(4.3)
—
Otherwise, no effects.
5
Returns: true if the from file was copied, otherwise false. The signature with argument ec returns
false if an error occurs.
6
Throws: As specified in 30.11.6.
7
Complexity: At most one direct or indirect invocation of status(to).
30.11.14.5
Copy symlink
[fs.op.copy_symlink]
void copy_symlink(const path& existing_symlink, const path& new_symlink);
void copy_symlink(const path& existing_symlink, const path& new_symlink,
error_code& ec) noexcept;
1
Effects: Equivalent to function (read_symlink(existing_symlink), new_symlink) or
function (read_symlink(existing_symlink, ec), new_symlink, ec), respectively, where in each
case function is create_symlink or create_directory_symlink as appropriate.
2
Throws: As specified in 30.11.6.
30.11.14.6
Create directories
[fs.op.create_directories]
bool create_directories(const path& p);
§ 30.11.14.6
1145
bool create_directories(const path& p, error_code& ec) noexcept;
1
Effects: Calls create_directory() for each element of p that does not exist.
2
Returns: true if a new directory was created for the directory p resolves to, otherwise false. The
signature with argument ec returns false if an error occurs.
3
Throws: As specified in 30.11.6.
4
Complexity: O(n) where n is the number of elements of p.
30.11.14.7
Create directory
[fs.op.create_directory]
bool create_directory(const path& p);
bool create_directory(const path& p, error_code& ec) noexcept;
1
Effects: Creates the directory p resolves to, as if by POSIX mkdir() with a second argument of
static_cast<int>(perms::all). Creation failure because p already exists is not an error.
2
Returns: true if a new directory was created, otherwise false. The signature with argument ec returns
false if an error occurs.
3
Throws: As specified in 30.11.6.
bool create_directory(const path& p, const path& existing_p);
bool create_directory(const path& p, const path& existing_p, error_code& ec) noexcept;
4
Effects: Establishes the postcondition by attempting to create the directory p resolves to, with
attributes copied from directory existing_p. The set of attributes copied is operating system
dependent. Creation failure because p resolves to an existing directory shall not be treated as
an error.
[Note: For POSIX-based operating systems, the attributes are those copied by native
API stat(existing_p.c_str(), &attributes_stat) followed by mkdir(p.c_str(), attributes_-
stat.st_mode). For Windows-based operating systems, the attributes are those copied by native API
CreateDirectoryExW(existing_p.c_str(), p.c_str(), 0). — end note ]
5
Postconditions: is_directory(p).
6
Returns: true if a new directory was created, otherwise false. The signature with argument ec returns
false if an error occurs.
7
Throws: As specified in 30.11.6.
30.11.14.8
Create directory symlink
[fs.op.create_dir_symlk]
void create_directory_symlink(const path& to, const path& new_symlink);
void create_directory_symlink(const path& to, const path& new_symlink,
error_code& ec) noexcept;
1
Effects: Establishes the postcondition, as if by POSIX symlink().
2
Postconditions: new_symlink resolves to a symbolic link file that contains an unspecified representation
of to.
3
Throws: As specified in 30.11.6.
4
[Note: Some operating systems require symlink creation to identify that the link is to a directory.
Portable code should use create_directory_symlink() to create directory symlinks rather than
create_symlink() — end note ]
5
[ Note: Some operating systems do not support symbolic links at all or support them only for regular
files. Some file systems (such as the FAT file system) do not support symbolic links regardless of the
operating system.
— end note ]
30.11.14.9
Create hard link
[fs.op.create_hard_lk]
void create_hard_link(const path& to, const path& new_hard_link);
void create_hard_link(const path& to, const path& new_hard_link,
error_code& ec) noexcept;
1
Effects: Establishes the postcondition, as if by POSIX link().
2
Postconditions:
(2.1)
—
exists(to) && exists(new_hard_link) && equivalent(to, new_hard_link)
§ 30.11.14.9
1146
(2.2)
—
The contents of the file or directory to resolves to are unchanged.
3
Throws: As specified in 30.11.6.
4
[ Note: Some operating systems do not support hard links at all or support them only for regular files.
Some file systems (such as the FAT file system) do not support hard links regardless of the operating
system. Some file systems limit the number of links per file.
— end note ]
30.11.14.10
Create symlink
[fs.op.create_symlink]
void create_symlink(const path& to, const path& new_symlink);
void create_symlink(const path& to, const path& new_symlink,
error_code& ec) noexcept;
1
Effects: Establishes the postcondition, as if by POSIX symlink().
2
Postconditions: new_symlink resolves to a symbolic link file that contains an unspecified representation
of to.
3
Throws: As specified in 30.11.6.
4
[ Note: Some operating systems do not support symbolic links at all or support them only for regular
files. Some file systems (such as the FAT file system) do not support symbolic links regardless of the
operating system.
— end note ]
30.11.14.11
Current path
[fs.op.current_path]
path current_path();
path current_path(error_code& ec);
1
Returns: The absolute path of the current working directory, whose pathname in the native format is
obtained as if by POSIX getcwd(). The signature with argument ec returns path() if an error occurs.
2
Throws: As specified in 30.11.6.
3
Remarks: The current working directory is the directory, associated with the process, that is used as
the starting location in pathname resolution for relative paths.
4
[ Note: The current_path() name was chosen to emphasize that the returned value is a path, not just
a single directory name.
— end note ]
5
[ Note: The current path as returned by many operating systems is a dangerous global variable. It may
be changed unexpectedly by a third-party or system library functions, or by another thread.
— end
note ]
void current_path(const path& p);
void current_path(const path& p, error_code& ec) noexcept;
6
Effects: Establishes the postcondition, as if by POSIX chdir().
7
Postconditions: equivalent(p, current_path()).
8
Throws: As specified in 30.11.6.
9
[Note: The current path for many operating systems is a dangerous global state. It may be changed
unexpectedly by a third-party or system library functions, or by another thread.
— end note ]
30.11.14.12
Equivalent
[fs.op.equivalent]
bool equivalent(const path& p1, const path& p2);
bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
1
Returns: true, if p1 and p2 resolve to the same file system entity, else false. The signature with
argument ec returns false if an error occurs.
2
Two paths are considered to resolve to the same file system entity if two candidate entities reside on
the same device at the same location. [ Note: On POSIX platforms, this is determined as if by the
values of the POSIX stat structure, obtained as if by stat() for the two paths, having equal st_dev
values and equal st_ino values.
— end note ]
3
Remarks: !exists(p1) || !exists(p2) is an error.
4
Throws: As specified in 30.11.6.
§ 30.11.14.12
1147
30.11.14.13
Exists
[fs.op.exists]
bool exists(file_status s) noexcept;
1
Returns: status_known(s) && s.type() != file_type::not_found.
bool exists(const path& p);
bool exists(const path& p, error_code& ec) noexcept;
2
Let s be a file_status, determined as if by status(p) or status(p, ec), respectively.
3
Effects: The signature with argument ec calls ec.clear() if status_known(s).
4
Returns: exists(s).
5
Throws: As specified in 30.11.6.
30.11.14.14
File size
[fs.op.file_size]
uintmax_t file_size(const path& p);
uintmax_t file_size(const path& p, error_code& ec) noexcept;
1
Effects: If exists(p) is false, an error is reported (30.11.6).
2
Returns:
(2.1)
—
If is_regular_file(p), the size in bytes of the file p resolves to, determined as if by the value of
the POSIX stat structure member st_size obtained as if by POSIX stat().
(2.2)
—
Otherwise, the result is implementation-defined.
The signature with argument ec returns static_cast<uintmax_t>(-1) if an error occurs.
3
Throws: As specified in 30.11.6.
30.11.14.15
Hard link count
[fs.op.hard_lk_ct]
uintmax_t hard_link_count(const path& p);
uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
1
Returns: The number of hard links for p. The signature with argument ec returns static_-
cast<uintmax_t>(-1) if an error occurs.
2
Throws: As specified in 30.11.6.
30.11.14.16
Is block file
[fs.op.is_block_file]
bool is_block_file(file_status s) noexcept;
1
Returns: s.type() == file_type::block.
bool is_block_file(const path& p);
bool is_block_file(const path& p, error_code& ec) noexcept;
2
Returns: is_block_file(status(p)) or is_block_file(status(p, ec)), respectively. The signa-
ture with argument ec returns false if an error occurs.
3
Throws: As specified in 30.11.6.
30.11.14.17
Is character file
[fs.op.is_char_file]
bool is_character_file(file_status s) noexcept;
1
Returns: s.type() == file_type::character.
bool is_character_file(const path& p);
bool is_character_file(const path& p, error_code& ec) noexcept;
2
Returns: is_character_file(status(p)) or is_character_file(status(p, ec)), respectively.
The signature with argument ec returns false if an error occurs.
3
Throws: As specified in 30.11.6.
§ 30.11.14.17
1148
30.11.14.18
Is directory
[fs.op.is_directory]
bool is_directory(file_status s) noexcept;
1
Returns: s.type() == file_type::directory.
bool is_directory(const path& p);
bool is_directory(const path& p, error_code& ec) noexcept;
2
Returns: is_directory(status(p)) or is_directory(status(p, ec)), respectively. The signature
with argument ec returns false if an error occurs.
3
Throws: As specified in 30.11.6.
30.11.14.19
Is empty
[fs.op.is_empty]
bool is_empty(const path& p);
bool is_empty(const path& p, error_code& ec) noexcept;
1
Effects:
(1.1)
—
Determine file_status s, as if by status(p) or status(p, ec), respectively.
(1.2)
—
For the signature with argument ec, return false if an error occurred.
(1.3)
—
Otherwise, if is_directory(s):
(1.3.1)
—
Create a variable itr, as if by directory_iterator itr(p) or directory_iterator itr(p,
ec), respectively.
(1.3.2)
—
For the signature with argument ec, return false if an error occurred.
(1.3.3)
—
Otherwise, return itr == directory_iterator().
(1.4)
—
Otherwise:
(1.4.1)
—
Determine uintmax_t sz, as if by file_size(p) or file_size(p, ec), respectively.
(1.4.2)
—
For the signature with argument ec, return false if an error occurred.
(1.4.3)
—
Otherwise, return sz == 0.
2
Throws: As specified in 30.11.6.
30.11.14.20
Is fifo
[fs.op.is_fifo]
bool is_fifo(file_status s) noexcept;
1
Returns: s.type() == file_type::fifo.
bool is_fifo(const path& p);
bool is_fifo(const path& p, error_code& ec) noexcept;
2
Returns: is_fifo(status(p)) or is_fifo(status(p, ec)), respectively. The signature with argu-
ment ec returns false if an error occurs.
3
Throws: As specified in 30.11.6.
30.11.14.21
Is other
[fs.op.is_other]
bool is_other(file_status s) noexcept;
1
Returns: exists(s) && !is_regular_file(s) && !is_directory(s) && !is_symlink(s).
bool is_other(const path& p);
bool is_other(const path& p, error_code& ec) noexcept;
2
Returns: is_other(status(p)) or is_other(status(p, ec)), respectively. The signature with
argument ec returns false if an error occurs.
3
Throws: As specified in 30.11.6.
30.11.14.22
Is regular file
[fs.op.is_regular_file]
bool is_regular_file(file_status s) noexcept;
1
Returns: s.type() == file_type::regular.
§ 30.11.14.22
1149
bool is_regular_file(const path& p);
2
Returns: is_regular_file(status(p)).
3
Throws: filesystem_error if status(p) would throw filesystem_error.
bool is_regular_file(const path& p, error_code& ec) noexcept;
4
Effects: Sets ec as if by status(p, ec).
[Note: file_type::none, file_type::not_found and
file_type::unknown cases set ec to error values. To distinguish between cases, call the status
function directly.
— end note ]
5
Returns: is_regular_file(status(p, ec)). Returns false if an error occurs.
30.11.14.23
Is socket
[fs.op.is_socket]
bool is_socket(file_status s) noexcept;
1
Returns: s.type() == file_type::socket.
bool is_socket(const path& p);
bool is_socket(const path& p, error_code& ec) noexcept;
2
Returns: is_socket(status(p)) or is_socket(status(p, ec)), respectively. The signature with
argument ec returns false if an error occurs.
3
Throws: As specified in 30.11.6.
30.11.14.24
Is symlink
[fs.op.is_symlink]
bool is_symlink(file_status s) noexcept;
1
Returns: s.type() == file_type::symlink.
bool is_symlink(const path& p);
bool is_symlink(const path& p, error_code& ec) noexcept;
2
Returns: is_symlink(symlink_status(p)) or is_symlink(symlink_status(p, ec)), respectively.
The signature with argument ec returns false if an error occurs.
3
Throws: As specified in 30.11.6.
30.11.14.25
Last write time
[fs.op.last_write_time]
file_time_type last_write_time(const path& p);
file_time_type last_write_time(const path& p, error_code& ec) noexcept;
1
Returns: The time of last data modification of p, determined as if by the value of the POSIX stat
structure member st_mtime obtained as if by POSIX stat(). The signature with argument ec returns
file_time_type::min() if an error occurs.
2
Throws: As specified in 30.11.6.
void last_write_time(const path& p, file_time_type new_time);
void last_write_time(const path& p, file_time_type new_time,
error_code& ec) noexcept;
3
Effects: Sets the time of last data modification of the file resolved to by p to new_time, as if by POSIX
futimens().
4
Throws: As specified in 30.11.6.
5
[ Note: A postcondition of last_write_time(p) == new_time is not specified since it might not hold
for file systems with coarse time granularity.
— end note ]
30.11.14.26
Permissions
[fs.op.permissions]
void permissions(const path& p, perms prms, perm_options opts=perm_options::replace);
void permissions(const path& p, perms prms, error_code& ec) noexcept;
void permissions(const path& p, perms prms, perm_options opts, error_code& ec);
1
Requires: Exactly one of the perm_options constants replace, add, or remove is present in opts.
2
Remarks: The second signature behaves as if it had an additional parameter perm_options opts with
an argument of perm_options::replace.
§ 30.11.14.26
1150
3
Effects: Applies the action specified by opts to the file p resolves to, or to file p itself if p is a symbolic
link and perm_options::nofollow is set in opts. The action is applied as if by POSIX fchmodat().
4
[ Note: Conceptually permissions are viewed as bits, but the actual implementation may use some other
mechanism. — end note ]
5
Throws: As specified in 30.11.6.
30.11.14.27
Proximate
[fs.op.proximate]
path proximate(const path& p, error_code& ec);
1
Returns: proximate(p, current_path(), ec).
2
Throws: As specified in 30.11.6.
path proximate(const path& p, const path& base = current_path());
path proximate(const path& p, const path& base, error_code& ec);
3
Returns: For the first form:
weakly_canonical(p).lexically_proximate(weakly_canonical(base));
For the second form:
weakly_canonical(p, ec).lexically_proximate(weakly_canonical(base, ec));
or path() at the first error occurrence, if any.
4
Throws: As specified in 30.11.6.
30.11.14.28
Read symlink
[fs.op.read_symlink]
path read_symlink(const path& p);
path read_symlink(const path& p, error_code& ec);
1
Returns: If p resolves to a symbolic link, a path object containing the contents of that symbolic link.
The signature with argument ec returns path() if an error occurs.
2
Throws: As specified in 30.11.6. [Note: It is an error if p does not resolve to a symbolic link.
— end
note ]
30.11.14.29
Relative
[fs.op.relative]
path relative(const path& p, error_code& ec);
1
Returns: relative(p, current_path(), ec).
2
Throws: As specified in 30.11.6.
path relative(const path& p, const path& base = current_path());
path relative(const path& p, const path& base, error_code& ec);
3
Returns: For the first form:
weakly_canonical(p).lexically_relative(weakly_canonical(base));
For the second form:
weakly_canonical(p, ec).lexically_relative(weakly_canonical(base, ec));
or path() at the first error occurrence, if any.
4
Throws: As specified in 30.11.6.
30.11.14.30
Remove
[fs.op.remove]
bool remove(const path& p);
bool remove(const path& p, error_code& ec) noexcept;
1
Effects: If exists(symlink_status(p, ec)), the file p is removed as if by POSIX remove(). [ Note:
A symbolic link is itself removed, rather than the file it resolves to.
— end note ]
2
Postconditions: exists(symlink_status(p)) is false.
3
Returns: false if p did not exist, otherwise true. The signature with argument ec returns false if
an error occurs.
§ 30.11.14.30
1151
4
Throws: As specified in 30.11.6.
30.11.14.31
Remove all
[fs.op.remove_all]
uintmax_t remove_all(const path& p);
uintmax_t remove_all(const path& p, error_code& ec) noexcept;
1
Effects: Recursively deletes the contents of p if it exists, then deletes file p itself, as if by POSIX
remove(). [ Note: A symbolic link is itself removed, rather than the file it resolves to.
— end note ]
2
Postconditions: exists(symlink_status(p)) is false.
3
Returns: The number of files removed. The signature with argument ec returns static_cast<
uintmax_t>(-1) if an error occurs.
4
Throws: As specified in 30.11.6.
30.11.14.32
Rename
[fs.op.rename]
void rename(const path& old_p, const path& new_p);
void rename(const path& old_p, const path& new_p, error_code& ec) noexcept;
1
Effects: Renames old_p to new_p, as if by POSIX rename().
[ Note:
(1.1)
—
If old_p and new_p resolve to the same existing file, no action is taken.
(1.2)
—
Otherwise, the rename may include the following effects:
(1.2.1)
—
if new_p resolves to an existing non-directory file, new_p is removed; otherwise,
(1.2.2)
—
if new_p resolves to an existing directory, new_p is removed if empty on POSIX compliant
operating systems but may be an error on other operating systems.
A symbolic link is itself renamed, rather than the file it resolves to.
— end note ]
2
Throws: As specified in 30.11.6.
30.11.14.33
Resize file
[fs.op.resize_file]
void resize_file(const path& p, uintmax_t new_size);
void resize_file(const path& p, uintmax_t new_size, error_code& ec) noexcept;
1
Postconditions: file_size(p) == new_size.
2
Throws: As specified in 30.11.6.
3
Remarks: Achieves its postconditions as if by POSIX truncate().
30.11.14.34
Space
[fs.op.space]
space_info space(const path& p);
space_info space(const path& p, error_code& ec) noexcept;
1
Returns: An object of type space_info. The value of the space_info object is determined as if
by using POSIX statvfs to obtain a POSIX struct statvfs, and then multiplying its f_blocks,
f_bfree, and f_bavail members by its f_frsize member, and assigning the results to the capacity,
free, and available members respectively. Any members for which the value cannot be determined
shall be set to static_cast<uintmax_t>(-1). For the signature with argument ec, all members are
set to static_cast<uintmax_t>(-1) if an error occurs.
2
Throws: As specified in 30.11.6.
3
Remarks: The value of member space_info::available is operating system dependent.
[Note:
available may be less than free. — end note ]
30.11.14.35
Status
[fs.op.status]
file_status status(const path& p);
1
Effects: As if:
error_code ec;
file_status result = status(p, ec);
§ 30.11.14.35
1152
if (result.type() == file_type::none)
throw filesystem_error(implementation-supplied-message , p, ec);
return result;
2
Returns: See above.
3
Throws: filesystem_error.
[Note: result values of file_status(file_type::not_found) and
file_status(file_type::unknown) are not considered failures and do not cause an exception to be
thrown. — end note ]
file_status status(const path& p, error_code& ec) noexcept;
4
Effects: If possible, determines the attributes of the file p resolves to, as if by using POSIX stat()
to obtain a POSIX struct stat. If, during attribute determination, the underlying file system API
reports an error, sets ec to indicate the specific error reported. Otherwise, ec.clear(). [Note: This
allows users to inspect the specifics of underlying API errors even when the value returned by status()
is not file_status(file_type::none). — end note ]
5
Let prms denote the result of (m & perms::mask), where m is determined as if by converting the
st_mode member of the obtained struct stat to the type perms.
6
Returns:
(6.1)
—
If ec
!= error_code():
(6.1.1)
—
If the specific error indicates that p cannot be resolved because some element of the path does
not exist, returns file_status(file_type::not_found).
(6.1.2)
—
Otherwise, if the specific error indicates that p can be resolved but the attributes cannot be
determined, returns file_status(file_type::unknown).
(6.1.3)
—
Otherwise, returns file_status(file_type::none).
[ Note: These semantics distinguish between p being known not to exist, p existing but not being
able to determine its attributes, and there being an error that prevents even knowing if p exists.
These distinctions are important to some use cases.
— end note ]
(6.2)
—
Otherwise,
(6.2.1)
—
If the attributes indicate a regular file, as if by POSIX S_ISREG, returns file_status(file_-
type::regular, prms). [ Note: file_type::regular implies appropriate <fstream> oper-
ations would succeed, assuming no hardware, permission, access, or file system race errors.
Lack of file_type::regular does not necessarily imply <fstream> operations would fail on
a directory.
— end note ]
(6.2.2)
—
Otherwise, if the attributes indicate a directory, as if by POSIX S_ISDIR, returns file_-
status(file_type::directory, prms). [ Note: file_type::directory implies that call-
ing directory_iterator(p) would succeed. — end note ]
(6.2.3)
—
Otherwise, if the attributes indicate a block special file, as if by POSIX S_ISBLK, returns
file_status(file_type::block, prms).
(6.2.4)
—
Otherwise, if the attributes indicate a character special file, as if by POSIX S_ISCHR, returns
file_status(file_type::character, prms).
(6.2.5)
—
Otherwise, if the attributes indicate a fifo or pipe file, as if by POSIX S_ISFIFO, returns
file_status(file_type::fifo, prms).
(6.2.6)
—
Otherwise, if the attributes indicate a socket, as if by POSIX S_ISSOCK, returns file_-
status(file_type::socket, prms).
(6.2.7)
—
Otherwise, if the attributes indicate an implementation-defined file type (30.11.9.2), returns
file_status(file_type::A, prms), where A is the constant for the implementation-defined
file type.
(6.2.8)
—
Otherwise, returns file_status(file_type::unknown, prms).
7
Remarks: If a symbolic link is encountered during pathname resolution, pathname resolution continues
using the contents of the symbolic link.
§ 30.11.14.35
1153
30.11.14.36
Status known
[fs.op.status_known]
bool status_known(file_status s) noexcept;
1
Returns: s.type() != file_type::none.
30.11.14.37
Symlink status
[fs.op.symlink_status]
file_status symlink_status(const path& p);
file_status symlink_status(const path& p, error_code& ec) noexcept;
1
Effects: Same as status(), above, except that the attributes of p are determined as if by using POSIX
lstat() to obtain a POSIX struct stat.
2
Let prms denote the result of (m & perms::mask), where m is determined as if by converting the
st_mode member of the obtained struct stat to the type perms.
3
Returns: Same as status(), above, except that if the attributes indicate a symbolic link, as if by
POSIX S_ISLNK, returns file_status(file_type::symlink, prms). The signature with argument
ec returns file_status(file_type::none) if an error occurs.
4
Remarks: Pathname resolution terminates if p names a symbolic link.
5
Throws: As specified in 30.11.6.
30.11.14.38
Temporary directory path
[fs.op.temp_dir_path]
path temp_directory_path();
path temp_directory_path(error_code& ec);
1
Let p be an unspecified directory path suitable for temporary files.
2
Effects: If exists(p) is false or is_directory(p) is false, an error is reported (30.11.6).
3
Returns: The path p. The signature with argument ec returns path() if an error occurs.
4
Throws: As specified in 30.11.6.
5
[ Example: For POSIX-based operating systems, an implementation might return the path supplied by
the first environment variable found in the list TMPDIR, TMP, TEMP, TEMPDIR, or if none of these
are found, "/tmp".
For Windows-based operating systems, an implementation might return the path reported by the
Windows GetTempPath API function. — end example ]
30.11.14.39
Weakly canonical
[fs.op.weakly_canonical]
path weakly_canonical(const path& p);
path weakly_canonical(const path& p, error_code& ec);
1
Returns: p with symlinks resolved and the result normalized (30.11.7.1).
2
Effects: Using status(p) or status(p, ec), respectively, to determine existence, return a path
composed by operator/= from the result of calling canonical() without a base argument and with a
path argument composed of the leading elements of p that exist, if any, followed by the elements of p
that do not exist, if any. For the first form, canonical() is called without an error_code argument.
For the second form, canonical() is called with ec as an error_code argument, and path() is returned
at the first error occurrence, if any.
3
Postconditions: The returned path is in normal form (30.11.7.1).
4
Remarks: Implementations should avoid unnecessary normalization such as when canonical has already
been called on the entirety of p.
5
Throws: As specified in 30.11.6.
30.12
C library files
[c.files]
30.12.1
Header <cstdio> synopsis
[cstdio.syn]
namespace std {
using size_t = see 21.2.4;
using FILE = see below ;
using fpos_t = see below ;
}
§ 30.12.1
1154
#define NULL see 21.2.3
#define _IOFBF see below
#define _IOLBF see below
#define _IONBF see below
#define BUFSIZ see below
#define EOF see below
#define FOPEN_MAX see below
#define FILENAME_MAX see below
#define L_tmpnam see below
#define SEEK_CUR see below
#define SEEK_END see below
#define SEEK_SET see below
#define TMP_MAX see below
#define stderr see below
#define stdin see below
#define stdout see below
namespace std {
int remove(const char* filename);
int rename(const char* old, const char* new);
FILE* tmpfile();
char* tmpnam(char* s);
int fclose(FILE* stream);
int fflush(FILE* stream);
FILE* fopen(const char* filename, const char* mode);
FILE* freopen(const char* filename, const char* mode,
FILE* stream);
void setbuf(FILE* stream, char* buf);
int setvbuf(FILE* stream, char* buf, int mode, size_t
size);
int fprintf(FILE* stream, const char* format, ...);
int fscanf(FILE* stream, const char* format, ...);
int printf(const char* format, ...);
int scanf(const char* format, ...);
int snprintf(char* s, size_t n, const char* format, ...);
int sprintf(char* s, const char* format, ...);
int sscanf(const char* s, const char* format, ...);
int vfprintf(FILE* stream, const char* format, va_list arg);
int vfscanf(FILE* stream, const char* format, va_list arg);
int vprintf(const char* format, va_list arg);
int vscanf(const char* format, va_list arg);
int vsnprintf(char* s, size_t n, const char* format, va_list arg);
int vsprintf(char* s, const char* format, va_list arg);
int vsscanf(const char* s, const char* format, va_list arg);
int fgetc(FILE* stream);
char* fgets(char* s, int n, FILE* stream);
int fputc(int c, FILE* stream);
int fputs(const char* s, FILE* stream);
int getc(FILE* stream);
int getchar();
int putc(int c, FILE* stream);
int putchar(int c);
int puts(const char* s);
int ungetc(int c, FILE* stream);
size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream);
size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream);
int fgetpos(FILE* stream, fpos_t* pos);
int fseek(FILE* stream, long int offset, int whence);
int fsetpos(FILE* stream, const fpos_t* pos);
long int ftell(FILE* stream);
void rewind(FILE* stream);
void clearerr(FILE* stream);
int feof(FILE* stream);
int ferror(FILE* stream);
void perror(const char* s);
}
§
30.12.1
1155
1
The contents and meaning of the header <cstdio> are the same as the C standard library header <stdio.h>.
2
Calls to the function tmpnam with an argument that is a null pointer value may introduce a data race (20.5.5.9)
with other calls to tmpnam with an argument that is a null pointer value.
See also: ISO C 7.21
30.12.2
Header <cinttypes> synopsis
[cinttypes.syn]
#include <cstdint>
// see 21.4.1
namespace std {
using imaxdiv_t = see below ;
intmax_t imaxabs(intmax_t j);
imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
intmax_t strtoimax(const char* nptr, char** endptr, int base);
uintmax_t strtoumax(const char* nptr, char** endptr, int base);
intmax_t wcstoimax(const wchar_t* nptr, wchar_t** endptr, int base);
uintmax_t wcstoumax(const wchar_t* nptr, wchar_t** endptr,
int
base);
intmax_t abs(intmax_t);
// optional, see below
imaxdiv_t div(intmax_t, intmax_t);
// optional, see below
}
#define
PRIdN see below
#define
PRIiN see below
#define
PRIoN see below
#define
PRIuN see below
#define
PRIxN see below
#define
PRIXN see below
#define
SCNdN see below
#define
SCNiN see below
#define
SCNoN see below
#define
SCNuN see below
#define
SCNxN see below
#define
PRIdLEASTN see below
#define
PRIiLEASTN see below
#define
PRIoLEASTN see below
#define
PRIuLEASTN see below
#define
PRIxLEASTN see below
#define
PRIXLEASTN see below
#define
SCNdLEASTN see below
#define
SCNiLEASTN see below
#define
SCNoLEASTN see below
#define
SCNuLEASTN see below
#define
SCNxLEASTN see below
#define
PRIdFASTN see below
#define
PRIiFASTN see below
#define
PRIoFASTN see below
#define
PRIuFASTN see below
#define
PRIxFASTN see below
#define
PRIXFASTN see below
#define
SCNdFASTN see below
#define
SCNiFASTN see below
#define
SCNoFASTN see below
#define
SCNuFASTN see below
#define
SCNxFASTN see below
#define
PRIdMAX see below
#define
PRIiMAX see below
#define
PRIoMAX see below
#define
PRIuMAX see below
#define
PRIxMAX see below
#define
PRIXMAX see below
#define
SCNdMAX see below
§
30.12.2
1156
#define SCNiMAX see below
#define SCNoMAX see below
#define SCNuMAX see below
#define SCNxMAX see below
#define PRIdPTR see below
#define PRIiPTR see below
#define PRIoPTR see below
#define PRIuPTR see below
#define PRIxPTR see below
#define PRIXPTR see below
#define SCNdPTR see below
#define SCNiPTR see below
#define SCNoPTR see below
#define SCNuPTR see below
#define SCNxPTR see below
1
The contents and meaning of the header <cinttypes> are the same as the C standard library header
<inttypes.h>, with the following changes:
(1.1)
—
The header <cinttypes> includes the header <cstdint> instead of <stdint.h>, and
(1.2)
—
if and only if the type intmax_t designates an extended integer type (6.7.1), the following function
signatures are added:
intmax_t abs(intmax_t);
imaxdiv_t div(intmax_t, intmax_t);
which shall have the same semantics as the function signatures intmax_t imaxabs(intmax_t) and
imaxdiv_t imaxdiv(intmax_t, intmax_t), respectively.
See also: ISO C 7.8
§ 30.12.2
1157
31
Regular expressions library
[re]
31.1
General
[re.general]
1
This Clause describes components that C++ programs may use to perform operations involving regular
expression matching and searching.
2
The following subclauses describe a basic regular expression class template and its traits that can handle
char-like (24.1) template arguments, two specializations of this class template that handle sequences of char
and wchar_t, a class template that holds the result of a regular expression match, a series of algorithms
that allow a character sequence to be operated upon by a regular expression, and two iterator types for
enumerating regular expression matches, as described in Table 128.
Table 128 — Regular expressions library summary
Subclause
Header(s)
31.2
Definitions
31.3
Requirements
31.5
Constants
31.6
Exception type
31.7
Traits
31.8
Regular expression template
<regex>
31.9
Submatches
31.10
Match results
31.11
Algorithms
31.12
Iterators
31.13
Grammar
31.2
Definitions
[re.def]
1
The following definitions shall apply to this Clause:
31.2.1
[defns.regex.collating.element]
collating element
a sequence of one or more characters within the current locale that collate as if they were a single character.
31.2.2
[defns.regex.finite.state.machine]
finite state machine
an unspecified data structure that is used to represent a regular expression, and which permits efficient
matches against the regular expression to be obtained.
31.2.3
[defns.regex.format.specifier]
format specifier
a sequence of one or more characters that is to be replaced with some part of a regular expression match.
31.2.4
[defns.regex.matched]
matched
a sequence of zero or more characters is matched by a regular expression when the characters in the sequence
correspond to a sequence of characters defined by the pattern.
31.2.5
[defns.regex.primary.equivalence.class]
primary equivalence class
a set of one or more characters which share the same primary sort key: that is the sort key weighting that
depends only upon character shape, and not accents, case, or locale specific tailorings.
§ 31.2.5
1158
31.2.6
[defns.regex.regular.expression]
regular expression
a pattern that selects specific strings from a set of character strings.
31.2.7
[defns.regex.subexpression]
sub-expression
a subset of a regular expression that has been marked by parenthesis.
31.3
Requirements
[re.req]
1
This subclause defines requirements on classes representing regular expression traits.
[Note: The class
template regex_traits, defined in 31.7, satisfies these requirements.
— end note ]
2
The class template basic_regex, defined in 31.8, needs a set of related types and functions to complete the
definition of its semantics. These types and functions are provided as a set of member typedef-names and
functions in the template parameter traits used by the basic_regex class template. This subclause defines
the semantics of these members.
3
To specialize class template basic_regex for a character container CharT and its related regular expression
traits class Traits, use basic_regex<CharT, Traits>.
4
In Table 129 X denotes a traits class defining types and functions for the character container type charT; u is
an object of type X; v is an object of type const X; p is a value of type const charT*; I1 and I2 are input
iterators (27.2.3); F1 and F2 are forward iterators (27.2.5); c is a value of type const charT; s is an object of
type X::string_type; cs is an object of type const X::string_type; b is a value of type bool; I is a value
of type int; cl is an object of type X::char_class_type, and loc is an object of type X::locale_type.
Table
129
— Regular expression traits class requirements
Expression
Return type
Assertion/note pre-/post-condition
X::char_type
charT
The character container type used in the
implementation of class template
basic_regex.
X::string_type
basic_-
string<charT>
X::locale_type
A copy
A type that represents the locale used by the
constructible type
traits class.
X::char_class_type
A bitmask
A bitmask type representing a particular
type (20.4.2.1.4).
character classification.
X::length(p)
size_t
Yields the smallest i such that p[i] == 0.
Complexity is linear in i .
v.translate(c)
X::char_type
Returns a character such that for any
character d that is to be considered equivalent
to c then v.translate(c) ==
v.translate(d).
v.translate_nocase(c)
X::char_type
For all characters C that are to be considered
equivalent to c when comparisons are to be
performed without regard to case, then
v.translate_nocase(c) ==
v.translate_nocase(C).
v.transform(F1, F2)
X::string_type
Returns a sort key for the character sequence
designated by the iterator range [F1, F2)
such that if the character sequence [G1, G2)
sorts before the character sequence [H1, H2)
then v.transform(G1, G2) <
v.transform(H1, H2).
§ 31.3
1159
Table 129 — Regular expression traits class requirements (contin-
ued)
Expression
Return type
Assertion/note pre-/post-condition
v.transform_primary(F1,
X::string_type
Returns a sort key for the character sequence
F2)
designated by the iterator range [F1, F2)
such that if the character sequence [G1, G2)
sorts before the character sequence [H1, H2)
when character case is not considered then
v.transform_primary(G1, G2) <
v.transform_primary(H1, H2).
v.lookup_collatename(F1,
X::string_type
Returns a sequence of characters that
F2)
represents the collating element consisting of
the character sequence designated by the
iterator range [F1, F2). Returns an empty
string if the character sequence is not a valid
collating element.
v.lookup_classname(F1,
X::char_class_-
Converts the character sequence designated by
F2, b)
type
the iterator range [F1, F2) into a value of a
bitmask type that can subsequently be passed
to isctype. Values returned from
lookup_classname can be bitwise or’ed
together; the resulting value represents
membership in either of the corresponding
character classes. If b is true, the returned
bitmask is suitable for matching characters
without regard to their case. Returns 0 if the
character sequence is not the name of a
character class recognized by X. The value
returned shall be independent of the case of
the characters in the sequence.
v.isctype(c, cl)
bool
Returns true if character c is a member of
one of the character classes designated by cl,
false otherwise.
v.value(c, I)
int
Returns the value represented by the digit c in
base I if the character c is a valid digit in base
I; otherwise returns -1. [Note: The value of I
will only be 8, 10, or 16.
— end note ]
u.imbue(loc)
X::locale_type
Imbues u with the locale loc and returns the
previous locale used by u if any.
v.getloc()
X::locale_type
Returns the current locale used by v, if any.
5
[ Note: Class template regex_traits satisfies the requirements for a regular expression traits class when it
is specialized for char or wchar_t. This class template is described in the header <regex>, and is described
in 31.7.
— end note ]
31.4
Header <regex> synopsis
[re.syn]
#include <initializer_list>
namespace std {
// 31.5, regex constants
namespace regex_constants {
using syntax_option_type = T1 ;
using match_flag_type = T2 ;
using error_type = T3 ;
}
// 31.6, class regex_error
class regex_error;
§ 31.4
1160
// 31.7, class template regex_traits
template<class charT> struct regex_traits;
// 31.8, class template basic_regex
template<class charT, class traits = regex_traits<charT>> class basic_regex;
using regex
= basic_regex<char>;
using wregex = basic_regex<wchar_t>;
// 31.8.6, basic_regex swap
template<class charT, class traits>
void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
// 31.9, class template sub_match
template<class BidirectionalIterator>
class sub_match;
using csub_match
= sub_match<const char*>;
using wcsub_match = sub_match<const wchar_t*>;
using ssub_match
= sub_match<string::const_iterator>;
using wssub_match = sub_match<wstring::const_iterator>;
// 31.9.2, sub_match non-member operators
template<class BiIter>
bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template<class BiIter>
bool operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template<class BiIter>
bool operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template<class BiIter>
bool operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template<class BiIter>
bool operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template<class BiIter>
bool operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template<class BiIter, class ST, class SA>
bool operator==(
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
template<class BiIter, class ST, class SA>
bool operator!=(
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
template<class BiIter, class ST, class SA>
bool operator<(
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
template<class BiIter, class ST, class SA>
bool operator>(
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
template<class BiIter, class ST, class SA>
bool operator>=(
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
template<class BiIter, class ST, class SA>
bool operator<=(
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
§ 31.4
1161
|
|