<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/132459>132459</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] Optimizations for algorithms on flat containers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++,
performance
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
huixie90
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ldionne
</td>
</tr>
</table>
<pre>
We could do something like this:
```c++
template <class Iterator, class Pred>
requires same_as<Pred, _Compare> &&
(__desugars_to_v<__less_tag, _Pred, _Reference, _Reference> ||
__desugars_to_v<__greater_tag, _Pred, _Reference, _Reference> || ...)
bool is_sorted(__ra_iterator<flat_set<_ValueType, _Compare, _Container>, typename _Container::iterator> first,
__ra_iterator<flat_set<_ValueType, _Compare, _Container>, typename _Container::iterator> last,
Pred pred) {
return true;
}
```
Other things we probably want to do if we go down that route:
- We might want a typedef for `__flat_set_iterator<...>` which expands to `__ra_iterator`?
- We might want to have some sort of trait instead of matching `flat_set` directly, maybe something like `__is_sorted_with_respect_to<Iterator, Predicate>` that we can then specialize for any container that is sorted as an invariant?
- In `std::flat_set::insert(Iter, Iter)` & friends, we could add `std::sorted_unique_t` when we see that `Iter` is a fellow `flat_set` iterator (or any kind of sorted iterator, really).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VcGOozgQ_RrnUuqImISEA4c03ZHmNKvVaueICijAO8Zm7CKZzNevbJLudGtOe9iWJWg79areq-cCvVe9ISrE7llIOczqp6I8EVKK3csKZx6sK3SrrDG0qm17Lb4RNHbWLbQWvB2JB2V60Oo7AQ_Ki_QokriyZFmNkM9hJUemcdLIBCItG43ewxcmh2ydkCUsO384akX6KpIjgKMfs3LkweNIFXqRlvFYllCVdpzQkUhfQcgsrOQIQh6qqiU_9-h8xbY6i7SsKk3eV4x9DHxD-JM6cmQa-vRfQNyXYSVH-B1c7wiZ3H9AhPV6LWQukmNtrQblK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