From 1823e905abb7044e38434cc7d16fdec8545dda1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 12 May 2022 14:24:07 -0400 Subject: [PATCH] Add lttng::make_unique MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add an equivalent to std::make_unique introduced in C++14. See https://herbsutter.com/gotw/_102/ for more details. Change-Id: I67e5b54d883e311869d7c1272f9a2905dc349212 Signed-off-by: Jérémie Galarneau --- src/common/Makefile.am | 1 + src/common/make-unique.hpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/common/make-unique.hpp diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 4df84d698..23d33e983 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -89,6 +89,7 @@ libcommon_lgpl_la_SOURCES = \ kernel-probe.cpp \ location.cpp \ log-level-rule.cpp \ + make-unique.hpp \ make-unique-wrapper.hpp \ mi-lttng.cpp mi-lttng.hpp \ notification.cpp \ diff --git a/src/common/make-unique.hpp b/src/common/make-unique.hpp new file mode 100644 index 000000000..244cd9e7b --- /dev/null +++ b/src/common/make-unique.hpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_MAKE_UNIQUE_H +#define LTTNG_MAKE_UNIQUE_H + +#include + +namespace lttng { + +template +std::unique_ptr make_unique(Args&&...args) +{ + return std::unique_ptr(new Type(std::forward(args)...)); +} + +} /* namespace lttng */ + +#endif /* LTTNG_MAKE_UNIQUE_H */ -- 2.34.1