This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of WP status.

3420. cpp17-iterator should check that the type looks like an iterator first

Section: 23.3.2.3 [iterator.traits] Status: WP Submitter: Tim Song Opened: 2020-02-29 Last modified: 2020-11-15

Priority: 0

View all other issues in [iterator.traits].

View all issues with WP status.

Discussion:

It is common in pre-C++20 code to rely on SFINAE-friendly iterator_traits to rule out non-iterators in template constraints (std::filesystem::path is one example in the standard library).

C++20 changed iterator_traits to automatically detect its members in some cases, and this detection can cause constraint recursion. LWG 3244 tries to fix this for path by short-circuiting the check when the source type is path itself, but this isn't sufficient:

struct Foo 
{
  Foo(const std::filesystem::path&);
};

static_assert(std::copyable<Foo>);

Here the copyability determination will ask whether a path can be constructed from a Foo, which asks whether Foo is an iterator, which checks whether Foo is copyable […].

To reduce the risk of constraint recursion, we should change cpp17-iterator so that it does not ask about copyability until the type is known to resemble an iterator.

[2020-04-04 Issue Prioritization]

Status set to Tentatively Ready after six positive votes on the reflector.

[2020-11-09 Approved In November virtual meeting. Status changed: Tentatively Ready → WP.]

Proposed resolution:

This wording is relative to N4861.

  1. Modify 23.3.2.3 [iterator.traits] as indicated:

    -2- The definitions in this subclause make use of the following exposition-only concepts:

    template<class I>
    concept cpp17-iterator =
      copyable<I> && requires(I i) {
        { *i } -> can-reference;
        { ++i } -> same_as<I&>;
        { *i++ } -> can-reference;
      } && copyable<I>;
      
    […]