Skip to content

Commit 33539cb

Browse files
committed
Extract MakeUnique into utilmemory.h
And use it to reduce chainparamsbase's direct reliance on util.h to only args handling. utilmemory.h can be replaced with <memory> once we move to C++14.
1 parent 6fcdb5e commit 33539cb

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ BITCOIN_CORE_H = \
179179
ui_interface.h \
180180
undo.h \
181181
util.h \
182+
utilmemory.h \
182183
utilmoneystr.h \
183184
utiltime.h \
184185
validation.h \

src/chainparamsbase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <tinyformat.h>
99
#include <util.h>
10+
#include <utilmemory.h>
1011

1112
#include <assert.h>
1213

src/interfaces/handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <interfaces/handler.h>
66

7-
#include <util.h>
7+
#include <utilmemory.h>
88

99
#include <boost/signals2/connection.hpp>
1010
#include <utility>

src/util.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
2-
// Copyright (c) 2009-2017 The Bitcoin Core developers
2+
// Copyright (c) 2009-2018 The Bitcoin Core developers
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

@@ -20,11 +20,11 @@
2020
#include <sync.h>
2121
#include <tinyformat.h>
2222
#include <utiltime.h>
23+
#include <utilmemory.h>
2324

2425
#include <atomic>
2526
#include <exception>
2627
#include <map>
27-
#include <memory>
2828
#include <set>
2929
#include <stdint.h>
3030
#include <string>
@@ -346,13 +346,6 @@ template <typename Callable> void TraceThread(const char* name, Callable func)
346346

347347
std::string CopyrightHolders(const std::string& strPrefix);
348348

349-
//! Substitute for C++14 std::make_unique.
350-
template <typename T, typename... Args>
351-
std::unique_ptr<T> MakeUnique(Args&&... args)
352-
{
353-
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
354-
}
355-
356349
/**
357350
* On platforms that support it, tell the kernel the calling thread is
358351
* CPU-intensive and non-interactive. See SCHED_BATCH in sched(7) for details.

src/utilmemory.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2009-2010 Satoshi Nakamoto
2+
// Copyright (c) 2009-2018 The Bitcoin Core developers
3+
// Distributed under the MIT software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#ifndef BITCOIN_UTILMEMORY_H
7+
#define BITCOIN_UTILMEMORY_H
8+
9+
#include <memory>
10+
#include <utility>
11+
12+
//! Substitute for C++14 std::make_unique.
13+
template <typename T, typename... Args>
14+
std::unique_ptr<T> MakeUnique(Args&&... args)
15+
{
16+
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
17+
}
18+
19+
#endif

0 commit comments

Comments
 (0)