Date
2025-03-29.00:00:00
Message id
14714

Content

According to the spec, the following code should hard error

std::flat_map<std::string, int, std::less<>> m;
m.try_emplace("abc", 5);  // hard error

The reason is that we specify in [flat.map.modifiers] p21 the effect to be as if `ranges::upper_bound` is called.

`ranges::upper_bound` requires `indirect_strict_weak_order`, which requires the comparator to be invocable for all combinations. In this case, it requires

const char (&)[4] < const char (&)[4] 

to be well-formed, which is no longer the case in C++26 after P2865R6.

We should just use `std::upper_bound` instead. libstdc++ already uses `std::upper_bound`. libc++ uses `ranges::upper_bound` but clang has not yet implemented P2865 properly.