From 38c3f678330e5a2d7ba948ffcae2499489474c12 Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Fri, 5 Jul 2024 19:43:55 -0400 Subject: [PATCH] util: add c++14-style MakeUnique for use with c++11 Backported from: 86179897 Original author: practicalswift --- src/Makefile.am | 1 + src/utilmemory.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/utilmemory.h diff --git a/src/Makefile.am b/src/Makefile.am index b26afc5c1..cc8d3136f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -158,6 +158,7 @@ BITCOIN_CORE_H = \ ui_interface.h \ undo.h \ util.h \ + utilmemory.h \ utilmoneystr.h \ utiltime.h \ utilstring.h \ diff --git a/src/utilmemory.h b/src/utilmemory.h new file mode 100644 index 000000000..15ecf8f80 --- /dev/null +++ b/src/utilmemory.h @@ -0,0 +1,19 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_UTIL_MEMORY_H +#define BITCOIN_UTIL_MEMORY_H + +#include +#include + +//! Substitute for C++14 std::make_unique. +template +std::unique_ptr MakeUnique(Args&&... args) +{ + return std::unique_ptr(new T(std::forward(args)...)); +} + +#endif