[libcamera-devel] libcamera: v4l2_device: Fix operator= definition

Message ID 20190127144152.9154-1-jacopo@jmondi.org
State Accepted
Headers show
Series
  • [libcamera-devel] libcamera: v4l2_device: Fix operator= definition
Related show

Commit Message

Jacopo Mondi Jan. 27, 2019, 2:41 p.m. UTC
While the C++ allows the redefinition of operator= to return an
arbitrary type, it is customary to return a reference to the assigned
value type.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/include/v4l2_device.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.20.1

Comments

Jacopo Mondi Jan. 27, 2019, 2:44 p.m. UTC | #1
On Sun, Jan 27, 2019 at 03:41:52PM +0100, Jacopo Mondi wrote:
> While the C++ allows the redefinition of operator= to return an

C++ "standard"

Will eventually fix when pushing.

> arbitrary type, it is customary to return a reference to the assigned
> value type.
>
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  src/libcamera/include/v4l2_device.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
> index 413bb7f..c67ebbf 100644
> --- a/src/libcamera/include/v4l2_device.h
> +++ b/src/libcamera/include/v4l2_device.h
> @@ -62,7 +62,7 @@ public:
>  	V4L2Device(const V4L2Device &) = delete;
>  	~V4L2Device();
>
> -	void operator=(const V4L2Device &) = delete;
> +	V4L2Device &operator=(const V4L2Device &) = delete;
>
>  	int open();
>  	bool isOpen() const;
> --
> 2.20.1
>
Laurent Pinchart Jan. 27, 2019, 4:09 p.m. UTC | #2
Hi Jacopo,

On Sun, Jan 27, 2019 at 03:41:52PM +0100, Jacopo Mondi wrote:
> While the C++ allows the redefinition of operator= to return an
> arbitrary type, it is customary to return a reference to the assigned
> value type.

It's a bit more than customary, as you wouldn't be able to write

	a = b = c;

otherwise. In any case the operator= can't be used if you declarate a
deleted operator, regardless of the return type, so this is fine.

> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

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

> ---
>  src/libcamera/include/v4l2_device.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
> index 413bb7f..c67ebbf 100644
> --- a/src/libcamera/include/v4l2_device.h
> +++ b/src/libcamera/include/v4l2_device.h
> @@ -62,7 +62,7 @@ public:
>  	V4L2Device(const V4L2Device &) = delete;
>  	~V4L2Device();
> 
> -	void operator=(const V4L2Device &) = delete;
> +	V4L2Device &operator=(const V4L2Device &) = delete;
> 
>  	int open();
>  	bool isOpen() const;

Patch

diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
index 413bb7f..c67ebbf 100644
--- a/src/libcamera/include/v4l2_device.h
+++ b/src/libcamera/include/v4l2_device.h
@@ -62,7 +62,7 @@  public:
 	V4L2Device(const V4L2Device &) = delete;
 	~V4L2Device();

-	void operator=(const V4L2Device &) = delete;
+	V4L2Device &operator=(const V4L2Device &) = delete;

 	int open();
 	bool isOpen() const;