Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between c++14 std::experimental::filesystem::v1 and c++17 std::filesystem?

Tags:

c++

c++17

c++14

I found this page, describing the changes between c++14 and c++17:

https://isocpp.org/files/papers/p0636r0.html

... It links to this page, which describes the proposed filesystem changes:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0218r0.html

I skimmed through it. There are small wording changes to the standard, but the only code change I saw were namespace changes that removed the "experimental" and "v1" parts, so "std::experimental::filesystem::v1" became "std::filesystem", which is expected.

From what I can tell, nothing other than the namespace path changed. Does anyone know if anything else changed?

In other words, I'm using gcc with -std=c++14. Can I write code now with std::experimental::filesystem and comfortably switch to -std=c++17 in the future with only this namespace change?

Closest questions I can find to being duplicates:

How similar are Boost filesystem and the standard C++ filesystem libraries?

Are the experimental features of modern C++ reliable for long-term projects?

like image 338
user79878 Avatar asked Jan 19 '18 18:01

user79878


People also ask

What is filesystem in c++?

Most modern file systems keep the files organized in a tree-like (or hierarchical) form. One or more root nodes are located at the tree's top. The filesystem is a library in C++17 standard which enables us to work with the file path, directories, status, and errors of the files in a hierarchical filesystem.

What is Boost filesystem?

The Boost Filesystem Library provides portable facilities to query and manipulate paths, files, and directories. The motivation for the library is the need to be able to perform portable script-like operations from within C++ programs.

What is a file system library?

The Filesystem library provides facilities for performing operations on file systems and their components, such as paths, regular files, and directories. The filesystem library was originally developed as boost.


1 Answers

The major papers making changes to the filesystem library are

  • P0219R1, adding relative paths support
  • P0317R1, adding caching to directory_entry
  • P0492R2, a lengthy list of fixes and changes in response to national body comments
  • P0430R2, support for certain non-POSIX systems

There are also some relatively minor fixes and changes that can be found in the LWG issue list. Look for issues with "C++17" status. Note that some of these changes are then superseded by the papers listed above.


For existing Filesystem TS code, I expect that P0492R2 is the one that matters the most, since the remaining papers are mostly feature additions rather than changes. P0492R2 includes both technical clarifications and significant semantic changes. Some in the latter category that immediately come to mind are:

  • path(".profile").stem() is now ".profile"
  • operator/ on path had its semantics changed significantly if the rhs is an absolute path or has a root-name. path("/foo") / "/bar" is now "/bar" rather than "/foo/bar"; path("C:\\x") / "D:y" on Windows is now "D:y".
  • The old absolute is gone. system_complete has been renamed absolute.
  • permissions's signature got a minor change.
like image 198
T.C. Avatar answered Sep 29 '22 14:09

T.C.