[libcamera-devel] [PATCH 3/5] provide a default fixed-sized Span constructor

Christian Rauch Rauch.Christian at gmx.de
Fri Apr 1 02:06:14 CEST 2022


The new default constructor allows to construct a fixed-sized Span via the
default constructor of its stored data type.
This prevents the construction of empty fixed-sized Spans that cannot hold
any data.

Signed-off-by: Christian Rauch <Rauch.Christian at gmx.de>
---
 include/libcamera/base/span.h | 5 +++++
 include/libcamera/controls.h  | 2 +-
 test/span.cpp                 | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/libcamera/base/span.h b/include/libcamera/base/span.h
index 88d2e3de..7a4806dc 100644
--- a/include/libcamera/base/span.h
+++ b/include/libcamera/base/span.h
@@ -112,6 +112,11 @@ public:
 	{
 	}

+	Span()
+	{
+		Span(std::array<value_type, extent>{});
+	}
+
 	explicit constexpr Span(pointer ptr, [[maybe_unused]] size_type count)
 		: data_(ptr)
 	{
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 665bcac1..de8a7770 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -167,7 +167,7 @@ public:

 		using V = typename T::value_type;
 		const V *value = reinterpret_cast<const V *>(data().data());
-		return { value, numElements_ };
+		return T{ value, numElements_ };
 	}

 #ifndef __DOXYGEN__
diff --git a/test/span.cpp b/test/span.cpp
index abf3a5d6..c37e2a66 100644
--- a/test/span.cpp
+++ b/test/span.cpp
@@ -37,7 +37,7 @@ protected:
 		 * to generate undefined behaviour.
 		 */

-		Span<int, 0>{};
+		/* Span<int, 0>{}; */
 		/* Span<int, 4>{}; */

 		Span<int, 4>{ &i[0], 4 };
--
2.25.1



More information about the libcamera-devel mailing list