为什么BOOST :: fileSystem :: path and std :: filesystem ::路径含量含
Why do boost::filesystem::path and std::filesystem::path lack operator+?
考虑有关路径分解的以下断言,其中每个局部变量例如stem
具有明显的初始化,例如auto stem = path.stem()
-
assert(root_path == root_name / root_directory);
assert(path == root_name / root_directory / relative_path);
assert(path == root_path / relative_path);
assert(path == parent_path / filename);
assert(filename == stem + extension);
这一切都起作用,除了最后一行 - 因为fs::path
没有定义operator+
。它具有operator+=
,但没有operator+
。
这里的故事是什么?
我已经确定可以通过添加自己的operator+
来编译此代码。有什么理由不这样做吗?(请注意,这是在我自己的名称空间中;我不是重新打开namespace std
。)
fs::path operator+(fs::path a, const fs::path& b)
{
a += b;
return a;
}
我对该主题的唯一假设是:
也许设计师担心
operator+
与std::string
的operator+
相混淆。但这似乎很愚蠢,因为它在语义上完全做得完全相同(那么为什么要关心它是否混淆?)。而且似乎设计师在设计path.append("x")
时不在乎Newbies的混乱,从而在语义上与str.append("x")
和path.concat("x")
进行语义不同的来做一些与str.append("x")
相同的相同的事情。也许
path
的隐式转换operator string_type() const
会导致某些p + q
变得模棱两可。但是我一直无法提出任何这样的情况。
这是针对文件系统库的缺陷,并且由于接口的复杂性以及通过转换为字符串和返回路径而解决的能力,因此被认为不是一个缺点。在此处阅读所有内容:https://timsong-cpp.github.io/lwg-issues/2668
相关文章:
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- 在带有尾部斜杠的路径上返回 std::filesystem::create_directories() 的值
- std::filesystem 和 std::experimental::filesystem 之间的路径差异
- 从std :: fileSystem ::路径对象的类中退出时的分割故障
- 如何从std :: filesystem ::路径中删除引号
- Boost Filesystem flowly_caronical不会在没有父文件夹的情况下解决相对路径
- 如何处理boost :: fileSystem ::路径的空间
- 如果P从root路径开始,为什么STD :: filesystem :: path :: append替换当前路径
- 如何使用 boost::filesystem 检查路径是否是可创建的文件
- 为什么BOOST :: fileSystem :: path and std :: filesystem ::路径含量含
- 为什么 boost::filesystem::p ath 和 std::filesystem::p ath 的路径转义字
- 如何删除"..使用 Visual Studio 2012 类的文件路径中的 /' 令牌<filesystem>?
- 使用 boost::filesystem::p ath 获取绝对路径
- Boost filesystem::路径构造器std::length_error
- 如何将带有 ".."(向上)组件的 boost::filesystem::p ath 转换为正确的路径
- 如何使用Boost.Filesystem检查两个路径是否指向同一个文件/目录
- 查询boost::filesystem::路径长度
- 将filesystem::path元素附加到另一个路径的最佳方法是什么?
- 如何使用Boost Filesystem Library v3确定文件是否按路径包含
- 为什么boost::filesystem::canonical()要求目标路径存在?