Fixes incorrect move operation in flat_map emplace.
The libstdc++ `flat_map` now correctly forwards the key in `_M_try_emplace`, preventing potential issues when inserting new elements.
This commit fixes an issue in the flat_map implementation where the key was unconditionally moved instead of forwarded during insertion in the _M_try_emplace function. This could lead to incorrect behavior or prevent insertion when the key type doesn’t support move operations. The fix ensures that the key is forwarded, allowing for correct construction of the element in place. A new test case, test10 in 23_containers/flat_map/1.cc, validates the fix.
In Details
flat_map is a C++ standard library container that provides a map-like interface using a sorted vector as its underlying storage. The _M_try_emplace function attempts to construct an element in place within the flat_map. This patch corrects an error in how the key is passed during this in-place construction. Toolchain devs outside libstdc++ might not immediately recognize this due to the container's relatively recent introduction.
For Context
The C++ Standard Library provides a flat_map container which, unlike a traditional std::map, stores its elements in a sorted array. emplace methods construct elements directly within the container's storage. This commit corrects an error in the _M_try_emplace insertion function within flat_map that was causing unintended move operations on the key, which could lead to bugs when inserting new new key-value pairs. The fix ensures correct in-place construction of new elements.