It is possible to append multiple paths in a row using the / operator:
std::filesystem::path p1{"A"};
auto p2 = p1 / "B" / "C";
which is rather convenient. However, concat only offers +=:
std::filesystem::path p1{"A"};
auto p2 = p1 / "B" / "C" + ".d"; // NOT OK
This is pretty annoying, as I can't easily add extensions to the end of my paths. I have no choice but to write something like
std::filesystem::path p1{"A"};
auto p2 = p1 / "B" / "C";
p2 += ".d";
Am I missing something? Is there a reason for this inconsistency?
const char[N], that would beauto p2 = p1 / "B" / (std::string("C") + ".d");("C" + ".d")adds twoconst char[2]s"A"+"B"auto p2 = p1 / "B" / "C" += ".d";orauto p2 = p1 / "B" / (std::string() + "C" + ".d");:D . Both of the these work in godbolt.note that in practice, "C" will most likelyNot in practice, in any case the result ofp1 / "B" / "C"has typestd::filesystem::path, so it's doing+=on it. Still, this is not an answer, as I do not know "the reason for this inconsistency".