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

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Jan 15 16:18:48 CET 2019


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>
---
 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



More information about the libcamera-devel mailing list