Title
Missing constexpr in std::counted_iterator
Status
c++23
Section
[counted.iter.nav]
Submitter
Jiang An

Created on 2021-11-21.00:00:00 last changed 4 months ago

Messages

Date: 2022-02-10.12:58:57

Proposed resolution:

This wording is relative to N4901.

  1. Modify [counted.iterator], class template counted_iterator synopsis, as indicated:

    […]
    constexpr counted_iterator& operator++();
    constexpr decltype(auto) operator++(int);
    constexpr counted_iterator operator++(int)
      requires forward_iterator<I>;
    constexpr counted_iterator& operator--()
      requires bidirectional_iterator<I>;
    constexpr counted_iterator operator--(int)
      requires bidirectional_iterator<I>;
    […]
    
  2. Modify [counted.iter.nav] as indicated:

    constexpr decltype(auto) operator++(int);
    

    -3- Preconditions: length > 0.

    -4- Effects: Equivalent to:

    --length;
    try { return current++; }
    catch(...) { ++length; throw; }
    
Date: 2022-02-10.00:00:00

[ 2022-02-10 Approved at February 2022 virtual plenary. Status changed: Tentatively Ready → WP. ]

Date: 2022-01-15.00:00:00

[ 2022-01-30; Reflector poll ]

Set status to Tentatively Ready after nine votes in favour during reflector poll.

Date: 2021-11-21.00:00:00

One overload of std::counted_operator::operator++ is not constexpr currently, which is seemly because of that a try-block (specified in [counted.iter.nav]/4) is not allowed in a constexpr function until C++20. Given a try-block is allowed in a constexpr function in C++20, IMO this overload should also be constexpr.

MSVC STL has already added constexpr at first. The situation of this overload is originally found by Casey Carter, but no LWG issue has been submitted.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-02-10 12:58:57adminsetmessages: + msg12358
2022-02-10 12:58:57adminsetstatus: ready -> wp
2022-01-30 16:31:11adminsetmessages: + msg12303
2022-01-30 16:31:11adminsetstatus: new -> ready
2021-11-21 12:06:12adminsetmessages: + msg12232
2021-11-21 00:00:00admincreate