std::filesy...path::assign(3)

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

🌸 std::filesystem::path::assign β€” a C++ Standard Library moment 🌸

okay bestie, welcome to the C++ Standard Library glow-up zone ✨ this one's all about std::filesystem::path::assign β€” yes, that's the whole NAME section, it's giving "the function is literally named after itself" and honestly? iconic.


✨ SYNOPSIS ✨

path& assign( string_type&& source );        (1) (since C++17)
template< class Source >                     (2) (since C++17)
path& assign( const Source& source );
template< class InputIt >                    (3) (since C++17)
path& assign( InputIt first, InputIt last );

So the vibe here is: it replaces the contents to the path object with a brand-new pathname, constructed from the character sequence you hand it. Like a whole makeover for your path object πŸ’…

  1. Assigns the pathname identified by the detected-format string source, which is left in a valid, but unspecified state. (yes bestie, valid but unspecified β€” it's alive, it's just not gonna tell you what it's wearing anymore πŸ™ˆ)
  2. Assigns the pathname identified by the detected-format character range source.
  3. Assigns the pathname identified by detected-format character range [first, last).

Now the fine print for (2), and this is the part where you gotta pay attention 🫢 β€” (2) participates in overload resolution only if Source and path are not the same type, and either:

  • Source is a specialization of std::basic_string or std::basic_string_view, or
  • std::iterator_traits<std::decay_t<Source>>::value_type is valid and denotes a possibly const-qualified encoding character type (char, char8_t, (since C++20)char16_t, char32_t, or wchar_t).

πŸŽ€ PARAMETERS πŸŽ€

  • source β€” a character range to use, represented as std::string, std::string_view, pointer to a null-terminated multibyte string, or as an input iterator with char value type that points to a null-terminated multibyte string. so many outfits, one parameter πŸ’–
  • first, last β€” a character range to use.

πŸ¦‹ TYPE REQUIREMENTS πŸ¦‹

  • InputIt must meet the requirements of LegacyInputIterator. no cutting corners, she has standards ✨
  • The value type of InputIt must be one of the encoded character types (char, wchar_t, char16_t and char32_t).

⭐ RETURN VALUE ⭐

*this β€” that's it, that's the whole section, she returns herself. main character energy fr fr πŸ‘‘


πŸ’€ DEFECT REPORTS πŸ’€

The following behavior-changing defect reports were applied retroactively to previously published C++ standards. (retroactive glow-ups, we love to see it 🌈)

  • LWG 3244 β€” applied to C++17. Behavior as published: the constraint that Source cannot be path was missing. Correct behavior: added. not the constraint being missing 😭 glad they fixed it bestie.

πŸ‘‘ SEE ALSO πŸ‘‘

  • operator= β€” assigns another path (public member function). the sister function, also slaying πŸ’…

quick vibe check: the whole point of assign is replacing what's inside the path object β€” if you were emotionally attached to the old contents, sorry babe, they're gone 🫢

that's the page!! brought to you by http://cppreference.com, dated 2024.06.10, and the manual name is C++ Standard Libary (yes, that's how it's spelled in the header, we're keeping it character for character, no cap) πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from