From 36ae3d544578432c1a6c58f972ac7690e1ecc937 Mon Sep 17 00:00:00 2001 From: Gerhard Raven Date: Mon, 22 Sep 2025 20:05:59 +0200 Subject: [PATCH] Make TrackCompactVertex' decayProducts satisfy std::ranges::viewable_range --- .../include/TrackKernel/TrackCompactVertex.h | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Tr/TrackKernel/include/TrackKernel/TrackCompactVertex.h b/Tr/TrackKernel/include/TrackKernel/TrackCompactVertex.h index 023b23ae857..24b67b5374d 100644 --- a/Tr/TrackKernel/include/TrackKernel/TrackCompactVertex.h +++ b/Tr/TrackKernel/include/TrackKernel/TrackCompactVertex.h @@ -230,27 +230,38 @@ namespace LHCb { friend auto decayProducts( const TrackCompactVertex& vtx ) { struct children_t { TrackCompactVertex const* vtx; - struct Sentinel {}; - struct Proxy { - bool operator!=( Sentinel ) const { return i != vtx->numChildren(); } - TrackCompactVertex const* vtx; - unsigned i; - Proxy& operator++() { + struct iterator_t { + using difference_type [[maybe_unused]] = std::ptrdiff_t; + using value_type [[maybe_unused]] = iterator_t; + using iterator_concept [[maybe_unused]] = std::input_iterator_tag; + using iterator_category [[maybe_unused]] = std::input_iterator_tag; + + TrackCompactVertex const* vtx = nullptr; + unsigned i = -1; + iterator_t& operator++() { ++i; return *this; } + iterator_t operator++( int ) { + auto i = *this; + ++*this; + return i; + } const auto& operator*() const { return *this; } + bool operator==( std::default_sentinel_t ) const { return !vtx || i == vtx->numChildren(); } // hack - hack -- client code sofar only needs mag2 of a vector.... // so instead we need another customization point which default to returning threeMomentum(x).mag2()... auto threeMomentum() const { return LHCb::LinAlg::Vec{ 0, 0, vtx->daughters.P( i ) }; } }; - Proxy begin() const { return { vtx, 0 }; } - Sentinel end() const { return {}; } - Proxy operator[]( unsigned i ) { return { vtx, i }; } - auto size() const { return vtx->numChildren(); } + static_assert( std::input_iterator ); + iterator_t begin() { return { vtx, 0 }; } + std::default_sentinel_t end() { return {}; } + iterator_t operator[]( unsigned i ) { return { vtx, i }; } + auto size() const { return vtx->numChildren(); } }; + static_assert( std::ranges::viewable_range ); return children_t{ &vtx }; } -- GitLab