Skip to content

<flat_set>: optimize unique algorithm call #6020

Description

STL/stl/inc/flat_set

Lines 708 to 716 in 6314950

void _Erase_dupes_if_not_multi() {
if constexpr (_IsUnique) {
const auto _Equivalent = [this](const _Kty& _Lhs, const _Kty& _Rhs) {
return !_Compare(_Lhs, _Rhs) && !_Compare(_Rhs, _Lhs);
};
const auto _End = _Mycont.end();
_Mycont.erase(_STD unique(_Mycont.begin(), _End, _Equivalent), _End);
}
}

This could have been vectorized unique, but the predicate is on the way.

For less<>, less<T>, ranges::less predicate and for usual types, the equivalence can be replaced with binary equality, and the predicate can be omitted.

In the case of predicate-less unique call for normal underlying container (like, not deque) the unique will be vectorized using already existing code path.


For flat_map this could work in principle too, but would effectively require implementing vector algorithms in headers, and would be way more tedious, so that's probably not what we would do, at least in a near future.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixedSomething works now, yay!flat_meowC++23 container adaptorsperformanceMust go faster

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions