Commit f90b16c4 by Jonathan Wakely Committed by Jonathan Wakely

Make filesystem::path comparison operators hidden friends (LWG 3065)

This change revealed two testsuite bugs where some string comparisons
only compiled by converting the strings to filesystem::path objects.

	* include/bits/fs_path.h (operator<, operator<=, operator>)
	(operator>=, operator==, operator!=): Make hidden friends, as per
	LWG 3065.
	* testsuite/27_io/filesystem/path/native/string-char8_t.cc: Fix
	string type in test.
	* testsuite/27_io/filesystem/path/native/string.cc: Likewise.

From-SVN: r270558
parent 7f8aaa1a
2019-04-24 Jonathan Wakely <jwakely@redhat.com> 2019-04-24 Jonathan Wakely <jwakely@redhat.com>
* include/bits/fs_path.h (operator<, operator<=, operator>)
(operator>=, operator==, operator!=): Make hidden friends, as per
LWG 3065.
* testsuite/27_io/filesystem/path/native/string-char8_t.cc: Fix
string type in test.
* testsuite/27_io/filesystem/path/native/string.cc: Likewise.
* include/std/any (any::any(ValueType&&)): Use __and_v. * include/std/any (any::any(ValueType&&)): Use __and_v.
* include/std/numeric (midpoint(T, T, T), midpoint(T*, T*, T*)): * include/std/numeric (midpoint(T, T, T), midpoint(T*, T*, T*)):
Likewise. Likewise.
......
...@@ -417,6 +417,40 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -417,6 +417,40 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
return __is; return __is;
} }
// non-member operators
/// Compare paths
friend bool operator<(const path& __lhs, const path& __rhs) noexcept
{ return __lhs.compare(__rhs) < 0; }
/// Compare paths
friend bool operator<=(const path& __lhs, const path& __rhs) noexcept
{ return !(__rhs < __lhs); }
/// Compare paths
friend bool operator>(const path& __lhs, const path& __rhs) noexcept
{ return __rhs < __lhs; }
/// Compare paths
friend bool operator>=(const path& __lhs, const path& __rhs) noexcept
{ return !(__lhs < __rhs); }
/// Compare paths
friend bool operator==(const path& __lhs, const path& __rhs) noexcept
{ return __lhs.compare(__rhs) == 0; }
/// Compare paths
friend bool operator!=(const path& __lhs, const path& __rhs) noexcept
{ return !(__lhs == __rhs); }
/// Append one path to another
friend path operator/(const path& __lhs, const path& __rhs)
{
path __result(__lhs);
__result /= __rhs;
return __result;
}
// Create a basic_string by reading until a null character. // Create a basic_string by reading until a null character.
template<typename _InputIterator, template<typename _InputIterator,
typename _Traits = std::iterator_traits<_InputIterator>, typename _Traits = std::iterator_traits<_InputIterator>,
...@@ -578,38 +612,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -578,38 +612,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
size_t hash_value(const path& __p) noexcept; size_t hash_value(const path& __p) noexcept;
/// Compare paths
inline bool operator<(const path& __lhs, const path& __rhs) noexcept
{ return __lhs.compare(__rhs) < 0; }
/// Compare paths
inline bool operator<=(const path& __lhs, const path& __rhs) noexcept
{ return !(__rhs < __lhs); }
/// Compare paths
inline bool operator>(const path& __lhs, const path& __rhs) noexcept
{ return __rhs < __lhs; }
/// Compare paths
inline bool operator>=(const path& __lhs, const path& __rhs) noexcept
{ return !(__lhs < __rhs); }
/// Compare paths
inline bool operator==(const path& __lhs, const path& __rhs) noexcept
{ return __lhs.compare(__rhs) == 0; }
/// Compare paths
inline bool operator!=(const path& __lhs, const path& __rhs) noexcept
{ return !(__lhs == __rhs); }
/// Append one path to another
inline path operator/(const path& __lhs, const path& __rhs)
{
path __result(__lhs);
__result /= __rhs;
return __result;
}
template<typename _InputIterator> template<typename _InputIterator>
inline auto inline auto
u8path(_InputIterator __first, _InputIterator __last) u8path(_InputIterator __first, _InputIterator __last)
......
...@@ -46,7 +46,7 @@ test02() ...@@ -46,7 +46,7 @@ test02()
path p(s); path p(s);
auto str = p.string<char>(); auto str = p.string<char>();
VERIFY( str == u"abc" ); VERIFY( str == "abc" );
VERIFY( str == p.string() ); VERIFY( str == p.string() );
auto strw = p.string<wchar_t>(); auto strw = p.string<wchar_t>();
......
...@@ -46,7 +46,7 @@ test02() ...@@ -46,7 +46,7 @@ test02()
path p(s); path p(s);
auto str = p.string<char>(); auto str = p.string<char>();
VERIFY( str == u"abc" ); VERIFY( str == "abc" );
VERIFY( str == p.string() ); VERIFY( str == p.string() );
auto strw = p.string<wchar_t>(); auto strw = p.string<wchar_t>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment