##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::filesystem::relative, std::filesystem::proximate

From cppreference.com
< cpp‎ | filesystem

Defined in header `<filesystem>` |  |
path relative( const std::filesystem::path& p, std::error_code& ec); | (1) | (since C++17)
path relative( const std::filesystem::path& p, const std::filesystem::path& base = std::filesystem::current_path()); path relative( const std::filesystem::path& p, const std::filesystem::path& base, std::error_code& ec); | (2) | (since C++17)
path proximate( const std::filesystem::path& p, std::error_code& ec); | (3) | (since C++17)
path proximate( const std::filesystem::path& p, const std::filesystem::path& base = std::filesystem::current_path()); path proximate( const std::filesystem::path& p, const std::filesystem::path& base, std::error_code& ec); | (4) | (since C++17)

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 weakly_canonical(p).lexically_relative(weakly_canonical(base)) or weakly_canonical(p, ec).lexically_relative(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 weakly_canonical(p).lexically_proximate(weakly_canonical(base)) or weakly_canonical(p, ec).lexically_proximate(weakly_canonical(base, ec)), except the error code form returns path() at the first error occurrence, if any.

### [edit] Parameters

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

### [edit] Return value

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

### [edit] Exceptions

The overload that does not take a std::error_code& parameter throws filesystem_error on underlying OS API errors, constructed with `p` as the first argument, `base` as the second argument, and the OS error code as the error code argument. std::bad_alloc may be thrown if memory allocation fails. 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. This overload has
`noexcept` specification:
noexcept

### [edit] Example

| This section is incomplete Reason: no example

### [edit] See also

path (C++17) | represents a path (class) [edit]
absolute system_complete (C++17)(C++17) | composes an absolute path converts a path to an absolute path replicating OS-specific behavior (function) [edit]
canonical weakly_canonical (C++17) | composes a canonical path (function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/filesystem/relative&oldid=86334"
Categories:

- unconditionally noexcept
- Todo no example

Hidden categories:

- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template