[v1] libcamera: base: utils: join(): Don't use `const_iterator` directly
diff mbox series

Message ID 20260120144431.264758-1-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • [v1] libcamera: base: utils: join(): Don't use `const_iterator` directly
Related show

Commit Message

Barnabás Pőcze Jan. 20, 2026, 2:44 p.m. UTC
For example, `std::span` does not have a `const_iterator` typedef before
C++23, so compilation fails. Simply use `auto`, the `const` qualifier on
the `items` variable should already ensure that, if one exists, a "const"
iterator will be used.

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

Comments

Laurent Pinchart Jan. 20, 2026, 6:03 p.m. UTC | #1
On Tue, Jan 20, 2026 at 03:44:31PM +0100, Barnabás Pőcze wrote:
> For example, `std::span` does not have a `const_iterator` typedef before
> C++23, so compilation fails. Simply use `auto`, the `const` qualifier on
> the `items` variable should already ensure that, if one exists, a "const"
> iterator will be used.

What will be used with C++20, std::span::iterator ?

I'm surprised that C++20 doesn't have a const_iterator for std::span,
but as std::span<const T>::iterator is not mutable, I see no issue with
this patch.

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

> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  include/libcamera/base/utils.h | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
> index 0b7407f77..2cb8e0a88 100644
> --- a/include/libcamera/base/utils.h
> +++ b/include/libcamera/base/utils.h
> @@ -110,8 +110,7 @@ std::string join(const Container &items, const std::string &sep, UnaryOp op)
>  	std::ostringstream ss;
>  	bool first = true;
>  
> -	for (typename Container::const_iterator it = std::begin(items);
> -	     it != std::end(items); ++it) {
> +	for (auto it = std::begin(items); it != std::end(items); ++it) {
>  		if (!first)
>  			ss << sep;
>  		else
> @@ -129,8 +128,7 @@ std::string join(const Container &items, const std::string &sep)
>  	std::ostringstream ss;
>  	bool first = true;
>  
> -	for (typename Container::const_iterator it = std::begin(items);
> -	     it != std::end(items); ++it) {
> +	for (auto it = std::begin(items); it != std::end(items); ++it) {
>  		if (!first)
>  			ss << sep;
>  		else

Patch
diff mbox series

diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
index 0b7407f77..2cb8e0a88 100644
--- a/include/libcamera/base/utils.h
+++ b/include/libcamera/base/utils.h
@@ -110,8 +110,7 @@  std::string join(const Container &items, const std::string &sep, UnaryOp op)
 	std::ostringstream ss;
 	bool first = true;
 
-	for (typename Container::const_iterator it = std::begin(items);
-	     it != std::end(items); ++it) {
+	for (auto it = std::begin(items); it != std::end(items); ++it) {
 		if (!first)
 			ss << sep;
 		else
@@ -129,8 +128,7 @@  std::string join(const Container &items, const std::string &sep)
 	std::ostringstream ss;
 	bool first = true;
 
-	for (typename Container::const_iterator it = std::begin(items);
-	     it != std::end(items); ++it) {
+	for (auto it = std::begin(items); it != std::end(items); ++it) {
 		if (!first)
 			ss << sep;
 		else