ATLAS Offline Software
Loading...
Searching...
No Matches
VectorConvertView.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
12
13namespace columnar
14{
15 namespace detail
16 {
28
29
31 template<typename FunctionType,typename IteratorType>
33 {
36 public:
37
38 VectorConvertIterator (const FunctionType& val_function, IteratorType&& val_iterator)
39 : m_function (val_function), m_iterator (std::move (val_iterator))
40 {}
41
42 [[nodiscard]] bool operator == (const VectorConvertIterator& that) const noexcept {
43 return m_iterator == that.m_iterator;}
44 [[nodiscard]] bool operator != (const VectorConvertIterator& that) const noexcept {
45 return m_iterator != that.m_iterator;}
46
48 ++ m_iterator; return *this;}
49
50 [[nodiscard]] decltype(auto) operator * () const noexcept {
51 return m_function (*m_iterator);}
52
55 private:
56
57 [[no_unique_address]] FunctionType m_function;
58 IteratorType m_iterator;
59 };
60 template<typename FunctionType,typename IteratorType> VectorConvertIterator (FunctionType&&,IteratorType&&) -> VectorConvertIterator<std::remove_cv_t<FunctionType>,std::remove_cv_t<IteratorType>>;
61
62
63
65 template<typename FunctionType,typename ViewType>
67 {
70 public:
71
72 explicit VectorConvertView (const FunctionType& val_function, const ViewType& val_view) noexcept
73 : m_function (val_function), m_view (val_view)
74 {}
75
76 [[nodiscard]] std::size_t size () const noexcept
77 {
78 return m_view.size();
79 }
80
81 [[nodiscard]] decltype(auto) operator[] (std::size_t index) const
82 {
83 if (index >= m_view.size()) [[unlikely]]
84 throw std::out_of_range ("VectorConvertView::operator[]: index out of range");
85 return m_function (m_view[index]);
86 }
87
88 [[nodiscard]] auto begin () const noexcept
89 {
90 return VectorConvertIterator (m_function, m_view.begin());
91 }
92
93 [[nodiscard]] auto end () const noexcept
94 {
96 }
97
100 private:
101
102 [[no_unique_address]] FunctionType m_function;
104 };
105 template<typename FunctionType,typename ViewType> VectorConvertView (FunctionType&&,ViewType&&) -> VectorConvertView<std::remove_cv_t<FunctionType>,std::remove_cv_t<ViewType>>;
106 }
107}
108
109#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
#define unlikely(x)
Definition dictionary.h:41
VectorConvertIterator(FunctionType &&, IteratorType &&) -> VectorConvertIterator< std::remove_cv_t< FunctionType >, std::remove_cv_t< IteratorType > >
VectorConvertView(FunctionType &&, ViewType &&) -> VectorConvertView< std::remove_cv_t< FunctionType >, std::remove_cv_t< ViewType > >
Definition index.py:1
STL namespace.