Created on 2016-05-09.00:00:00 last changed 90 months ago
Proposed resolution:
This wording is relative to N4582.
Change [fs.class.path], class path synopsis, as indicated:
[Drafting note: Making the string_type&& constructors and assignment operators noexcept would over-constrain implementations which may need to perform construct additional state]
namespace std::filesystem { class path { public: […] // 27.10.8.4.1, constructors and destructor path() noexcept; path(const path& p); path(path&& p) noexcept; path(string_type&& source); template <class Source> path(const Source& source); […] // 27.10.8.4.2, assignments path& operator=(const path& p); path& operator=(path&& p) noexcept; path& operator=(string_type&& source); path& assign(string_type&& source); template <class Source> path& operator=(const Source& source); template <class Source> path& assign(const Source& source) template <class InputIterator> path& assign(InputIterator first, InputIterator last); […] }; }
Add a new paragraph following [fs.path.construct]/3:
path(string_type&& source);-?- Effects: Constructs an object of class path with pathname having the original value of source. source is left in a valid but unspecified state.
Add a new paragraph following [fs.path.assign]/4:
path& operator=(string_type&& source); path& assign(string_type&& source);-?- Effects: Modifies pathname to have the original value of source. source is left in a valid but unspecified state.
-?- Returns:*this
Currently construction of a path from the native string_type always performs a copy, even when that string is passed as a rvalue. This is a large pessimization as paths are commonly constructed from temporary strings.
One pattern I frequently see is:path foo(path const& p) { auto s = p.native(); mutateString(s); return s; }
Implementations should be allowed to move from s and avoid an unnecessary allocation. I believe string_type&& constructor and assignment operator overloads should be added to support this.
History | |||
---|---|---|---|
Date | User | Action | Args |
2017-07-30 20:15:43 | admin | set | status: wp -> c++17 |
2016-06-28 12:50:44 | admin | set | status: ready -> wp |
2016-05-22 15:38:38 | admin | set | status: new -> ready |
2016-05-10 20:14:04 | admin | set | messages: + msg8113 |
2016-05-09 00:00:00 | admin | create |