[v1,1/2] libcamera: base: utils: Simplify `enumerate()`
diff mbox series

Message ID 20251027105333.103186-2-barnabas.pocze@ideasonboard.com
State Accepted
Headers show
Series
  • Fix doxygen 1.15.0 issues
Related show

Commit Message

Barnabás Pőcze Oct. 27, 2025, 10:53 a.m. UTC
`std::{begin,end}()` support arrays, thus there is no need for a second
overload. The only reason it is currently needed is that the trailing
return type of the first overload uses `iterable.begin()`, which leads
to a substitution failure, so that overload is not considered.

So remove the array overload, and let CTAD deduce the `Base` template
parameter of `enumerate_adapter`, which will make things work for
arrays as well.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 include/libcamera/base/utils.h | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

Comments

Laurent Pinchart Oct. 27, 2025, 12:12 p.m. UTC | #1
On Mon, Oct 27, 2025 at 11:53:32AM +0100, Barnabás Pőcze wrote:
> `std::{begin,end}()` support arrays, thus there is no need for a second

I'd write "C-style arrays" here to differentiate it from std::array.

> overload. The only reason it is currently needed is that the trailing
> return type of the first overload uses `iterable.begin()`, which leads
> to a substitution failure, so that overload is not considered.
> 
> So remove the array overload, and let CTAD deduce the `Base` template
> parameter of `enumerate_adapter`, which will make things work for
> arrays as well.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  include/libcamera/base/utils.h | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
> index cb8caaa9ba..d32bd1cd62 100644
> --- a/include/libcamera/base/utils.h
> +++ b/include/libcamera/base/utils.h
> @@ -355,19 +355,11 @@ private:
>  } /* namespace details */
>  
>  template<typename T>
> -auto enumerate(T &iterable) -> details::enumerate_adapter<decltype(iterable.begin())>
> +auto enumerate(T &iterable)
>  {
> -	return { std::begin(iterable), std::end(iterable) };
> +	return details::enumerate_adapter{ std::begin(iterable), std::end(iterable) };
>  }
>  
> -#ifndef __DOXYGEN__
> -template<typename T, size_t N>
> -auto enumerate(T (&iterable)[N]) -> details::enumerate_adapter<T *>
> -{
> -	return { std::begin(iterable), std::end(iterable) };
> -}
> -#endif
> -
>  class Duration : public std::chrono::duration<double, std::nano>
>  {
>  	using BaseDuration = std::chrono::duration<double, std::nano>;
Kieran Bingham Oct. 27, 2025, 5:36 p.m. UTC | #2
Quoting Barnabás Pőcze (2025-10-27 10:53:32)
> `std::{begin,end}()` support arrays, thus there is no need for a second
> overload. The only reason it is currently needed is that the trailing
> return type of the first overload uses `iterable.begin()`, which leads
> to a substitution failure, so that overload is not considered.
> 
> So remove the array overload, and let CTAD deduce the `Base` template
> parameter of `enumerate_adapter`, which will make things work for
> arrays as well.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  include/libcamera/base/utils.h | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
> index cb8caaa9ba..d32bd1cd62 100644
> --- a/include/libcamera/base/utils.h
> +++ b/include/libcamera/base/utils.h
> @@ -355,19 +355,11 @@ private:
>  } /* namespace details */
>  
>  template<typename T>
> -auto enumerate(T &iterable) -> details::enumerate_adapter<decltype(iterable.begin())>
> +auto enumerate(T &iterable)
>  {
> -       return { std::begin(iterable), std::end(iterable) };
> +       return details::enumerate_adapter{ std::begin(iterable), std::end(iterable) };
>  }
>  
> -#ifndef __DOXYGEN__
> -template<typename T, size_t N>
> -auto enumerate(T (&iterable)[N]) -> details::enumerate_adapter<T *>
> -{
> -       return { std::begin(iterable), std::end(iterable) };
> -}
> -#endif
> -
>  class Duration : public std::chrono::duration<double, std::nano>
>  {
>         using BaseDuration = std::chrono::duration<double, std::nano>;
> -- 
> 2.51.1
>

Patch
diff mbox series

diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
index cb8caaa9ba..d32bd1cd62 100644
--- a/include/libcamera/base/utils.h
+++ b/include/libcamera/base/utils.h
@@ -355,19 +355,11 @@  private:
 } /* namespace details */
 
 template<typename T>
-auto enumerate(T &iterable) -> details::enumerate_adapter<decltype(iterable.begin())>
+auto enumerate(T &iterable)
 {
-	return { std::begin(iterable), std::end(iterable) };
+	return details::enumerate_adapter{ std::begin(iterable), std::end(iterable) };
 }
 
-#ifndef __DOXYGEN__
-template<typename T, size_t N>
-auto enumerate(T (&iterable)[N]) -> details::enumerate_adapter<T *>
-{
-	return { std::begin(iterable), std::end(iterable) };
-}
-#endif
-
 class Duration : public std::chrono::duration<double, std::nano>
 {
 	using BaseDuration = std::chrono::duration<double, std::nano>;