Go to the documentation of this file.
15 #ifndef BELUGA_CONTAINERS_CIRCULAR_ARRAY_HPP
16 #define BELUGA_CONTAINERS_CIRCULAR_ARRAY_HPP
22 #include <type_traits>
48 static_cast<std::underlying_type_t<CircularArrayFeatureFlags>
>(lflag) |
49 static_cast<std::underlying_type_t<CircularArrayFeatureFlags>
>(rflag));
54 return static_cast<bool>(
55 static_cast<std::underlying_type_t<CircularArrayFeatureFlags>
>(mask) &
56 static_cast<std::underlying_type_t<CircularArrayFeatureFlags>
>(flag));
75 template <
typename T, std::
size_t N, CircularArrayFeatureFlags F = CircularArrayFeatureFlags::kNone>
125 typename = std::enable_if_t<std::is_same_v<T, typename std::iterator_traits<Iterator>::value_type>>>
134 throw std::length_error{
"Range does not fit in circular array"};
138 const auto n =
static_cast<size_type>(std::distance(first, last));
141 throw std::length_error{
"Range does not fit in circular array"};
143 std::advance(first, n - N);
162 template <std::
size_t M,
typename = std::enable_if_t<M >= 1 && M <= N>>
165 for (std::size_t i = 0; i < M; ++i)
168 for (std::size_t i = 0; i < M; ++i)
208 template <
bool Enabled = !(F & CircularArrayFeatureFlags::kLayoutReversal)>
212 "Cannot push_back() when the layout reversal feature is enabled.");
215 throw std::length_error{
"Circular array reached its maximum size"};
231 template <
bool Enabled = (F & CircularArrayFeatureFlags::kLayoutReversal)>
235 "Cannot push_front() when the layout reversal feature is not enabled.");
238 throw std::length_error{
"Circular array reached its maximum size"};
253 template <
bool Enabled = (F & CircularArrayFeatureFlags::kLayoutReversal)>
264 template <
bool Enabled = !(F & CircularArrayFeatureFlags::kLayoutReversal)>
322 throw std::out_of_range{
"Index out of circular array range"};
324 return (*
this)[index];
333 throw std::out_of_range{
"Index out of circular array range"};
335 return (*
this)[index];
356 index = std::min(index,
size_ - 1);
392 template <CircularArrayFeatureFlags G>
400 template <
typename U, std::
size_t M, CircularArrayFeatureFlags G>
408 [[nodiscard]] constexpr T*
data() noexcept {
return data_.data(); }
415 [[nodiscard]] constexpr
const T*
data() const noexcept {
return data_.data(); }
418 [[nodiscard]] constexpr
bool full() const noexcept {
return size_ == N; }
421 [[nodiscard]] constexpr
bool empty() const noexcept {
return size_ == 0U; }
460 template <
typename T, std::
size_t N>
472 template <
typename T, std::
size_t N, CircularArrayFeatureFlags F>
486 template <std::
size_t I,
class T, std::
size_t N, CircularArrayFeatureFlags F>
495 template <std::
size_t I,
class T, std::
size_t N, CircularArrayFeatureFlags F>
504 template <std::
size_t I,
class T, std::
size_t N, CircularArrayFeatureFlags F>
513 template <std::
size_t I,
class T, std::
size_t N, CircularArrayFeatureFlags F>
522 template <
typename T, std::
size_t N, CircularArrayFeatureFlags F, CircularArrayFeatureFlags G>
532 template <
typename T, std::
size_t N, beluga::CircularArrayFeatureFlags F>
533 struct tuple_size<
beluga::CircularArray<T, N, F>> : std::integral_constant<std::size_t, N> {};
536 template <std::
size_t I,
typename T, std::
size_t N, beluga::CircularArrayFeatureFlags F>
537 struct tuple_element<I,
beluga::CircularArray<T, N, F>> {
constexpr const_iterator begin() const noexcept
Returns a constant iterator pointing to the front of the array.
friend class CircularArray
constexpr T & get(CircularArray< T, N, F > &array) noexcept
Gets an lvalue reference to the ith value in a given array.
constexpr const_reference back() const noexcept
Returns a constant reference to the value at the back of the array.
constexpr const_iterator end() const noexcept
Returns a constant iterator pointing past the back of the array.
constexpr bool empty() const noexcept
Returns true if the array is empty, false otherwise.
CircularArray(Iterator first, Sentinel last)
Constructs array from a pair of iterators.
constexpr void swap(CircularArray< T, N, F > &a, CircularArray< T, N, G > &b)
Swaps arrays a and b.
constexpr bool full() const noexcept
Returns true if the array is full, false otherwise.
void allocator_type
Allocator type of the array (required in range-v3 10.0).
T type
! Always T since circular arrays are homogeneous.
constexpr CircularArrayFeatureFlags operator|(CircularArrayFeatureFlags lflag, CircularArrayFeatureFlags rflag)
Bitwise OR operator overload to combine two feature flags in a single mask-like flag.
std::enable_if_t< Enabled > pop_front() noexcept
Pops a value from the front of the array.
constexpr iterator end() noexcept
Returns an iterator pointing past the back of the array.
std::enable_if_t< Enabled > push_front(value_type value)
Pushes a value at the front of the array.
const value_type & const_reference
Constant value reference type of the array.
void swap(CircularArray< T, N, G > &other) noexcept(std::is_nothrow_swappable_v< T >)
Swaps array with another.
constexpr const_reverse_iterator crend() const noexcept
Returns a constant reverse iterator pointing past the front of the array.
constexpr size_type size() const noexcept
Returns the current array size.
constexpr const_iterator cend() const noexcept
Returns a constant iterator pointing past the back of the array.
constexpr reference operator[](size_type index) noexcept
Returns a reference to the array value at the given index.
constexpr reference front() noexcept
Returns a reference to the value at the front of the array.
constexpr const_reverse_iterator crbegin() const noexcept
Returns a constant reverse iterator pointing to the back of the array.
value_type & reference
Value reference type of the array.
CircularArray< T, N, F > & operator<<(CircularArray< T, N, F > &array, T value)
Convenient stream operator overload to push a value to a circular array.
constexpr reference at(size_type index)
Returns a reference to the array value at the given index.
constexpr const_reference operator[](size_type index) const noexcept
Returns a constant reference to the array value at the given index.
A random access iterator for any indexable container.
CircularArray< T, N, CircularArrayFeatureFlags::kRolloverOnWrite|CircularArrayFeatureFlags::kExtrapolateOnRead|CircularArrayFeatureFlags::kLayoutReversal > RollingWindow
Convenient type alias for a circular array that behaves like a rolling window.
constexpr const T * data() const noexcept
Returns a constant pointer to the underlying array data.
constexpr size_type max_size() const noexcept
Returns the maximum array size.
CircularArrayFeatureFlags
Feature flags for circular arrays.
An implementation of generic, non-threadsafe circular array.
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator type of the array.
std::enable_if_t< Enabled > pop_back() noexcept
Pops a value from the back of the array.
std::size_t size_type
Size type of the array.
Implementation of a random access iterator for indexable containers.
constexpr reference back() noexcept
Returns a reference to the value at the back of the array.
constexpr const_iterator cbegin() const noexcept
Returns a constant iterator pointing to the front of the array.
constexpr T * data() noexcept
Returns a pointer to the underlying array data.
std::ptrdiff_t difference_type
Size difference type of the array.
state_type value_type
Value type of the array.
constexpr size_type effective_size() const noexcept
Returns the effective array size.
constexpr bool operator&(CircularArrayFeatureFlags mask, CircularArrayFeatureFlags flag)
Bitwise AND operator overload to check of the presence of a feature flag in a feature mask.
const value_type * const_pointer
Constant value pointer type of the arra.y.
constexpr const_reference at(size_type index) const
Returns a constant reference to the array value at the given index.
void fill(const T &value)
Fills array to its maximum size with a given value.
IndexingIterator< CircularArray< T, N, F > > iterator
Iterator type of the array.
CircularArray(T(&&data)[M])
Constructs array from an aggregate.
void clear() noexcept
Clears array.
std::reverse_iterator< const_iterator > const_reverse_iterator
Constant reverse iterator type of the array.
IndexingIterator< const CircularArray< T, N, F > > const_iterator
Constant iterator type of the array.
constexpr iterator begin() noexcept
Returns an iterator pointing to the front of the array.
constexpr const_reverse_iterator rend() const noexcept
Returns a constant reverse iterator pointing past the front of the array.
constexpr reverse_iterator rend() noexcept
Returns a reverse iterator pointing past the front of the array.
constexpr reverse_iterator rbegin() noexcept
Returns a reverse iterator pointing to the back of the array.
constexpr size_type head_index() const noexcept
std::enable_if_t< Enabled > push_back(value_type value)
Pushes a value to the back of the array.
value_type * pointer
Value pointer type of the array.
constexpr const_reference front() const noexcept
Returns a constant reference to the value at the front of the array.
The main Beluga namespace.
constexpr const_reverse_iterator rbegin() const noexcept
Returns a constant reverse iterator pointing to the back of the array.
beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53