summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/flat_map
AgeCommit message (Collapse)Author
2025-06-06libstdc++: Fix flat_map::operator[] for const lvalue keys [PR120432]Patrick Palka
The const lvalue operator[] overload wasn't properly forwarding the key type to the generic overload, causing a hard error for const keys. Rather than correcting the forwarded type this patch just makes the non-template overloads call try_emplace directly instead. That way we can remove the non-standard same_as constraint on the generic overload and match the spec more closely. PR libstdc++/120432 libstdc++-v3/ChangeLog: * include/std/flat_map (flat_map::operator[]): Make the non-template overloads call try_emplace directly. Remove non-standard same_as constraint on the template overload. * testsuite/23_containers/flat_map/1.cc (test08): New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-05-29libstdc++: Compare keys and values separately in flat_map::operator==Patrick Palka
Instead of effectively doing a zipped comparison of the keys and values, compare them separately to leverage the underlying containers' optimized equality implementations. libstdc++-v3/ChangeLog: * include/std/flat_map (_Flat_map_impl::operator==): Compare keys and values separately. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-05-29libstdc++: Fix tuple/pair confusion with std::erase_if(flat_map) [PR120465]Patrick Palka
std::erase_if for flat_map/multimap is implemented via ranges::erase_if over a zip_view of the keys and values, the value_type of which is a tuple, but the given predicate needs to be called with a pair (flat_map's value_type). So use a projection to convert the tuple into a suitable pair. PR libstdc++/120465 libstdc++-v3/ChangeLog: * include/std/flat_map (_Flat_map_impl::_M_erase_if): Use a projection with ranges::remove_if to pass a pair instead of a tuple to the predicate. * testsuite/23_containers/flat_map/1.cc (test07): Strengthen to expect the argument passed to the predicate is a pair. * testsuite/23_containers/flat_multimap/1.cc (test07): Likewise. Co-authored-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-04-29libstdc++: Fix availability of std::erase_if(std::flat_foo) [PR119427]Patrick Palka
These std::erase_if overloads were wrongly implemented as hidden friends, visible only via ADL, so erase_if(x) would work but not std::erase_if(x). PR libstdc++/119427 libstdc++-v3/ChangeLog: * include/std/flat_map (_Flat_map_impl::erase_if): Replace this hidden friend with ... (_Flat_map_impl::_M_erase_if): ... this member function. (flat_map): Export _Flat_map_impl::_M_erase_if. (erase_if(flat_map)): Define. (flat_multimap): Export _Flat_map_impl::_M_erase_if. (erase_if(flat_multimap)): Define. * include/std/flat_set (_Flat_set_impl::erase_if): Replace with ... (_Flat_set_impl::_M_erase_if): ... this member function. (flat_set): Export _Flat_set_impl::_M_erase_if. (erase_if(flat_set)): Define. (flat_multiset): Export _Flat_set_impl::_M_erase_if. (erase_if(flat_multiset)): Define. * testsuite/23_containers/flat_map/1.cc (test07): New test. * testsuite/23_containers/flat_multimap/1.cc (test07): New test. * testsuite/23_containers/flat_multiset/1.cc (test09): New test. * testsuite/23_containers/flat_set/1.cc (test09): New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-01-31libstdc++: Fix flat_foo::insert_range for non-common ranges [PR118156]Patrick Palka
This fixes flat_map/multimap::insert_range by just generalizing the insert implementation to handle heterogenous iterator/sentinel pair. I'm not sure we can do better than this, e.g. we can't implement it in terms of the adapted containers' insert_range because that'd require two passes over the range. For flat_set/multiset, we can implement insert_range directly in terms of the adapted container's insert_range. A fallback implementation is also provided if insert_range isn't available, as is the case for std::deque currently. PR libstdc++/118156 libstdc++-v3/ChangeLog: * include/std/flat_map (_Flat_map_impl::_M_insert): Generalized version of insert taking heterogenous iterator/sentinel pair. (_Flat_map_impl::insert): Dispatch to _M_insert. (_Flat_map_impl::insert_range): Likewise. (flat_map): Export _Flat_map_impl::insert_range. (flat_multimap): Likewise. * include/std/flat_set (_Flat_set_impl::insert_range): Reimplement directly, not in terms of insert. (flat_set): Export _Flat_set_impl::insert_range. (flat_multiset): Likewise. * testsuite/23_containers/flat_map/1.cc (test06): New test. * testsuite/23_containers/flat_multimap/1.cc (test06): New test. * testsuite/23_containers/flat_multiset/1.cc (test06): New test. * testsuite/23_containers/flat_set/1.cc (test06): New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-12-19libstdc++: Implement C++23 <flat_map> (P0429R9)Patrick Palka
This implements the C++23 container adaptors std::flat_map and std::flat_multimap from P0429R9. The implementation is shared as much as possible between the two adaptors via a common base class that's parameterized according to key uniqueness. libstdc++-v3/ChangeLog: * include/Makefile.am: Add new header <flat_map>. * include/Makefile.in: Regenerate. * include/bits/alloc_traits.h (__not_allocator_like): New concept. * include/bits/stl_function.h (__transparent_comparator): Likewise. * include/bits/stl_iterator_base_types.h (__has_input_iter_cat): Likewise. * include/bits/uses_allocator.h (__allocator_for): Likewise. * include/bits/utility.h (sorted_unique_t): Define for C++23. (sorted_unique): Likewise. (sorted_equivalent_t): Likewise. (sorted_equivalent): Likewise. * include/bits/version.def (flat_map): Define. * include/bits/version.h: Regenerate. * include/precompiled/stdc++.h: Include <flat_map>. * include/std/flat_map: New file. * src/c++23/std.cc.in: Export <flat_map>. * testsuite/23_containers/flat_map/1.cc: New test. * testsuite/23_containers/flat_multimap/1.cc: New test. Co-authored-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>