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

Niklas Söderlund niklas.soderlund at ragnatech.se
Tue Jan 15 23:42:02 CET 2019


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 at ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund at 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 at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

-- 
Regards,
Niklas Söderlund


More information about the libcamera-devel mailing list