Skip to content

Range-ify the code #4

Description

@dangelog

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.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions