gulrak / filesystem

An implementation of C++17 std::filesystem for C++11 /C++14/C++17/C++20 on Windows, macOS, Linux and FreeBSD.
MIT License
1.34k stars 173 forks source link

Question: why no operator+? #92

Closed trapexit closed 3 years ago

trapexit commented 3 years ago

I know it's not in the standard but wondering if anyone knew why there exists operator/= and operator+= and operator/ but not operator+?

gulrak commented 3 years ago

First of all: I don't really know.

I thought of it as historically derived from boost: Boost started with only operator/= and operator/ and they argued originally that they didn't want to use operator+= and operator+ for the path appends as it would be easily confused with those operators from std::string doing something different. Concatenation was only introduced later (around boost 1.50 I think) with concat() and operator+=, as a way to add something like an extension to a path and my guess is they didn't want to add operator+ to avoid new users start using that for work operator/ was made to do. Later when std::experimental::filesystem and after that std::filesystem where developed, as kind-of evolutionary steps from boost, I guess they followed boost in that tradition. When implementing my version of thestd::filesystem` interface, I read quite some of the papers, but I can't remember seeing explicit reasoning about this in there. So in the end I can only speculate.

Still, as you already mentioned, it is not part of C++17 or C++20, so currently I follow the lead and also have no operator+ in ghc::filesystem::path as I want to keep surprises small for developers switching between std::filesystem and my implementation depending on compiler or platform.

trapexit commented 3 years ago

Thanks for the details. I'd just run into a number of instances where operator+ would have been useful figured I'd ask. Thanks.