[libcamera-devel] [PATCH v2 3/5] provide a default fixed-sized Span constructor
Christian Rauch
Rauch.Christian at gmx.de
Wed Apr 6 01:22:07 CEST 2022
Hi Laurent,
If we can only default-construct a Span that is either 0-fixed-sized or
variable-sized, and we want to return default-constructed objects to
indicate errors, then it is not possible to use N-fixed-size Spans.
We either have to use a Span type that supports N-fixed-sized
default-construction, or the default-construction of types has to be
avoided. If having feature/behaviour comparability with std::span is a
high priority, then only the option that avoids default-construction is
left.
Best,
Christian
Am 05.04.22 um 17:27 schrieb Laurent Pinchart:
> Hi Christian,
>
> Thank you for the patch.
>
> On Tue, Apr 05, 2022 at 01:42:13AM +0100, Christian Rauch via libcamera-devel wrote:
>> This allows to construct empty 0-fixed-sized Spans.
>>
>> Signed-off-by: Christian Rauch <Rauch.Christian at gmx.de>
>> ---
>> include/libcamera/base/span.h | 2 --
>> include/libcamera/controls.h | 2 +-
>> 2 files changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/include/libcamera/base/span.h b/include/libcamera/base/span.h
>> index 88d2e3de..bff4c115 100644
>> --- a/include/libcamera/base/span.h
>> +++ b/include/libcamera/base/span.h
>> @@ -105,8 +105,6 @@ public:
>>
>> static constexpr std::size_t extent = Extent;
>>
>> - template<bool Dependent = false,
>> - typename = std::enable_if_t<Dependent || Extent == 0>>
>
> The issue here is that the std::span class has this constraint ([1]):
>
> This overload participates in overload resolution only if
> extent == 0 || extent == std::dynamic_extent.
>
> [1] https://en.cppreference.com/w/cpp/container/span/span
>
> If we drop the constraint here, we will have an issue when switching to
> std::span in the future. Is there a way we could achieve the result
> you're aiming for without this change ?
>
>> constexpr Span() noexcept
>> : data_(nullptr)
>> {
>> 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__
>
More information about the libcamera-devel
mailing list