问题描述
在以下两种情况下,是否有理由调用lexically_normal:
std::filesystem::path filepath = someFuntionThatGetsAPath();
filepath = std::filesystem::canonical (filepath).lexically_normal ();
filepath = std::filesystem::weakly_canonical (filepath).lexically_normal ();
我在代码库中看到了这个,并且不确定是否有必要。我假设规范的和弱规范的不会失败,并且已经返回规范化的路径。
谢谢
解决方法
摘自weakly_canonical的参考:
...结果路径为正常形式。
因此,在此函数的返回值上调用lexically_normal
毫无意义。
但是,对于canonical
,结果路径不一定是正常形式,因此在结果上调用lexically_normal
很有意义。