libcamera: utils: Implement C++14 make_unique<>()

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>
This commit is contained in:
Laurent Pinchart 2019-01-15 15:30:48 +02:00
parent f388aa7041
commit a2f095947f

View file

@ -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__ */