std::filesystem::path::concat, std::filesystem::path::operator+=
Min standard notice:
Concatenates the current path and the argument
# Declarations
path& operator+=( const path& p );
(since C++17)
path& operator+=( const string_type& str );
path& operator+=( std::basic_string_view<value_type> str );
(since C++17)
path& operator+=( const value_type* ptr );
(since C++17)
path& operator+=( value_type x );
(since C++17)
template< class CharT >
path& operator+=( CharT x );
(since C++17)
template< class Source >
path& operator+=( const Source& source );
(since C++17)
template< class Source >
path& concat( const Source& source );
(since C++17)
template< class InputIt >
path& concat( InputIt first, InputIt last );
(since C++17)
# Parameters
p: path to appendstr: string or string view to appendptr: pointer to the beginning of a null-terminated string to appendx: single character to appendsource: 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 of LegacyInputIterators that specify a multicharacter sequence that represents a path name
# Return value
*this
# Notes
Unlike with append() or operator/=, additional directory separators are never introduced.
# Example
#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';
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3055 | C++17 | the specification of concatenating a single character was ill-formed | made well-formed |
| LWG 3244 | C++17 | constraint that Source cannot be path was missing | added |