c++ - 在对std::filesystem::canonical()或std::filesystem::weakly_canonical()的调用上,lexically_normal()是否冗余?

标签 c++ c++17 std-filesystem

在以下两种情况下,是否有理由调用lexically_normal:

std::filesystem::path filepath = someFuntionThatGetsAPath();

filepath = std::filesystem::canonical (filepath).lexically_normal ();
filepath = std::filesystem::weakly_canonical (filepath).lexically_normal ();

我在代码库中看到了这一点,但不确定是否有必要。我假设规范和弱规范不会失败,并且已经返回规范化路径。
谢谢

最佳答案

weakly_canonical的引用中:

... The resulting path is in normal form.


因此,在此函数的返回值上调用lexically_normal是没有意义的。
但是,对于canonical,结果路径不一定是正常形式,因此在结果上调用lexically_normal是有意义的。

关于c++ - 在对std::filesystem::canonical()或std::filesystem::weakly_canonical()的调用上,lexically_normal()是否冗余?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64063869/

相关文章:

c++ - 从大括号 std::string 构造 std::string_view,clang 和 gcc 不同意 -Wconversion

c++ - std::experimental::filesystem::recursive_directory_iterator 跳过文件夹及其子文件夹

c++ - 具有基类参数的派生类的拷贝构造函数的排序

c++ - 如何通过cstdlib系统传递带空格的参数

c++ - Visual C++ 中的去虚拟化

c++ - C++17 std::filesystem::path 中的 native 路径分隔符错误?

c++ - fclose() 函数慢

c++ - 为了什么目的可能需要来自 Boost 库的同步原语和容器?

c++ - 统一调用语法的 C++17 提案打算如何处理 namespace ?