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

Make RelationRange a proper view #727

Merged
merged 1 commit into from
Jan 21, 2025

Conversation

m-fila
Copy link
Contributor

@m-fila m-fila commented Jan 20, 2025

BEGINRELEASENOTES

  • Make RelationRange fulfill the std::ranges::view and std::ranges::borrowed_range concepts

ENDRELEASENOTES

As suggested in #626 (comment) adding tests for checking whether RelationRange is a std range - it is.

Since the RelationRange is a very lightweight, non-owning view it can fulfill two more concepts that can be used by the std range algorithms and adapters to avoid unneeded operations:

  • view - it's cheap to move/copy as it stores only iterators to the data living elsewhere
  • borrowed_range - the iterators taken from range remain valid even when the range is destroyed since they are not local to the range

The RelationRange is very similar to std::span and std::ranges::subrange and could potential replaced by them except for two differences:

  • RealationRange has at for bound-check element access whereas the alternatives don't (until C++26)
  • RelationRange element access returns copy whereas the alternatives would return const reference. Since the elements are podio objects then copy is preferred.

The RelationRange could be also re-implemented with std::ranges::view_interface but it comes with issues like above so I think isn't really worth it

@m-fila m-fila force-pushed the relation_range_as_range branch from 39a6337 to e6b4b24 Compare January 20, 2025 12:28
Copy link
Collaborator

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Thank you.

@tmadlener tmadlener merged commit 8e2aa67 into AIDASoft:master Jan 21, 2025
18 checks passed
@m-fila m-fila deleted the relation_range_as_range branch January 21, 2025 12:43
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

Successfully merging this pull request may close these issues.

2 participants