Skip to content

Commit

Permalink
HeapArray: Add span returners
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed May 12, 2024
1 parent 522c2e3 commit 117e6be
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/common/heap_array.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <[email protected]>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)

#pragma once
Expand All @@ -10,6 +10,7 @@
#include <cstdlib>
#include <cstring>
#include <type_traits>
#include <span>

template<typename T, std::size_t SIZE, std::size_t ALIGNMENT = 0>
class FixedHeapArray
Expand Down Expand Up @@ -73,6 +74,9 @@ class FixedHeapArray

void swap(this_type& move) { std::swap(m_data, move.m_data); }

std::span<T, SIZE> span() { return std::span<T, SIZE>(m_data); }
std::span<const T, SIZE> cspan() const { return std::span<const T, SIZE>(m_data); }

this_type& operator=(const this_type& rhs)
{
std::copy(begin(), end(), rhs.cbegin());
Expand Down Expand Up @@ -314,6 +318,9 @@ class DynamicHeapArray
move.m_size = 0;
}

std::span<T> span() { return std::span<T>(m_data, m_size); }
std::span<const T> cspan() const { return std::span<const T>(m_data, m_size); }

this_type& operator=(const this_type& rhs)
{
assign(rhs);
Expand Down

0 comments on commit 117e6be

Please sign in to comment.