C++ Logo

std-discussion

Advanced search

Re: fs::path appenders have inconsistent behavior for UNC paths between OSes

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Fri, 5 Nov 2021 12:42:36 +0300
On 11/5/21 06:58, Thiago Macieira via Std-Discussion wrote:
> On Thursday, 4 November 2021 18:58:57 PDT Andrey Semashev via Std-Discussion
> wrote:
>> That's not a rationale, it's a consequence of the specification. I'm
>> interested in the motivation for the specification being written this
>> way (if it was written so intentionally, with respect to the case I
>> described).
>
> It seems that operator/ is implemented like the "cd" command, not a string
> concatenation.
>
> Think of this:
> $ cd /usr
> $ cd /bin
> $ pwd
> /bin
>
> You don't expect it to show /usr/bin (whether /bin is a symlink to /usr/bin or
> not is irrelevant here).
>
> I agree with you it's surprising at first sight because
>
> "//net/foo" + "/bar"
>
> makes it a subdir of //net/foo.
>
> But it's not meant to be like string concatenation.

The operator is called "append operation", so to me it is very much
intended as a concatenation. I do not see where the spec suggests it
should behave as filesystem navigation.

> The only prior art of operator/ that I know of is in the Meson buildsystem and
> it behaves exactly like fs::path. See
> https://mesonbuild.com/Syntax.html#string-path-building

std::filesystem was modeled after Boost.Filesystem, where operator/=
acted as a simple concatenation with insertion of a directory separator.
To the point it didn't even consider root names or root directories.

Received on 2021-11-05 04:42:42