Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How similar are Boost.Filesystem and the C++ standard filesystem library?

I need a filesystem library for use with a C++11-capable compiler or a C++14-capable one - so it can't be be from C++17.

Now, I know that the filesystem library going into C++17 is based based on Boost::Filesystem; but - are they similar enough for me to use the Boost library and then seamlessly switch to the standard version at a later time, without changing more than, say, a using statement? Or are there (minor/significant) differences between the two? I know that for the case of variant, the Boost and the standard library versions differ quite a bit.

like image 849
einpoklum Avatar asked Nov 30 '16 22:11

einpoklum


People also ask

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.

Which of the following boost library can helps to handling files directories & paths from a CPP program?

The Boost. Filesystem library provides facilities to manipulate files and directories, and the paths that identify them. The features of the library include: A modern C++ interface, highly compatible with the C++ standard library.

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.


1 Answers

There are a number of differences. Some were, I believe, Boost changes that were never propagated. For example, there is no path.filename_is_dot() query (as discussed below, it would be less useful in std::filesystem anyway).

There was also a good bit of late-breaking news on this front:

  1. Support for non-POSIX-like filesystems:
    • Specify whether a string is OS-native or POSIX-like (or let the implementation decide, which is (still) the default)
    • An implementation may define additional file types (beyond regular, directory, socket, etc.)
    • An implementation may define file_size for a directory or device file
  2. filename(), normalization, and relative/absolute conversions redefined (examples for POSIX):
    • path("foo/.").lexically_normal()=="foo/" (is the opposite in Boost)
    • path("foo/").filename()=="" (is path(".") in Boost)
    • remove_filename() leaves the trailing slash and is thus idempotent (it assigns parent_path() in Boost)
    • path(".profile").extension()=="" (is the whole name in Boost)
    • path decompositions and combinations can preserve things like alternate data stream names that are normally invisible
    • path("foo")/"/bar"=="/bar" (is path("foo/bar") in Boost), which allows composing relative file names with others (absolute or relative) and replaces Boost's absolute()
    • Boost's system_complete() (which takes only one argument) is renamed to absolute()
    • canonical() thus takes only one argument (fixed in a DR)
    • lexically_relative() handles .. and root elements correctly
    • permissions() takes more arguments (Boost combines them into a bitmask)

Note that Boost.Filesystem v4 is under development and is supposed to be C++17-compatible (but therefore incompatible in many respects with v3).

like image 196
Davis Herring Avatar answered Sep 22 '22 11:09

Davis Herring