Skip to content

Commit 8e2aa67

Browse files
authored
Make RelationRange a proper view (#727)
1 parent 4e41eb9 commit 8e2aa67

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

include/podio/RelationRange.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef PODIO_RELATIONRANGE_H
22
#define PODIO_RELATIONRANGE_H
33

4-
#include <iterator>
4+
#include <ranges>
55
#include <vector>
66

77
namespace podio {
@@ -57,4 +57,11 @@ class RelationRange {
5757
};
5858
} // namespace podio
5959

60+
// Opt-in to view concept
61+
template <typename ReferenceType>
62+
inline constexpr bool std::ranges::enable_view<podio::RelationRange<ReferenceType>> = true;
63+
// Opt-in to borrowed_range concept
64+
template <typename ReferenceType>
65+
inline constexpr bool std::ranges::enable_borrowed_range<podio::RelationRange<ReferenceType>> = true;
66+
6067
#endif // PODIO_RELATIONRANGE_H

tests/unittests/std_interoperability.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "datamodel/ExampleHit.h"
22
#include "datamodel/ExampleHitCollection.h"
33
#include "datamodel/MutableExampleHit.h"
4+
45
#include "podio/LinkCollection.h"
6+
#include "podio/RelationRange.h"
57

68
#include <catch2/catch_test_macros.hpp>
79

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

1200+
TEST_CASE("RelationRange as range", "[relations][ranges][std]") {
1201+
using relation_range = podio::RelationRange<ExampleHit>;
1202+
1203+
STATIC_REQUIRE(std::ranges::contiguous_range<relation_range>);
1204+
STATIC_REQUIRE(std::ranges::sized_range<relation_range>);
1205+
STATIC_REQUIRE(std::ranges::common_range<relation_range>);
1206+
STATIC_REQUIRE(std::ranges::viewable_range<relation_range>);
1207+
STATIC_REQUIRE(std::ranges::view<relation_range>);
1208+
STATIC_REQUIRE(std::ranges::borrowed_range<relation_range>);
1209+
}
1210+
11981211
#undef DOCUMENTED_STATIC_FAILURE
11991212
#undef DOCUMENTED_FAILURE

0 commit comments

Comments
 (0)