microsoft / microsoft/STL

`<vector>`: `vector<bool>::iterator` fails to meet Cpp17InputIterator requirements

Open
#5,002 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

LWG issue needed
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

Describe the bug

The following program doesn't compile.

#include <vector>

int main()
{
    std::vector<bool> vb{true};
    vb.begin()->flip();
    (*vb.begin()).flip();
}

It's probably intended that (*vb.begin()).flip() works and is equivalent to vb[0].flip(). As per [tab:inputiterator], it seems that vb.begin()->flip() also needs to be supported.

Command-line test case

Godbolt link

Expected behavior

vb.begin()->flip() works and is equivalent to vb[0].flip().

STL version

Microsoft Visual Studio Community 2022
Version 17.12.0 Preview 2.1

(Probably in all existing versions.)

Additional context

We may need to correspondingly change member type pointer to conform to [iterator.traits]/1.

Also, it's even not very clear to me that vector<bool>::iterator is required to meet the Cpp17InputIterator named requirements. Given vector<bool> is not a real container, it's unclear which requirements on iterators of containers are applied to iterators of vector<bool>. LWG-1422 is related.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the implementation of vector::iterator and reproduce the provided program using the Godbolt link. Check the Cpp17InputIterator and iterator_traits requirements cited in the issue; done means both flip() expressions compile and behave equivalently to vb[0].flip().

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.