std::filesy...::operator+=(3)
πΈ NAME πΈ
okay so this is the C++ Standard Libary manual page for std::filesystem::path::concat,std::filesystem::path::operator+= β filed under std::filesy...::operator+=(3). Two names, one concatenation situation. Periodt. π
β¨ Synopsis β¨
Concatenates the current path and the argument π
path& operator+=( const path& p ); (1)
(since C++17)
path& operator+=( const string_type& str ); (2)
(since C++17)
path& operator+=( std::basic_string_view<value_type> str );
path& operator+=( const value_type* ptr ); (3)
(since C++17)
path& operator+=( value_type x ); (4)
(since C++17)
template< class CharT > (5)
(since C++17)
path& operator+=( CharT x );
template< class Source > (6)
(since C++17)
path& operator+=( const Source& source );
template< class Source > (7)
(since C++17)
path& concat( const Source& source );
template< class InputIt > (8)
(since C++17)
path& concat( InputIt first, InputIt last );
Hereβs the overload tea, bestie:
1-3,6,7)β Appendspath(p).native()to the pathname stored in*thisin the native format. This directly manipulates the value ofnative()and may not be portable between operating systems.4,5)β Same asreturn *this += std::basic_string_view(&x, 1);.8)β Same asreturn *this += path(first, last);.
(6) and (7) participate 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 π
pβ path to append.strβ string or string view to append.ptrβ pointer to the beginning of a null-terminated string to append.xβ single character to append.sourceβstd::basic_string,std::basic_string_view, null-terminated multicharacter string, or an input iterator pointing to a null-terminated multicharacter sequence, which represents a path name (either in portable or in native format).first,lastβ pair ofLegacyInputIteratorsthat specify a multicharacter sequence that represents a path name.
π§ Type requirements π§
InputItmust meet the requirements ofLegacyInputIterator.- The value type of
InputItmust be one of the encoded character types (char,wchar_t,char16_tandchar32_t). CharTmust be one of the encoded character types (char,wchar_t,char16_tandchar32_t).
π Return value π
*this β yep, it returns the same object, bestie. π
π₯ Exceptions π₯
May throw std::bad_alloc if memory allocation fails.
π¦ Notes π¦
Unlike with append() or operator/=, additional directory separators are never introduced. Never. Not even one sneaky separator. The separator is not invited to this party. π«Ά
π Example π
Run this code π»
#include <filesystem>
#include <iostream>
#include <string>
int main()
{
std::filesystem::path p1; // an empty path
p1 += "var"; // does not insert a separator
std::cout << R"("" + "var" --> )" << p1 << '\n';
p1 += "lib"; // does not insert a separator
std::cout << R"("var" + "lib" --> )" << p1 << '\n';
auto str = std::string{"1234567"};
p1.concat(std::begin(str) + 3, std::end(str) - 1);
std::cout << "p1.concat --> " << p1 << '\n';
}
π₯οΈ Output π₯οΈ
"" + "var" --> "var"
"var" + "lib" --> "varlib"
p1.concat --> "varlib456"
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- LWG 3055, applied to C++17 β behavior as published: the specification of concatenating a single character was ill-formed; correct behavior: made well-formed.
- LWG 3244, applied to C++17 β behavior as published: constraint that
Sourcecannot bepathwas missing; correct behavior: added.
π See also π
appendβ appends elements to the path with a directory separator.operator/=(public member function)operator/(C++17) (function) β concatenates two paths with a directory separator.
source/version and date, bestie: http://cppreference.com, 2024.06.10, page std::filesy...::operator+=(3). Mwah πβ¨
π¦ 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