Title
Directory iterators should be usable with default sentinel
Status
new
Section
[fs.class.directory.iterator.general][fs.class.rec.dir.itr.general]
Submitter
Jonathan Wakely

Created on 2022-06-17.00:00:00 last changed 1 week ago

Messages

Date: 2022-06-17.18:41:49

Proposed resolution:

This wording is relative to N4910.

  1. Modify [fs.class.directory.iterator.general], class directory_iterator synopsis, as indicated:

    namespace std::filesystem {
      class directory_iterator {
        […]
    
        const directory_entry& operator*() const;
        const directory_entry* operator->() const;
        directory_iterator& operator++();
        directory_iterator& increment(error_code& ec);
        
        friend bool operator==(const directory_iterator& lhs, default_sentinel_t) noexcept
        { return lhs == end(lhs); }
    
        // other members as required by [input.iterators], input iterators
      };
    }
    
  2. Modify [fs.class.rec.dir.itr.general], class recursive_directory_iterator synopsis, as indicated:

    namespace std::filesystem {
      class recursive_directory_iterator {
        […]
    
        void pop();
        void pop(error_code& ec);
        void disable_recursion_pending();
        
        friend bool operator==(const recursive_directory_iterator& lhs, default_sentinel_t) noexcept
        { return lhs == end(lhs); }
    
        // other members as required by [input.iterators], input iterators
      };
    }
    
Date: 2022-06-17.00:00:00

We added comparisons with default_sentinel_t to the stream and streambuf iterators, because their past-the-end iterator is just a default-constructed iterator. We didn't do the same for filesystem directory iterators, but they also use a default-constructed value as the sentinel.

The proposed resolution addresses this oversight.

History
Date User Action Args
2022-06-17 18:41:49adminsetmessages: + msg12509
2022-06-17 00:00:00admincreate