[libcamera-devel,v2,7/8] libcamera: utils: Implement C++14 make_unique<>()

Message ID 20190115151849.1547-8-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Pipeline handler refactoring and assorted improvements
Related show

Commit Message

Laurent Pinchart Jan. 15, 2019, 3:18 p.m. UTC
C++14 introduces std::make_unique<>() that makes it easier to initialize
unique_ptr<> instances. As libcamera is limited to C++11, implement our
own version of the function in the libcamera::utils namespace.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/include/utils.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Niklas Söderlund Jan. 15, 2019, 10:42 p.m. UTC | #1
Hi Laurent,

Thanks for your work.

On 2019-01-15 17:18:48 +0200, Laurent Pinchart wrote:
> C++14 introduces std::make_unique<>() that makes it easier to initialize
> unique_ptr<> instances. As libcamera is limited to C++11, implement our
> own version of the function in the libcamera::utils namespace.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/libcamera/include/utils.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h
> index 3ffa6f4ea591..a2e450b35372 100644
> --- a/src/libcamera/include/utils.h
> +++ b/src/libcamera/include/utils.h
> @@ -7,6 +7,19 @@
>  #ifndef __LIBCAMERA_UTILS_H__
>  #define __LIBCAMERA_UTILS_H__
>  
> +#include <memory>
> +
>  #define ARRAY_SIZE(a)	(sizeof(a) / sizeof(a[0]))
>  
> +namespace libcamera::utils {
> +
> +/* C++11 doesn't provide std::make_unique */
> +template<typename T, typename... Args>
> +std::unique_ptr<T> make_unique(Args&&... args)
> +{
> +	return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
> +}
> +
> +} /* namespace libcamera::utils */
> +
>  #endif /* __LIBCAMERA_UTILS_H__ */
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h
index 3ffa6f4ea591..a2e450b35372 100644
--- a/src/libcamera/include/utils.h
+++ b/src/libcamera/include/utils.h
@@ -7,6 +7,19 @@ 
 #ifndef __LIBCAMERA_UTILS_H__
 #define __LIBCAMERA_UTILS_H__
 
+#include <memory>
+
 #define ARRAY_SIZE(a)	(sizeof(a) / sizeof(a[0]))
 
+namespace libcamera::utils {
+
+/* C++11 doesn't provide std::make_unique */
+template<typename T, typename... Args>
+std::unique_ptr<T> make_unique(Args&&... args)
+{
+	return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+
+} /* namespace libcamera::utils */
+
 #endif /* __LIBCAMERA_UTILS_H__ */