std::experi...::canonical(3)
π NAME π
From the C++ Standard Libary manual, bestie: std::experimental::filesystem::canonical β std::experimental::filesystem::canonical. The name is the name, and it's iconic. π
β¨ Synopsis β¨
Okay so this is the filesystem TS flavor, defined in the header:
Defined in header <experimental/filesystem>
path canonical( const path& p, const path& base = current_path() ); (1) (filesystem TS)
path canonical( const path& p, error_code& ec ); (2) (filesystem TS)
path canonical( const path& p, const path& base, error_code& ec ); (3) (filesystem TS)
π¦ Description π¦
Converts path p to a canonical absolute path, i.e. an absolute path that has no dot, dot-dot elements or symbolic links.
If p is not an absolute path, the function behaves as if it is first made absolute by absolute(p, base) or absolute(p) for (2).
The path p must exist. Like, actually exist. No fake paths, bestie. π«Ά
π Parameters π
pβ a path which may be absolute or relative tobase, and which must be an existing pathbaseβ base path to be used in casepis relativeecβ error code to store error status to
πΈ Return value πΈ
An absolute path that resolves to the same file as absolute(p, base) (or absolute(p) for (2)).
π₯ Exceptions π₯
The overload that does not take an 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 an 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.
This function is modeled after the POSIX realpath.
π Example π
// Run this code
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
fs::path p = fs::path("..") / ".." / "AppData";
std::cout << "Current path is " << fs::current_path() << '\n'
<< "Canonical path for " << p << " is " <<
fs::canonical(p) << '\n';
}
Possible output:
Current path is "C:\Users\abcdef\AppData\Local\Temp"
Canonical path for "..\..\AppData" is "C:\Users\abcdef\AppData"
π See also π
pathβ represents a path (class)absoluteβ composes an absolute pathsystem_completeβ converts a path to an absolute path replicating OS-specific behavior (function)
π·οΈ Categories π·οΈ
- Noindexed pages
- unconditionally noexcept
π Hidden categories π
- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template
Cute sign-off time π: source/version/date tea is http://cppreference.com Β· 2024.06.10 Β· std::experi...::canonical(3). That's the footer, bestie β periodt. π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms