std-path.cc
48 KB
-
LWG 2936: update path::compare logic and optimize string comparisons · 36313a6b
The resolution for LWG 2936 defines the comparison more precisely, which this patch implements. The patch also defines comparisons with strings to work without constructing a temporary path object (so avoids any memory allocations). * include/bits/fs_path.h (path::compare(const string_type&)) (path::compare(const value_type*)): Add noexcept and construct a string view to compare to instead of a path. (path::compare(basic_string_view<value_type>)): Add noexcept. Remove inline definition. * src/filesystem/std-path.cc (path::_Parser): Track last type read from input. (path::_Parser::next()): Return a final empty component when the input ends in a non-root directory separator. (path::_M_append(basic_string_view<value_type>)): Remove special cases for trailing non-root directory separator. (path::_M_concat(basic_string_view<value_type>)): Likewise. (path::compare(const path&)): Implement LWG 2936. (path::compare(basic_string_view<value_type>)): Define in terms of components returned by parser, consistent with LWG 2936. * testsuite/27_io/filesystem/path/compare/lwg2936.cc: New. * testsuite/27_io/filesystem/path/compare/path.cc: Test more cases. * testsuite/27_io/filesystem/path/compare/strings.cc: Likewise. From-SVN: r267235
Jonathan Wakely committed