Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is lexically_normal() redundant on a call to std::filesystem::canonical() or std::filesystem::weakly_canonical()?

Would there be a reason to call lexically_normal in either of these cases:

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

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

I'm seeing this in a code base and I am not sure if it is necessary. I am assuming that canonical and weakly canonical doesn't fail and returns a normalized path already.

Thanks

like image 983
michig54 Avatar asked Nov 18 '25 10:11

michig54


1 Answers

From the reference for weakly_canonical:

... The resulting path is in normal form.

So there is no point in calling lexically_normal on the return value of this function.

However, for canonical, the resulting path is not necessarily in normal form, and so it makes sense to call lexically_normal on the result.

like image 91
cigien Avatar answered Nov 21 '25 02:11

cigien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!