Skip to content

Commit 662f7ef

Browse files
committed
Core (LV::Buffer): Add as_span() to create std::span objects.
1 parent 836da7b commit 662f7ef

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: libvisual/libvisual/lv_buffer.h

+19
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include <libvisual/lv_intrusive_ptr.hpp>
3939
#include <memory>
40+
#include <span>
4041
#include <cstdlib>
4142

4243
namespace LV {
@@ -88,6 +89,24 @@ namespace LV {
8889
*/
8990
void destroy_content ();
9091

92+
/**
93+
* Returns an std::span that is a view of the entire buffer.
94+
*/
95+
template <typename T>
96+
std::span<T> as_span () noexcept
97+
{
98+
return {static_cast<T*> (get_data ()), get_size () / sizeof (T)};
99+
}
100+
101+
/**
102+
* Returns an std::span that is a view of the entire buffer.
103+
*/
104+
template <typename T>
105+
std::span<T const> as_span () const noexcept
106+
{
107+
return {static_cast<T const*> (get_data ()), get_size () / sizeof (T)};
108+
}
109+
91110
/**
92111
* Sets the data pair (data and its size).
93112
*

0 commit comments

Comments
 (0)