std::filesystem::path::compare
: cppreference.com
<tbody>
</tbody>
int compare( const path& p ) const noexcept; |
(1) | (C++17) |
int compare( const string_type& str ) const; int compare( std::basic_string_view<value_type> str ) const; |
(2) | (C++17) |
int compare( const value_type* s ) const; |
(3) | (C++17) |
1)
root_name().native().compare(p.root_name().native()) 2)
compare(path(str)) 3)
compare(path(s)) | p | - | |
| str | - | |
| s | - |
0
0
0
2-3) ()
Run this code
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
void demo(int rc, fs::path p1, fs::path p2) {
if(rc < 0) std::cout << p1 << " < " << p2 << '\n';
else if(rc > 0) std::cout << p1 << " > " << p2 << '\n';
else if(rc == 0) std::cout << p1 << "==" << p2 << '\n';
}
int main() {
fs::path p1 = "/a/b/"; // as if "a/b/." for lexicographical iteration
fs::path p2 = "/a/b/#";
demo(p1.compare(p2), p1, p2);
demo(p1.compare("a/b/_"), p1, "a/b/_");
}
:
"/a/b/" > "/a/b/#"
"/a/b/" < "a/b/_"
C++
| DR | |||
|---|---|---|---|
| LWG 2936 | C++17 | compared all path elements directly | root name and root directory handled separately |
(C++20)(C++20)(C++20)(C++20)(C++20)(C++20) |
2 () |