Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ref_span.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <iterator>
5
6#include "ref_array.hpp"
7#include "ref_vector.hpp"
8
9namespace bb {
10
11template <typename T> class RefSpan {
12 public:
13 // Default constructor
15 : storage(nullptr)
16 , array_size(0)
17 {}
18
19 template <std::size_t Size>
20 RefSpan(const RefArray<T, Size>& ref_array)
21 : storage(ref_array.get_storage())
22 , array_size(Size)
23 {}
24 RefSpan(const RefVector<T>& ref_vector)
25 : storage(&ref_vector.get_storage()[0])
26 , array_size(ref_vector.size())
27 {}
28
29 // Constructor from an array of pointers and size
30 RefSpan(T** ptr_array, std::size_t size)
31 : storage(ptr_array)
33 {}
34
35 // Copy constructor
36 RefSpan(const RefSpan& other) = default;
37
38 // Move constructor
39 RefSpan(RefSpan&& other) noexcept = default;
40
41 // Destructor
42 ~RefSpan() = default;
43
44 // Copy assignment operator
45 RefSpan& operator=(const RefSpan& other) = default;
46
47 // Move assignment operator
48 RefSpan& operator=(RefSpan&& other) noexcept = default;
49
50 // Access element at index
51 T& operator[](std::size_t idx) const
52 {
53 // Assuming the caller ensures idx is within bounds.
54 return *storage[idx];
55 }
56
57 // Get size of the RefSpan
58 constexpr std::size_t size() const { return array_size; }
59
60 // Iterator implementation
61 class iterator {
62 public:
64 : array(array)
65 , pos(pos)
66 {}
67
68 T& operator*() const { return *(array[pos]); }
69
71 {
72 ++pos;
73 return *this;
74 }
75
77 {
78 iterator temp = *this;
79 ++(*this);
80 return temp;
81 }
82
83 bool operator==(const iterator& other) const { return pos == other.pos; }
84 bool operator!=(const iterator& other) const { return pos != other.pos; }
85
86 private:
87 T* const* array;
89 };
90
91 // Begin and end for iterator support
92 iterator begin() const { return iterator(storage, 0); }
93 iterator end() const { return iterator(storage, array_size); }
94
95 private:
96 T* const* storage;
98};
99
100} // namespace bb
A template class for a reference array. Behaves as if std::array<T&, N> was possible.
Definition ref_array.hpp:22
iterator & operator++()
Definition ref_span.hpp:70
bool operator!=(const iterator &other) const
Definition ref_span.hpp:84
iterator(T *const *array, std::size_t pos)
Definition ref_span.hpp:63
iterator operator++(int)
Definition ref_span.hpp:76
bool operator==(const iterator &other) const
Definition ref_span.hpp:83
T & operator*() const
Definition ref_span.hpp:68
~RefSpan()=default
std::size_t array_size
Definition ref_span.hpp:97
T & operator[](std::size_t idx) const
Definition ref_span.hpp:51
iterator end() const
Definition ref_span.hpp:93
iterator begin() const
Definition ref_span.hpp:92
T *const * storage
Definition ref_span.hpp:96
RefSpan(const RefVector< T > &ref_vector)
Definition ref_span.hpp:24
RefSpan & operator=(const RefSpan &other)=default
RefSpan(const RefArray< T, Size > &ref_array)
Definition ref_span.hpp:20
RefSpan(T **ptr_array, std::size_t size)
Definition ref_span.hpp:30
RefSpan & operator=(RefSpan &&other) noexcept=default
constexpr std::size_t size() const
Definition ref_span.hpp:58
RefSpan(RefSpan &&other) noexcept=default
RefSpan(const RefSpan &other)=default
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13