Title
cpp17-iterator should check that the type looks like an iterator first
Status
c++23
Section
[iterator.traits]
Submitter
Tim Song

Created on 2020-02-29.00:00:00 last changed 12 months ago

Messages

Date: 2020-11-09.21:40:50

Proposed resolution:

This wording is relative to N4861.

  1. Modify [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>;
      
    […]
    
Date: 2020-11-09.00:00:00

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

Date: 2020-04-04.00:00:00

[ 2020-04-04 Issue Prioritization ]

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

Date: 2020-02-29.00:00:00

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.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2020-11-09 21:40:50adminsetmessages: + msg11567
2020-11-09 21:40:50adminsetstatus: ready -> wp
2020-04-04 18:43:37adminsetmessages: + msg11187
2020-04-04 18:43:37adminsetstatus: new -> ready
2020-03-30 15:43:05adminsetmessages: + msg11182
2020-02-29 00:00:00admincreate