std::experi...::path::path(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… NAME πŸ’…

okay so bestie, you're looking at std::experi...::path::path(3) from the C++ Standard Libary β€” yes, that's the manual name, typo and all, we're keeping it πŸ’–. The page name is std::experimental::filesystem::path::path, and the NAME says it's literally std::experimental::filesystem::path::path β€” std::experimental::filesystem::path::path. Iconic redundancy, no notes.


✨ Synopsis ✨

Constructs a new path object. Here are the overloads, exactly as they are, bestie:

path();                                                      (1)
(filesystem TS)
path( const path& p );                                       (2)
(filesystem TS)
path( path&& p );                                            (3)
(filesystem TS)
template< class Source >                                     (4)
(filesystem TS)
path( const Source& source );
template< class InputIt >                                    (5)
(filesystem TS)
path( InputIt first, InputIt last );
template< class Source >                                     (6)
(filesystem TS)
path( const Source& source, const std::locale& loc );
template< class InputIt >                                    (7)
(filesystem TS)
path( InputIt first, InputIt last, const std::locale& loc );

Constructs a new path object. (Said it twice because it's important πŸ’….)

  • 1) Constructs an empty path. Empty. Blank. A little path baby with nothing in it πŸŽ€.
  • 2) Copy constructor. Constructs a copy of p.
  • 3) Move constructor. Constructs a copy of p, p is left in valid but unspecified state. (Not me leaving things in valid but unspecified state 😭.)
  • 4,5) Constructs the path from a character sequence provided by source (4), which is a pointer or an input iterator to a null-terminated character/wide character sequence or an std::basic_string, or represented as a pair of input iterators [first, last) (5). Any of the four character types char, char16_t, char32_t, wchar_t is allowed, and the method of conversion to the native character set depends on the character type used by source.
    • If the source character type is char, the encoding of the source is assumed to be the native narrow encoding (so no conversion takes place on POSIX systems).
    • If the source character type is char16_t, conversion from UTF-16 to native filesystem encoding is used.
    • If the source character type is char32_t, conversion from UTF-32 to native filesystem encoding is used.
    • If the source character type is wchar_t, the input is assumed to be the native wide encoding (so no conversion takes places on Windows).
  • 6,7) Constructs the path from a character sequence provided by source (6), which is a pointer or an input iterator to a null-terminated character sequence or an std::string, or represented as a pair of input iterators [first, last) (7). The only character type allowed is char. Uses loc to perform the character encoding conversion. If value_type is wchar_t, converts from to wide using the std::codecvt<wchar_t, char, std::mbstate_t> facet of loc. Otherwise, first converts to wide using the std::codecvt<wchar_t, char, std::mbstate_t> facet and then converts to filesystem native character type using std::codecvt<wchar_t, value_type> facet of loc.

πŸŽ€ Parameters πŸŽ€

  • p β€” a path to copy.
  • source β€” a std::basic_string, pointer to a null-terminated character string, or an input iterator with a character value type that points to a null-terminated character sequence (the character type must be char for overload (6)).
  • first, last β€” pair of LegacyInputIterators that specify a UTF-8 encoded character sequence.
  • loc β€” locale that defines encoding conversion to use.

🌸 Type requirements 🌸

  • InputIt must meet the requirements of LegacyInputIterator.
  • The value type of InputIt must be one of the four character types char, wchar_t, char16_t and char32_t to use the overload (5).
  • The value type of InputIt must be char to use the overload (7).

πŸ’€ Exceptions πŸ’€

  • 1,2) (none)
  • 3) noexcept specification: noexcept
  • 4-7) (none)

πŸ¦‹ Notes πŸ¦‹

For portable pathname generation from Unicode strings, see u8path.

πŸ“ Example πŸ“

// Run this code

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;

int main()
{
    fs::path p1 = "/usr/lib/sendmail.cf"; // portable format
    fs::path p2 = "C:\\users\\abcdef\\AppData\\Local\\Temp\\"; // native format
    fs::path p3 = L"D:/猫.txt"; // wide string

    std::cout << "p1 = " << p1 << '\n'
              << "p2 = " << p2 << '\n'
              << "p3 = " << p3 << '\n';
}

Output:

p1 = "/usr/lib/sendmail.cf"
p2 = "C:\users\abcdef\AppData\Local\Temp\"
p3 = "D:/猫.txt"

πŸ‘‘ See also πŸ‘‘

  • u8path creates a path from a UTF-8 encoded source (function).

🌈 Categories 🌈

  • Noindexed pages
  • unconditionally noexcept

πŸ™ˆ Hidden categories πŸ™ˆ

  • Pages with unreviewed unconditional noexcept template
  • Pages with unreviewed noexcept template

source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::experi...::path::path(3) β€” k bye bestie, drink water and don't leave your path in a valid but unspecified state πŸ’œπŸ«Ά

πŸ“¦ where this page comes from