Skip to content

Remove converter hack around std::map::iterator - #523

Merged
nunoplopes merged 7 commits into
Cpp2Rust:masterfrom
lucic71:map-iterator
Oct 11, 2026
Merged

nunoplopes merged 7 commits into
Cpp2Rust:masterfrom
lucic71:map-iterator

Conversation

@lucic71

@lucic71 lucic71 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

The old code special cased std::map::iterator (which is just a sugar for std::pair<const K, V>) to generate i.first() and i.second() instead of i.0 and i.1.

This PR removes the hack by saving a pair in libcc2rs::MapIter which can be accessed with .0 and .1. It also fixes a translation bug:

 for (auto i : m) {
    i.second = -1;
    assert(i.second == -1);
  }
  for (const auto &i : m) {
    assert(i.second != -1);
  }

@nunoplopes
nunoplopes merged commit 747cb00 into Cpp2Rust:master Oct 11, 2026
9 checks passed
nunoplopes pushed a commit that referenced this pull request Oct 11, 2026
I realized that #523 fully works only with the new AST matcher because
of const types: string matcher matches strings which is broken for const
pointers in general. Until the AST matcher lands I fixed the string
matcher.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants