3

boost::filesystem::path uses & to escape quotes in path string, see demo:

std::cout << boost::filesystem::path("/R&D/Project \"boost\"") << std::endl;

Prints "/R&&D/Project &"boost&"". However, for std::filesystem::path I see this:

Performs stream input or output on the path p. std::quoted is used so that spaces are not truncation when later read by stream input operator.

Here is from std::quoted:

escape - the character to use as the escape character, defaults to \

From this I can tell that std::filesystem::path will use \ instead of &.

Is this correct? If yes, why the committee decided to change this behavior?

Bonus question: are there any implementations of std::filesystem::path available? Seems like none of latest GCC and clang provide <filesystem> header.

Mikhail
  • 20,685
  • 7
  • 70
  • 146

2 Answers2

2

Boost::Filesystem is fairly old, and predates C++14's quoted. It's entirely reasonable for the standard to be internally consistent. Following Boost is only a secondary concern.

MSalters
  • 173,980
  • 10
  • 155
  • 350
1

If yes, why the committee decided to change this behavior?

From N3399, emphasized is mine:

The Boost inserter outputs quoted strings, which are recognized as such by the extractor. There is a sentiment within the Filesystem Study Group that supplying a quoted and/or escaped string manipulator as a string extension would be a better solution than a path specific feature. See proposal N3431, Quoted Strings Library Proposal.

That said, the filesystem study group think it's better to use quoted string manipulator than a specific feature for path

Bonus question: are there any implementations of std::filesystem::path available? Seems like none of latest GCC and clang provide header.

AFAIK, major compilers like g++, clang, msvc both provides filesystem as an experimental feature with <experimental/filesystem> in namespace std::experimental::filesystem. gcc has it from version 5.3 as you can see here, MSVC has it from VS2012 (it's <filesystem> in VS2012 and VS2013, then move to <experimental/filesystem> and <filesystem> in VS2015)

Community
  • 1
  • 1
Danh
  • 5,916
  • 7
  • 30
  • 45
  • Great, thanks for the quote! As for experimental, I tried it in online compilers with no success: http://melpon.org/wandbox/permlink/nfZ88PnrttOGbEHu Maybe its just a problem in online compiler. – Mikhail Nov 22 '16 at 19:08
  • 1
    @Mikhail As Jonathan had mentioned in [this answer](http://stackoverflow.com/a/33159746/4115625), you must link it with `-lstdc++fs` See [this](http://melpon.org/wandbox/permlink/75pJtT4K3dAgGT1i) – Danh Nov 23 '16 at 06:02