Use hidden friends for directory iterator comparisons
The equality operators for directory iterators are not explicitly specified in the standard, they're only required to meet the iterator requirements. This means we don't need to declare them at namespace scope and can implement them as hidden friends. Also add 'noexcept' to directory_iterator's dereference operators. * include/bits/fs_dir.h (directory_iterator::operator*) (directory_iterator::operator->): Add noexcept. (operator==, operator!=): Replace namespace-scope equality operators for directory iterators with hidden friends. From-SVN: r270175
This commit is contained in:
parent
67087c7e53
commit
dd4a309e05
@ -1,5 +1,10 @@
|
||||
2019-04-05 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
* include/bits/fs_dir.h (directory_iterator::operator*)
|
||||
(directory_iterator::operator->): Add noexcept.
|
||||
(operator==, operator!=): Replace namespace-scope equality operators
|
||||
for directory iterators with hidden friends.
|
||||
|
||||
PR libstdc++/89986
|
||||
* config/abi/pre/gnu.ver: Add missing exports.
|
||||
* testsuite/27_io/filesystem/iterators/directory_iterator.cc: Test
|
||||
|
@ -390,8 +390,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
||||
directory_iterator&
|
||||
operator=(directory_iterator&& __rhs) noexcept = default;
|
||||
|
||||
const directory_entry& operator*() const;
|
||||
const directory_entry* operator->() const { return &**this; }
|
||||
const directory_entry& operator*() const noexcept;
|
||||
const directory_entry* operator->() const noexcept { return &**this; }
|
||||
directory_iterator& operator++();
|
||||
directory_iterator& increment(error_code& __ec);
|
||||
|
||||
@ -407,7 +407,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
||||
|
||||
friend bool
|
||||
operator==(const directory_iterator& __lhs,
|
||||
const directory_iterator& __rhs);
|
||||
const directory_iterator& __rhs) noexcept
|
||||
{
|
||||
return !__rhs._M_dir.owner_before(__lhs._M_dir)
|
||||
&& !__lhs._M_dir.owner_before(__rhs._M_dir);
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const directory_iterator& __lhs,
|
||||
const directory_iterator& __rhs) noexcept
|
||||
{ return !(__lhs == __rhs); }
|
||||
|
||||
friend class recursive_directory_iterator;
|
||||
|
||||
@ -422,17 +431,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
||||
end(directory_iterator) noexcept
|
||||
{ return directory_iterator(); }
|
||||
|
||||
inline bool
|
||||
operator==(const directory_iterator& __lhs, const directory_iterator& __rhs)
|
||||
{
|
||||
return !__rhs._M_dir.owner_before(__lhs._M_dir)
|
||||
&& !__lhs._M_dir.owner_before(__rhs._M_dir);
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator!=(const directory_iterator& __lhs, const directory_iterator& __rhs)
|
||||
{ return !(__lhs == __rhs); }
|
||||
|
||||
class recursive_directory_iterator
|
||||
{
|
||||
public:
|
||||
@ -499,7 +497,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
||||
|
||||
friend bool
|
||||
operator==(const recursive_directory_iterator& __lhs,
|
||||
const recursive_directory_iterator& __rhs);
|
||||
const recursive_directory_iterator& __rhs) noexcept
|
||||
{
|
||||
return !__rhs._M_dirs.owner_before(__lhs._M_dirs)
|
||||
&& !__lhs._M_dirs.owner_before(__rhs._M_dirs);
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const recursive_directory_iterator& __lhs,
|
||||
const recursive_directory_iterator& __rhs) noexcept
|
||||
{ return !(__lhs == __rhs); }
|
||||
|
||||
struct _Dir_stack;
|
||||
std::__shared_ptr<_Dir_stack> _M_dirs;
|
||||
@ -513,19 +520,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
||||
end(recursive_directory_iterator) noexcept
|
||||
{ return recursive_directory_iterator(); }
|
||||
|
||||
inline bool
|
||||
operator==(const recursive_directory_iterator& __lhs,
|
||||
const recursive_directory_iterator& __rhs)
|
||||
{
|
||||
return !__rhs._M_dirs.owner_before(__lhs._M_dirs)
|
||||
&& !__lhs._M_dirs.owner_before(__rhs._M_dirs);
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator!=(const recursive_directory_iterator& __lhs,
|
||||
const recursive_directory_iterator& __rhs)
|
||||
{ return !(__lhs == __rhs); }
|
||||
|
||||
_GLIBCXX_END_NAMESPACE_CXX11
|
||||
|
||||
// @} group filesystem
|
||||
|
Loading…
x
Reference in New Issue
Block a user