From e6b4b24bb3253ae181cd51e955b263fca6bda0f6 Mon Sep 17 00:00:00 2001 From: Mateusz Jakub Fila Date: Mon, 20 Jan 2025 11:30:29 +0100 Subject: [PATCH] make `RelationRange` a view --- include/podio/RelationRange.h | 9 ++++++++- tests/unittests/std_interoperability.cpp | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/podio/RelationRange.h b/include/podio/RelationRange.h index 42f885f44..06fd87117 100644 --- a/include/podio/RelationRange.h +++ b/include/podio/RelationRange.h @@ -1,7 +1,7 @@ #ifndef PODIO_RELATIONRANGE_H #define PODIO_RELATIONRANGE_H -#include +#include #include namespace podio { @@ -57,4 +57,11 @@ class RelationRange { }; } // namespace podio +// Opt-in to view concept +template +inline constexpr bool std::ranges::enable_view> = true; +// Opt-in to borrowed_range concept +template +inline constexpr bool std::ranges::enable_borrowed_range> = true; + #endif // PODIO_RELATIONRANGE_H diff --git a/tests/unittests/std_interoperability.cpp b/tests/unittests/std_interoperability.cpp index 6f4acc890..591e92f9c 100644 --- a/tests/unittests/std_interoperability.cpp +++ b/tests/unittests/std_interoperability.cpp @@ -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 @@ -1195,5 +1197,16 @@ TEST_CASE("LinkCollection and range concepts", "[links][iterator][std]") { STATIC_REQUIRE(std::ranges::viewable_range); } +TEST_CASE("RelationRange as range", "[relations][ranges][std]") { + using relation_range = podio::RelationRange; + + STATIC_REQUIRE(std::ranges::contiguous_range); + STATIC_REQUIRE(std::ranges::sized_range); + STATIC_REQUIRE(std::ranges::common_range); + STATIC_REQUIRE(std::ranges::viewable_range); + STATIC_REQUIRE(std::ranges::view); + STATIC_REQUIRE(std::ranges::borrowed_range); +} + #undef DOCUMENTED_STATIC_FAILURE #undef DOCUMENTED_FAILURE