A quote from Programming Languages — C++ — File System Technical Specification draft N4100:
8.4.8 pathcompare [path.compare]
1 int compare(const path& p) const noexcept;
2 Returns: A value less than 0 if native() for the elements of *this are lexicographically less than native() for the elements of p, otherwise a value greater than 0 if native()for the elements of *this are lexicographically greater than native() for the elements of p, otherwise 0.
Why the file path comparison is defined as case-sensitive if there are file systems that are case-insensitive (NTFS, etc)? Shouldn't comparison be done according to specific file system rules?
You have additionally equivalent()
function specified in 15.13, which checks if two paths resolve to the same file.
bool equivalent(const path& p1, const path& p2)
- Returns:
true
, ifs1 == s2
andp1
andp2
resolve to the same file system entity, elsefalse
. The signature with argumentec
returnsfalse
if an error occurs.
compare()
function will use iterators and path::operator==
to compare elements. In 8.6.13 you have written:
bool operator==(const path& lhs, const path& rhs) noexcept;
Equivalence is determined by the equivalent() non-member function, which determines if two paths resolve to the same file system entity. Thus equivalent("foo", "bar") will be true when both paths resolve to the same file
Programmers wishing to determine if two paths are "the same" must decide if "the same" means "the same representation" or "resolve to the same actual file", and choose the appropriate function accordingly
So, equivalent()
comparison is done according to system specific rules, while compare()
checks if you have used "the same representation" to describe path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With