From 8326bc05d9c6c6430c3f95310dfe54ec16fd8eea Mon Sep 17 00:00:00 2001 From: Chong Kai Xiong Date: Sat, 4 Mar 2023 23:41:33 +0800 Subject: [PATCH] Core (LV::Buffer): Add as_span() to create std::span objects. --- libvisual/libvisual/lv_buffer.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libvisual/libvisual/lv_buffer.h b/libvisual/libvisual/lv_buffer.h index 8f6a3f728..9eca7b15d 100644 --- a/libvisual/libvisual/lv_buffer.h +++ b/libvisual/libvisual/lv_buffer.h @@ -37,6 +37,7 @@ #include #include +#include #include namespace LV { @@ -88,6 +89,24 @@ namespace LV { */ void destroy_content (); + /** + * Returns an std::span that is a view of the entire buffer. + */ + template + std::span as_span () noexcept + { + return {static_cast (get_data ()), get_size () / sizeof (T)}; + } + + /** + * Returns an std::span that is a view of the entire buffer. + */ + template + std::span as_span () const noexcept + { + return {static_cast (get_data ()), get_size () / sizeof (T)}; + } + /** * Sets the data pair (data and its size). *