Title
[filesys.ts] [PDTS] Unclear why range-based-for functions return different types
Status
open
Section
[fs.filesystem.synopsis]
Submitter
FI-2

Created on 2014-01-20.00:00:00 last changed 90 months ago

Messages

Date: 2016-01-28.01:00:35

Proposed resolution:

  1. Change 6 [fs.filesystem.synopsis]:

      class directory_iterator;
    
      // enable directory_iterator range-based for statements
      const directory_iterator& begin(const directory_iterator& iter) noexcept;
      directory_iterator end(const directory_iterator&) noexcept;
    
      class recursive_directory_iterator;
    
      // enable recursive_directory_iterator range-based for statements
      const recursive_directory_iterator& begin(const recursive_directory_iterator& iter) noexcept;
      recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
      
  2. Change 13.2 [directory_iterator.nonmembers]:

    These functions enable use of directory_iterator with C++11 range-based for statements.

    const directory_iterator& begin(constdirectory_iterator& iter) noexcept;

    Returns: iter.

    directory_iterator end(const directory_iterator&) noexcept;

    Returns: directory_iterator().

  3. Change 14.2 [rec.dir.itr.nonmembers]:

    These functions enable use of recursive_directory_iterator with C++11 range-based for statements.

    const recursive_directory_iterator& begin(constrecursive_directory_iterator& iter) noexcept;

    Returns: iter.

    recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;

    Returns: recursive_directory_iterator().

Date: 2014-02-13.00:00:00

[ 2014-02-13 LWG/SG-3 Issaquah: Proposed wording accepted. ]

Date: 2014-02-11.00:00:00

[ 2014-02-11 Issaquah: Change begin() argument and return to pass-by-value. See wiki notes for rationale. Beman to provide wording for review next meeting. ]

Date: 2014-02-08.00:00:00

[ 2014-02-08: Daniel responds to Beman ]

The difference in return types becomes relevant, when testing whether e.g. directory_iterator would satisfy the Traversable requirements as currently specified in N3763. Expressed in code form these requirements impose that the following assertion holds:

  static_assert(std::is_same<
      decltype(std::range_begin(std::declval<directory_iterator>())),
      decltype(std::range_end(std::declval<directory_iterator>()))
    >::value, "No Traversable type");
  

Both directory_iterator and recursive_directory_iterator won't satisfy this requirement currently.

Date: 2016-01-31.20:31:05

Addresses: filesys.ts

It is unclear why the range-for support functions (begin()/end()) for directory_iterator and recursive_directory_iterator return different types for begin() and end(), namely that begin() returns a reference to const and end() returns a value.

[2014-02-07: Beman Dawes provides comments from the Boost implementation:]

  //  begin() and end() are only used by a range-based for statement in the context of
  //  auto - thus the top-level const is stripped - so returning const is harmless and
  //  emphasizes begin() is just a pass through.
History
Date User Action Args
2017-07-30 20:10:41adminsetstatus: wp -> open
2016-01-28 01:00:35adminsetmessages: + msg7725
2016-01-28 01:00:35adminsetmessages: + msg7724
2016-01-28 01:00:35adminsetmessages: + msg7723
2016-01-28 01:00:35adminsetmessages: + msg7722
2014-01-20 00:00:00admincreate