Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range-ify the code #4

Open
dangelog opened this issue Sep 8, 2022 · 0 comments
Open

Range-ify the code #4

dangelog opened this issue Sep 8, 2022 · 0 comments

Comments

@dangelog
Copy link

dangelog commented Sep 8, 2022

We cannot pretend that ranges don't exist. While rightfully one does NOT want to reimplement the algorithms themselves¹, one should still

  • reason in terms of iterator/sentinel pairs, instead of iterator/iterator
  • detect if <ranges> is available
  • if so, use the algorithm overloads in std::ranges (as they're the only ones that support iterator/sentinel)

Example:

QRegularExpression re = "\\d+";
auto matches = re.globalMatch(string);
auto matchesLengths = KDAlgorithms::transform(matches, [](const auto &m) { return m.capturedLength(); });

¹ even if simple (e.g. find_if). In other words, ranges should be supported up to the algorithmic call, after that one can require the user to be using a C++20 standard library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant