[ Web Proxy ]
URL:
Viewing: http://ja.cppreference.com/cpp/filesystem/path/compare [Back]  [Original]

std::filesystem::path::compare - cppreference.com
cppreference.com

std::filesystem::path::compare

: cppreference.com
 
C++
(C++20)
(C++20)
(C++17)
(C++11)
(C++11)
(C++11)
 
 
 
<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())
has_root_directory() != p.has_root_directory() has_root_directory() false
(relative_path()) p (p.relative_path()) 0 begin() end() native()
2) compare(path(str))
3) compare(path(s))

p -
str -
s -

0

0

0

2-3) ()

#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

2
() [edit]

Web Proxy Viewer  |  New URL  |  Original Page