ATLAS Offline Software
Loading...
Searching...
No Matches
VectorConvertView.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8#ifndef COLUMNAR_CORE_VECTOR_CONVERT_VIEW_H
9#define COLUMNAR_CORE_VECTOR_CONVERT_VIEW_H
10
11#include <cstddef> //std::size_t
12#include <stdexcept> //std::out_of_range
13#include <utility> //for std::move
14
15namespace columnar
16{
17 namespace detail
18 {
30
31
37 [[noreturn]] [[gnu::cold]] [[gnu::noinline]] inline void throwVectorConvertViewOutOfRange ()
38 {
39 throw std::out_of_range ("VectorConvertView::operator[]: index out of range");
40 }
41
42
44 template<typename FunctionType,typename IteratorType>
46 {
49 public:
50
51 VectorConvertIterator (const FunctionType& val_function, IteratorType&& val_iterator)
52 : m_function (val_function), m_iterator (std::move (val_iterator))
53 {}
54
55 [[nodiscard]] bool operator == (const VectorConvertIterator& that) const noexcept {
56 return m_iterator == that.m_iterator;}
57 [[nodiscard]] bool operator != (const VectorConvertIterator& that) const noexcept {
58 return m_iterator != that.m_iterator;}
59
61 ++ m_iterator; return *this;}
62
63 [[nodiscard]] decltype(auto) operator * () const {
64 return m_function (*m_iterator);}
65
68 private:
69
70 [[no_unique_address]] FunctionType m_function;
71 IteratorType m_iterator;
72 };
73 template<typename FunctionType,typename IteratorType> VectorConvertIterator (FunctionType&&,IteratorType&&) -> VectorConvertIterator<std::decay_t<FunctionType>,std::decay_t<IteratorType>>;
74
75
76
78 template<typename FunctionType,typename ViewType>
80 {
83 public:
84
85 explicit VectorConvertView (const FunctionType& val_function, const ViewType& val_view) noexcept
86 : m_function (val_function), m_view (val_view)
87 {}
88
89 [[nodiscard]] std::size_t size () const noexcept
90 {
91 return m_view.size();
92 }
93
94 [[nodiscard]] decltype(auto) operator[] (std::size_t index) const
95 {
96 if (index >= m_view.size()) [[unlikely]]
98 return m_function (m_view[index]);
99 }
100
101 [[nodiscard]] auto begin () const noexcept
102 {
103 return VectorConvertIterator (m_function, m_view.begin());
104 }
105
106 [[nodiscard]] auto end () const noexcept
107 {
109 }
110
113 private:
114
115 [[no_unique_address]] FunctionType m_function;
117 };
118 template<typename FunctionType,typename ViewType> VectorConvertView (FunctionType&&,ViewType&&) -> VectorConvertView<std::decay_t<FunctionType>,std::decay_t<ViewType>>;
119 }
120}
121
122#endif
ViewType
Definition RPCdef.h:8
an iterator that does converts members using a passed in function
bool operator==(const VectorConvertIterator &that) const noexcept
VectorConvertIterator & operator++() noexcept
VectorConvertIterator(const FunctionType &val_function, IteratorType &&val_iterator)
bool operator!=(const VectorConvertIterator &that) const noexcept
a range view that does converts members using a passed in function
std::size_t size() const noexcept
VectorConvertView(const FunctionType &val_function, const ViewType &val_view) noexcept
Container id definitions for the columnar infrastructure.
VectorConvertIterator(FunctionType &&, IteratorType &&) -> VectorConvertIterator< std::decay_t< FunctionType >, std::decay_t< IteratorType > >
void throwVectorConvertViewOutOfRange()
throw the exception for an out-of-range index
VectorConvertView(FunctionType &&, ViewType &&) -> VectorConvertView< std::decay_t< FunctionType >, std::decay_t< ViewType > >
Definition index.py:1
STL namespace.
#define unlikely(x)