Skip to content

Commit

Permalink
Core (LV::Buffer): Add as_span() to create std::span objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaixiong committed Mar 31, 2023
1 parent 05ff710 commit 8326bc0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions libvisual/libvisual/lv_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <libvisual/lv_intrusive_ptr.hpp>
#include <memory>
#include <span>
#include <cstdlib>

namespace LV {
Expand Down Expand Up @@ -88,6 +89,24 @@ namespace LV {
*/
void destroy_content ();

/**
* Returns an std::span that is a view of the entire buffer.
*/
template <typename T>
std::span<T> as_span () noexcept
{
return {static_cast<T*> (get_data ()), get_size () / sizeof (T)};
}

/**
* Returns an std::span that is a view of the entire buffer.
*/
template <typename T>
std::span<T const> as_span () const noexcept
{
return {static_cast<T const*> (get_data ()), get_size () / sizeof (T)};
}

/**
* Sets the data pair (data and its size).
*
Expand Down

0 comments on commit 8326bc0

Please sign in to comment.