GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::filesystem::relative,std::filesystem::proximate(3) C++ Standard Libary std::filesystem::relative,std::filesystem::proximate(3)

std::filesystem::relative,std::filesystem::proximate - std::filesystem::relative,std::filesystem::proximate


Defined in header <filesystem>
path relative( const std::filesystem::path& p, (1) (since C++17)
std::error_code& ec );
path relative( const std::filesystem::path& p,


const std::filesystem::path& base =
std::filesystem::current_path()); (2) (since C++17)
path relative( const std::filesystem::path& p,
const std::filesystem::path& base,


std::error_code& ec );
path proximate( const std::filesystem::path& p, (3) (since C++17)
std::error_code& ec );
path proximate( const std::filesystem::path& p,


const std::filesystem::path& base =
std::filesystem::current_path()); (4) (since C++17)
path proximate( const std::filesystem::path& p,
const std::filesystem::path& base,


std::error_code& ec );


1) Returns relative(p, current_path(), ec)
2) Returns p made relative to base. Resolves symlinks and normalizes both p and base
before other processing. Effectively returns
std::filesystem::weakly_canonical(p).lexically_relative(std::filesystem::weakly_canonical(base))
or std::filesystem::weakly_canonical(p,
ec).lexically_relative(std::filesystem::weakly_canonical(base, ec)), except the
error code form returns path() at the first error occurrence, if any.
3) Returns proximate(p, current_path(), ec)
4) Effectively returns
std::filesystem::weakly_canonical(p).lexically_proximate(std::filesystem::weakly_canonical(base))
or std::filesystem::weakly_canonical(p,
ec).lexically_proximate(std::filesystem::weakly_canonical(base, ec)), except the
error code form returns path() at the first error occurrence, if any.


p - an existing path
base - base path, against which p will be made relative/proximate
ec - error code to store error status to


1) p made relative against base.
2) p made proximate against base


The overload that does not take a std::error_code& parameter throws
filesystem::filesystem_error on underlying OS API errors, constructed with p as the
first path argument, base as the second path argument, and the OS error code as the
error code argument. The overload taking a std::error_code& parameter sets it to the
OS API error code if an OS API call fails, and executes ec.clear() if no errors
occur. Any overload not marked noexcept may throw std::bad_alloc if memory
allocation fails.

// Run this code


#include <iostream>
#include <filesystem>


void show(std::filesystem::path x, std::filesystem::path y)
{
std::cout << "x:\t\t " << x << "\ny:\t\t " << y << '\n'
<< "relative(x, y): "
<< std::filesystem::relative(x, y) << '\n'
<< "proximate(x, y): "
<< std::filesystem::proximate(x, y) << "\n\n";
}


int main()
{
show("/a/b/c", "/a/b");
show("/a/c", "/a/b");
show("c", "/a/b");
show("/a/b", "c");
}


x: "/a/b/c"
y: "/a/b"
relative(x, y): "c"
proximate(x, y): "c"


x: "/a/c"
y: "/a/b"
relative(x, y): "../c"
proximate(x, y): "../c"


x: "c"
y: "/a/b"
relative(x, y): ""
proximate(x, y): "c"


x: "/a/b"
y: "c"
relative(x, y): ""
proximate(x, y): "/a/b"


path represents a path
(C++17) (class)
absolute composes an absolute path
(C++17) (function)
canonical composes a canonical path
weakly_canonical (function)
(C++17)
lexically_normal converts path to normal form
lexically_relative converts path to relative form
lexically_proximate converts path to proximate form
(public member function of std::filesystem::path)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.