util: add c++14-style MakeUnique for use with c++11

Backported from: 86179897
Original author: practicalswift <practicalswift@users.noreply.github.com>
This commit is contained in:
Patrick Lodder 2024-07-05 19:43:55 -04:00
parent 2fcaf1310c
commit 38c3f67833
No known key found for this signature in database
GPG Key ID: 7C523F5FBABE80E7
2 changed files with 20 additions and 0 deletions

View File

@ -158,6 +158,7 @@ BITCOIN_CORE_H = \
ui_interface.h \
undo.h \
util.h \
utilmemory.h \
utilmoneystr.h \
utiltime.h \
utilstring.h \

19
src/utilmemory.h Normal file
View File

@ -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 <memory>
#include <utility>
//! Substitute for C++14 std::make_unique.
template <typename T, typename... Args>
std::unique_ptr<T> MakeUnique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
#endif