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
33 template<typename FunctionType,typename IteratorType>
35 {
38 public:
39
40 VectorConvertIterator (const FunctionType& val_function, IteratorType&& val_iterator)
41 : m_function (val_function), m_iterator (std::move (val_iterator))
42 {}
43
44 [[nodiscard]] bool operator == (const VectorConvertIterator& that) const noexcept {
45 return m_iterator == that.m_iterator;}
46 [[nodiscard]] bool operator != (const VectorConvertIterator& that) const noexcept {
47 return m_iterator != that.m_iterator;}
48
50 ++ m_iterator; return *this;}
51
52 [[nodiscard]] decltype(auto) operator * () const noexcept {
53 return m_function (*m_iterator);}
54
57 private:
58
59 [[no_unique_address]] FunctionType m_function;
60 IteratorType m_iterator;
61 };
62 template<typename FunctionType,typename IteratorType> VectorConvertIterator (FunctionType&&,IteratorType&&) -> VectorConvertIterator<std::decay_t<FunctionType>,std::decay_t<IteratorType>>;
63
64
65
67 template<typename FunctionType,typename ViewType>
69 {
72 public:
73
74 explicit VectorConvertView (const FunctionType& val_function, const ViewType& val_view) noexcept
75 : m_function (val_function), m_view (val_view)
76 {}
77
78 [[nodiscard]] std::size_t size () const noexcept
79 {
80 return m_view.size();
81 }
82
83 [[nodiscard]] decltype(auto) operator[] (std::size_t index) const
84 {
85 if (index >= m_view.size()) [[unlikely]]
86 throw std::out_of_range ("VectorConvertView::operator[]: index out of range");
87 return m_function (m_view[index]);
88 }
89
90 [[nodiscard]] auto begin () const noexcept
91 {
92 return VectorConvertIterator (m_function, m_view.begin());
93 }
94
95 [[nodiscard]] auto end () const noexcept
96 {
98 }
99
102 private:
103
104 [[no_unique_address]] FunctionType m_function;
106 };
107 template<typename FunctionType,typename ViewType> VectorConvertView (FunctionType&&,ViewType&&) -> VectorConvertView<std::decay_t<FunctionType>,std::decay_t<ViewType>>;
108 }
109}
110
111#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
VectorConvertIterator(FunctionType &&, IteratorType &&) -> VectorConvertIterator< std::decay_t< FunctionType >, std::decay_t< IteratorType > >
VectorConvertView(FunctionType &&, ViewType &&) -> VectorConvertView< std::decay_t< FunctionType >, std::decay_t< ViewType > >
Definition index.py:1
STL namespace.
#define unlikely(x)