[libcamera-devel,v2,3/5] provide a default fixed-sized Span constructor
diff mbox series

Message ID 20220405004215.86340-4-Rauch.Christian@gmx.de
State Superseded
Headers show
Series
  • generate and use fixed-sized Span Control types
Related show

Commit Message

Christian Rauch April 5, 2022, 12:42 a.m. UTC
This allows to construct empty 0-fixed-sized Spans.

Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>
---
 include/libcamera/base/span.h | 2 --
 include/libcamera/controls.h  | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

--
2.25.1

Comments

Laurent Pinchart April 5, 2022, 4:27 p.m. UTC | #1
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@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__
Christian Rauch April 5, 2022, 11:22 p.m. UTC | #2
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@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__
>

Patch
diff mbox series

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>>
 	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__