知方号

知方号

std::filesystem::equivalent

std::filesystem::equivalent

 C++Compiler supportFreestanding and hostedLanguageStandard libraryStandard library headersNamed requirementsFeature test macros (C++20)Language support libraryConcepts library (C++20)Metaprogramming library (C++11)Diagnostics libraryGeneral utilities libraryStrings libraryContainers libraryIterators libraryRanges library (C++20)Algorithms libraryNumerics libraryLocalizations libraryInput/output libraryFilesystem library (C++17)Regular expressions library (C++11)Concurrency support library (C++11)Technical specificationsSymbols indexExternal libraries[edit] Filesystem libraryClassesfilesystem::pathfilesystem::filesystem_errorfilesystem::directory_entryfilesystem::directory_iteratorfilesystem::recursive_directory_iterator    filesystem::file_statusfilesystem::space_infofilesystem::file_typefilesystem::permsfilesystem::perm_optionsfilesystem::copy_optionsfilesystem::directory_optionsfilesystem::file_time_typeFunctionsfilesystem::absolutefilesystem::canonicalfilesystem::weakly_canonicalfilesystem::relativefilesystem::proximatefilesystem::copyfilesystem::copy_filefilesystem::copy_symlinkfilesystem::create_directoryfilesystem::create_directoriesfilesystem::create_hard_linkfilesystem::create_symlinkfilesystem::create_directory_symlinkfilesystem::current_pathfilesystem::existsfilesystem::equivalentfilesystem::file_sizefilesystem::hard_link_countfilesystem::last_write_timefilesystem::permissionsfilesystem::read_symlinkfilesystem::removefilesystem::remove_allfilesystem::renamefilesystem::resize_filefilesystem::spacefilesystem::statusfilesystem::symlink_statusfilesystem::temp_directory_pathFile typesfilesystem::is_block_filefilesystem::is_character_filefilesystem::is_directoryfilesystem::is_emptyfilesystem::status_knownfilesystem::is_fifofilesystem::is_otherfilesystem::is_regular_filefilesystem::is_socketfilesystem::is_symlink[edit]  Defined in header bool equivalent( const std::filesystem::path& p1,                 const std::filesystem::path& p2 ); (1) (since C++17) bool equivalent( const std::filesystem::path& p1,

                 const std::filesystem::path& p2,

                 std::error_code& ec ) noexcept; (2) (since C++17)

Checks whether the paths p1 and p2 resolve to the same file system entity.

If either p1 or p2 does not exist, an error is reported.

The non-throwing overload returns false on errors.

Contents1 Parameters2 Return value3 Exceptions4 Notes5 Example6 Defect reports7 See also[edit] Parameters p1, p2 - paths to check for equivalence ec - out-parameter for error reporting in the non-throwing overload[edit] Return value

true if the p1 and p2 refer to the same file or directory and their file status is the same. false otherwise.

[edit] Exceptions

Any overload not marked noexcept may throw std::bad_alloc if memory allocation fails.

1) Throws std::filesystem::filesystem_error on underlying OS API errors, constructed with p1 as the first path argument, p2 as the second path argument, and the OS error code as the error code argument.2) Sets a std::error_code& parameter to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur.[edit] Notes

Two paths are considered to resolve to the same file system entity if the two candidate entities the paths resolve to are located on the same device at the same location. For POSIX, this means that the st_dev and st_ino members of their POSIX stat structure, obtained as if by POSIX stat(), are equal.

In particular, all hard links for the same file or directory are equivalent, and a symlink and its target on the same file system are equivalent.

[edit] ExampleRun this code#include #include #include namespace fs = std::filesystem; int main(){ // hard link equivalency fs::path p1 = "."; fs::path p2 = fs::current_path(); if (fs::equivalent(p1, p2)) std::cout

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。