https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122921
Bug ID: 122921
Summary: The value_type of flat_map's iterator should be
pair<Key, T> instead of pair<const Key, T>
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gulackeg at gmail dot com
Target Milestone: ---
Test code:
// https://godbolt.org/z/bvcY3T961
#include <flat_map>
#include <ranges>
using C = std::flat_map<int, int>;
using V = std::pair<int, int>;
using V = C::value_type; // OK
// - ✅ libc++: OK
// - ❌ libstdc++: error: type alias redefinition with different types
// ('std::ranges::range_value_t<C>' (aka 'std::pair<const int, int>')
// vs 'C::value_type' (aka 'pair<int, int>'))
using V = std::ranges::range_value_t<C>;
According to [flat.map.defn][1], `flat_map`'s `value_type` is specified as
`pair<Key, T>`, and this should also be the `value_type` of `flat_map`'s
`iterator` and `const_iterator`.
[1]: https://eel.is/c++draft/flat.map.defn