Skip to content

<algorithm>: algorithms should use TMP to provide optimized implementation for vector<bool> iterators #625

Description

MS's STL already uses metaprogramming to help the optimizer produce
optimized code. As an example, std::fill delegates to std::memset
if safe, which has the advantage of guaranteed good performance in
Debug mode, as well as not having to rely on the optimizer to salvage
reasonable ASM out of the actual code.

I would like optimizations like this to also happen when calling various
algorithms on std::vector<bool>, which currently does not happen.

As an example, this code

void clean_out(std::vector<bool>& vec) {
    std::fill(vec.begin(), vec.end(), false);
}

should end up calling memset, rather than doing whatever this is.

Other algorithms that could be optimized:

  • std::copy
  • std::count
  • std::find
  • std::equal
  • possibly others?

This would also improve the performance of std::vector<bool>'s member functions, as it internally uses std algorithms.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions