[v2] libcamera: bound_method: Use std::apply
diff mbox series

Message ID 20260511111121.3042550-1-laurent.pinchart@ideasonboard.com
State New
Headers show
Series
  • [v2] libcamera: bound_method: Use std::apply
Related show

Commit Message

Laurent Pinchart May 11, 2026, 11:11 a.m. UTC
Now that libcamera uses C++17, we can use std::apply to replace the
custom implementation.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
Changes since v1:

- Drop private invokePack() overload
- Use lambda function and std::move() to avoid copy
---
 include/libcamera/base/bound_method.h | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)


base-commit: 500c2320619a47bd01d1ffe69ca4cc6eae6e00e8

Comments

Barnabás Pőcze May 11, 2026, 12:20 p.m. UTC | #1
2026. 05. 11. 13:11 keltezéssel, Laurent Pinchart írta:
> Now that libcamera uses C++17, we can use std::apply to replace the
> custom implementation.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> Changes since v1:
> 
> - Drop private invokePack() overload
> - Use lambda function and std::move() to avoid copy
> ---

Looks ok to me.

Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>


>   include/libcamera/base/bound_method.h | 22 ++++++++--------------
>   1 file changed, 8 insertions(+), 14 deletions(-)
> 
> diff --git a/include/libcamera/base/bound_method.h b/include/libcamera/base/bound_method.h
> index 9b42a8a1e8ca..f11159e8a0a4 100644
> --- a/include/libcamera/base/bound_method.h
> +++ b/include/libcamera/base/bound_method.h
> @@ -90,25 +90,19 @@ class BoundMethodArgs : public BoundMethodBase
>   public:
>   	using PackType = BoundMethodPack<R, Args...>;
>   
> -private:
> -	template<std::size_t... I>
> -	void invokePack(BoundMethodPackBase *pack, std::index_sequence<I...>)
> -	{
> -		[[maybe_unused]] auto *args = static_cast<PackType *>(pack);
> -
> -		if constexpr (!std::is_void_v<R>)
> -			args->ret_ = invoke(std::forward<Args>(std::get<I>(args->args_))...);
> -		else
> -			invoke(std::forward<Args>(std::get<I>(args->args_))...);
> -	}
> -
> -public:
>   	BoundMethodArgs(void *obj, Object *object, ConnectionType type)
>   		: BoundMethodBase(obj, object, type) {}
>   
>   	void invokePack(BoundMethodPackBase *pack) override
>   	{
> -		invokePack(pack, std::make_index_sequence<sizeof...(Args)>{});
> +		auto *argsPack = static_cast<PackType *>(pack);
> +
> +		std::apply([&](Args &&...args) {
> +			if constexpr (!std::is_void_v<R>)
> +				argsPack->ret_ = invoke(std::forward<decltype(args)>(args)...);
> +			else
> +				invoke(std::forward<decltype(args)>(args)...);
> +		}, std::move(argsPack->args_));
>   	}
>   
>   	virtual R activate(Args... args, bool deleteMethod = false) = 0;
> 
> base-commit: 500c2320619a47bd01d1ffe69ca4cc6eae6e00e8

Patch
diff mbox series

diff --git a/include/libcamera/base/bound_method.h b/include/libcamera/base/bound_method.h
index 9b42a8a1e8ca..f11159e8a0a4 100644
--- a/include/libcamera/base/bound_method.h
+++ b/include/libcamera/base/bound_method.h
@@ -90,25 +90,19 @@  class BoundMethodArgs : public BoundMethodBase
 public:
 	using PackType = BoundMethodPack<R, Args...>;
 
-private:
-	template<std::size_t... I>
-	void invokePack(BoundMethodPackBase *pack, std::index_sequence<I...>)
-	{
-		[[maybe_unused]] auto *args = static_cast<PackType *>(pack);
-
-		if constexpr (!std::is_void_v<R>)
-			args->ret_ = invoke(std::forward<Args>(std::get<I>(args->args_))...);
-		else
-			invoke(std::forward<Args>(std::get<I>(args->args_))...);
-	}
-
-public:
 	BoundMethodArgs(void *obj, Object *object, ConnectionType type)
 		: BoundMethodBase(obj, object, type) {}
 
 	void invokePack(BoundMethodPackBase *pack) override
 	{
-		invokePack(pack, std::make_index_sequence<sizeof...(Args)>{});
+		auto *argsPack = static_cast<PackType *>(pack);
+
+		std::apply([&](Args &&...args) {
+			if constexpr (!std::is_void_v<R>)
+				argsPack->ret_ = invoke(std::forward<decltype(args)>(args)...);
+			else
+				invoke(std::forward<decltype(args)>(args)...);
+		}, std::move(argsPack->args_));
 	}
 
 	virtual R activate(Args... args, bool deleteMethod = false) = 0;