Skip to content

Commit 117e6be

Browse files
committed
HeapArray: Add span returners
1 parent 522c2e3 commit 117e6be

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/common/heap_array.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <[email protected]>
1+
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
22
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
33

44
#pragma once
@@ -10,6 +10,7 @@
1010
#include <cstdlib>
1111
#include <cstring>
1212
#include <type_traits>
13+
#include <span>
1314

1415
template<typename T, std::size_t SIZE, std::size_t ALIGNMENT = 0>
1516
class FixedHeapArray
@@ -73,6 +74,9 @@ class FixedHeapArray
7374

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

77+
std::span<T, SIZE> span() { return std::span<T, SIZE>(m_data); }
78+
std::span<const T, SIZE> cspan() const { return std::span<const T, SIZE>(m_data); }
79+
7680
this_type& operator=(const this_type& rhs)
7781
{
7882
std::copy(begin(), end(), rhs.cbegin());
@@ -314,6 +318,9 @@ class DynamicHeapArray
314318
move.m_size = 0;
315319
}
316320

321+
std::span<T> span() { return std::span<T>(m_data, m_size); }
322+
std::span<const T> cspan() const { return std::span<const T>(m_data, m_size); }
323+
317324
this_type& operator=(const this_type& rhs)
318325
{
319326
assign(rhs);

0 commit comments

Comments
 (0)