Skip to content

[libc++] flat_set uses 2x as many comparisons as it should #175086

@halbi2

Description

@halbi2
#include <flat_set>
#include <iostream>

int Count = 0;
struct Comp { bool operator()(int x, int y) const { ++Count; return x < y; } };

int main() {
  std::flat_set<int, Comp> x = {0,0,0,0,0,0,0,0,0,0};
  std::cout << Count;
}

This program uses 27 comparisons. It can be done in 18. The problem is that flat_set::__key_equiv always calls the comparator twice instead of once. I will post a patch for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions