Skip to content

Commit

Permalink
make RelationRange a view
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila committed Jan 20, 2025
1 parent ad3fc80 commit 39a6337
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion include/podio/RelationRange.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef PODIO_RELATIONRANGE_H
#define PODIO_RELATIONRANGE_H

#include <iterator>
#include <ranges>
#include <vector>

namespace podio {
Expand Down Expand Up @@ -57,4 +57,11 @@ class RelationRange {
};
} // namespace podio

// Opt-in to view concept
template <typename ReferenceType>
inline constexpr bool std::ranges::enable_view<podio::RelationRange<ReferenceType>> = true;
// Opt-in to borrowed_range concept
template <typename ReferenceType>
inline constexpr bool std::ranges::enable_borrowed_range<podio::RelationRange<ReferenceType>> = true;

#endif // PODIO_RELATIONRANGE_H
13 changes: 13 additions & 0 deletions tests/unittests/std_interoperability.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "datamodel/ExampleHit.h"
#include "datamodel/ExampleHitCollection.h"
#include "datamodel/MutableExampleHit.h"

#include "podio/LinkCollection.h"
#include "podio/RelationRange.h"

#include <catch2/catch_test_macros.hpp>

Expand Down Expand Up @@ -1195,5 +1197,16 @@ TEST_CASE("LinkCollection and range concepts", "[links][iterator][std]") {
STATIC_REQUIRE(std::ranges::viewable_range<link_collection>);
}

TEST_CASE("RelationRange as range", "[relations][ranges][std]") {
using relation_range = podio::RelationRange<ExampleHit>;

STATIC_REQUIRE(std::ranges::contiguous_range<relation_range>);
STATIC_REQUIRE(std::ranges::sized_range<relation_range>);
STATIC_REQUIRE(std::ranges::common_range<relation_range>);
STATIC_REQUIRE(std::ranges::viewable_range<relation_range>);
STATIC_REQUIRE(std::ranges::view<relation_range>);
STATIC_REQUIRE(std::ranges::borrowed_range<relation_range>);
}

#undef DOCUMENTED_STATIC_FAILURE
#undef DOCUMENTED_FAILURE

0 comments on commit 39a6337

Please sign in to comment.