std::filesy...path::assign(3)
πΈ 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 π
- 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 π) - Assigns the pathname identified by the detected-format character range
source. - 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:
Sourceis a specialization ofstd::basic_stringorstd::basic_string_view, orstd::iterator_traits<std::decay_t<Source>>::value_typeis valid and denotes a possibly const-qualified encoding character type (char,char8_t, (since C++20)char16_t,char32_t, orwchar_t).
π PARAMETERS π
sourceβ a character range to use, represented asstd::string,std::string_view, pointer to a null-terminated multibyte string, or as an input iterator withcharvalue type that points to a null-terminated multibyte string. so many outfits, one parameter πfirst,lastβ a character range to use.
π¦ TYPE REQUIREMENTS π¦
InputItmust meet the requirements of LegacyInputIterator. no cutting corners, she has standards β¨- The value type of
InputItmust be one of the encoded character types (char,wchar_t,char16_tandchar32_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 thatSourcecannot bepathwas 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
- 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