From 5bb0e1da38dd1c5c9ef4619da8aad99ccfd30cf2 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Mon, 23 Oct 2017 11:49:39 -0700 Subject: [PATCH] Modernize use of std::make_unique Summary: Via the clang-tidy check modernize-make-unique. Reviewed By: yfeldblum Differential Revision: D6107790 fbshipit-source-id: 1cf186feae511cbd91f44893059737a85778b6cf --- folly/Benchmark.cpp | 3 +- folly/ConcurrentSkipList-inl.h | 2 +- folly/executors/test/AsyncTest.cpp | 4 +- .../executors/test/ThreadPoolExecutorTest.cpp | 4 +- folly/futures/test/ContextTest.cpp | 6 +- folly/futures/test/FutureTest.cpp | 2 +- folly/futures/test/PromiseTest.cpp | 4 +- folly/futures/test/SemiFutureTest.cpp | 6 +- folly/gen/test/BaseTest.cpp | 56 +++++++++---------- folly/gen/test/ParallelTest.cpp | 3 +- folly/io/async/AsyncSSLSocket.cpp | 3 +- folly/io/async/EventBase.cpp | 5 +- folly/io/async/test/AsyncSSLSocketTest.h | 7 ++- folly/io/async/test/EventBaseTest.cpp | 2 +- folly/io/async/test/SSLSessionTest.cpp | 4 +- folly/ssl/detail/OpenSSLThreading.cpp | 3 +- folly/test/AtomicHashArrayTest.cpp | 3 +- folly/test/AtomicHashMapTest.cpp | 18 +++--- folly/test/AtomicUnorderedMapTest.cpp | 5 +- folly/test/ConcurrentSkipListTest.cpp | 2 +- folly/test/ExpectedTest.cpp | 4 +- folly/test/FBVectorTest.cpp | 2 +- folly/test/MoveWrapperTest.cpp | 2 +- folly/test/OptionalTest.cpp | 4 +- folly/test/ThreadCachedIntTest.cpp | 7 ++- folly/test/ThreadLocalTest.cpp | 3 +- folly/test/small_vector_test.cpp | 2 +- folly/test/sorted_vector_test.cpp | 8 +-- 28 files changed, 95 insertions(+), 79 deletions(-) diff --git a/folly/Benchmark.cpp b/folly/Benchmark.cpp index 83d162a1..b80eb6b3 100644 --- a/folly/Benchmark.cpp +++ b/folly/Benchmark.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -451,7 +452,7 @@ void runBenchmarks() { std::unique_ptr bmRegex; if (!FLAGS_bm_regex.empty()) { - bmRegex.reset(new boost::regex(FLAGS_bm_regex)); + bmRegex = std::make_unique(FLAGS_bm_regex); } // PLEASE KEEP QUIET. MEASUREMENTS IN PROGRESS. diff --git a/folly/ConcurrentSkipList-inl.h b/folly/ConcurrentSkipList-inl.h index eca30ceb..090a732e 100644 --- a/folly/ConcurrentSkipList-inl.h +++ b/folly/ConcurrentSkipList-inl.h @@ -255,7 +255,7 @@ class NodeRecycler g(lock_); if (nodes_.get() == nullptr) { - nodes_.reset(new std::vector(1, node)); + nodes_ = std::make_unique>(1, node); } else { nodes_->push_back(node); } diff --git a/folly/executors/test/AsyncTest.cpp b/folly/executors/test/AsyncTest.cpp index 4a7f0cf0..c1c87d46 100644 --- a/folly/executors/test/AsyncTest.cpp +++ b/folly/executors/test/AsyncTest.cpp @@ -18,6 +18,8 @@ #include #include +#include + using namespace folly; TEST(AsyncFunc, manual_executor) { @@ -45,7 +47,7 @@ TEST(AsyncFunc, void_lambda) { } TEST(AsyncFunc, moveonly_lambda) { - auto lambda = [] { return std::unique_ptr(new int(42)); }; + auto lambda = [] { return std::make_unique(42); }; auto future = async(lambda); EXPECT_EQ(42, *future.get()); } diff --git a/folly/executors/test/ThreadPoolExecutorTest.cpp b/folly/executors/test/ThreadPoolExecutorTest.cpp index faf92172..85d26187 100644 --- a/folly/executors/test/ThreadPoolExecutorTest.cpp +++ b/folly/executors/test/ThreadPoolExecutorTest.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include @@ -445,8 +446,7 @@ TEST(ThreadPoolExecutorTest, RequestContext) { RequestContextScopeGuard rctx; // create new request context for this scope EXPECT_EQ(nullptr, RequestContext::get()->getContextData("test")); - RequestContext::get()->setContextData( - "test", std::unique_ptr(new TestData(42))); + RequestContext::get()->setContextData("test", std::make_unique(42)); auto data = RequestContext::get()->getContextData("test"); EXPECT_EQ(42, dynamic_cast(data)->data_); diff --git a/folly/futures/test/ContextTest.cpp b/folly/futures/test/ContextTest.cpp index 48185ae7..a3dca7ec 100644 --- a/folly/futures/test/ContextTest.cpp +++ b/folly/futures/test/ContextTest.cpp @@ -17,6 +17,8 @@ #include #include +#include + using namespace folly; class TestData : public RequestData { @@ -34,9 +36,7 @@ TEST(Context, basic) { EXPECT_EQ(nullptr, RequestContext::get()->getContextData("test")); // Set some test data - RequestContext::get()->setContextData( - "test", - std::unique_ptr(new TestData(10))); + RequestContext::get()->setContextData("test", std::make_unique(10)); // Start a future Promise p; diff --git a/folly/futures/test/FutureTest.cpp b/folly/futures/test/FutureTest.cpp index 49ce1cac..5f097ce5 100644 --- a/folly/futures/test/FutureTest.cpp +++ b/folly/futures/test/FutureTest.cpp @@ -561,7 +561,7 @@ TEST(Future, thenBindTry) { } TEST(Future, value) { - auto f = makeFuture(std::unique_ptr(new int(42))); + auto f = makeFuture(std::make_unique(42)); auto up = std::move(f.value()); EXPECT_EQ(42, *up); diff --git a/folly/futures/test/PromiseTest.cpp b/folly/futures/test/PromiseTest.cpp index 3f41c072..509aa7aa 100644 --- a/folly/futures/test/PromiseTest.cpp +++ b/folly/futures/test/PromiseTest.cpp @@ -17,6 +17,8 @@ #include #include +#include + using namespace folly; using std::unique_ptr; using std::string; @@ -75,7 +77,7 @@ TEST(Promise, setValue) { Promise> mov; auto fmov = mov.getFuture(); - mov.setValue(unique_ptr(new int(42))); + mov.setValue(std::make_unique(42)); unique_ptr ptr = std::move(fmov.value()); EXPECT_EQ(42, *ptr); diff --git a/folly/futures/test/SemiFutureTest.cpp b/folly/futures/test/SemiFutureTest.cpp index 64527adf..1471d42b 100644 --- a/folly/futures/test/SemiFutureTest.cpp +++ b/folly/futures/test/SemiFutureTest.cpp @@ -72,7 +72,7 @@ TEST(SemiFuture, special) { } TEST(SemiFuture, value) { - auto f = makeSemiFuture(std::unique_ptr(new int(42))); + auto f = makeSemiFuture(std::make_unique(42)); auto up = std::move(f.value()); EXPECT_EQ(42, *up); @@ -159,8 +159,8 @@ TEST(SemiFuture, MakeSemiFutureFromFutureWithUnit) { } TEST(SemiFuture, MakeSemiFutureFromFutureWithValue) { - auto f = SemiFuture>{ - makeFuture(std::unique_ptr(new int(42)))}; + auto f = + SemiFuture>{makeFuture(std::make_unique(42))}; auto up = std::move(f.value()); EXPECT_EQ(42, *up); } diff --git a/folly/gen/test/BaseTest.cpp b/folly/gen/test/BaseTest.cpp index 0158b936..3948168d 100644 --- a/folly/gen/test/BaseTest.cpp +++ b/folly/gen/test/BaseTest.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -604,13 +605,13 @@ TEST(Gen, DistinctBy) { // 0 1 4 9 6 5 6 9 4 1 0 TEST(Gen, DistinctMove) { // 0 1 4 9 6 5 6 9 4 1 0 auto expected = vector{0, 1, 2, 3, 4, 5}; - auto actual = - seq(0, 100) - | mapped([](int i) { return std::unique_ptr(new int(i)); }) + auto actual = seq(0, 100) | + mapped([](int i) { return std::make_unique(i); }) // see comment below about selector parameters for Distinct - | distinctBy([](const std::unique_ptr& pi) { return *pi * *pi % 10; }) - | mapped([](std::unique_ptr pi) { return *pi; }) - | as(); + | distinctBy([](const std::unique_ptr& pi) { + return *pi * *pi % 10; + }) | + mapped([](std::unique_ptr pi) { return *pi; }) | as(); // NOTE(tjackson): the following line intentionally doesn't work: // | distinctBy([](std::unique_ptr pi) { return *pi * *pi % 10; }) @@ -917,11 +918,10 @@ TEST(Gen, CustomType) { } TEST(Gen, NoNeedlessCopies) { - auto gen = seq(1, 5) - | map([](int x) { return unique_ptr(new int(x)); }) - | map([](unique_ptr p) { return p; }) - | map([](unique_ptr&& p) { return std::move(p); }) - | map([](const unique_ptr& p) { return *p; }); + auto gen = seq(1, 5) | map([](int x) { return std::make_unique(x); }) | + map([](unique_ptr p) { return p; }) | + map([](unique_ptr&& p) { return std::move(p); }) | + map([](const unique_ptr& p) { return *p; }); EXPECT_EQ(15, gen | sum); EXPECT_EQ(6, gen | take(3) | sum); } @@ -1236,18 +1236,16 @@ TEST(Gen, Batch) { TEST(Gen, BatchMove) { auto expected = vector>{ {0, 1}, {2, 3}, {4} }; - auto actual = - seq(0, 4) - | mapped([](int i) { return std::unique_ptr(new int(i)); }) - | batch(2) - | mapped([](std::vector>& pVector) { - std::vector iVector; - for (const auto& p : pVector) { - iVector.push_back(*p); - }; - return iVector; - }) - | as(); + auto actual = seq(0, 4) | + mapped([](int i) { return std::make_unique(i); }) | batch(2) | + mapped([](std::vector>& pVector) { + std::vector iVector; + for (const auto& p : pVector) { + iVector.push_back(*p); + }; + return iVector; + }) | + as(); EXPECT_EQ(expected, actual); } @@ -1256,22 +1254,22 @@ TEST(Gen, Window) { for (size_t windowSize = 1; windowSize <= 20; ++windowSize) { // no early stop auto actual = seq(0, 10) | - mapped([](int i) { return std::unique_ptr(new int(i)); }) | - window(4) | dereference | as(); + mapped([](int i) { return std::make_unique(i); }) | window(4) | + dereference | as(); EXPECT_EQ(expected, actual) << windowSize; } for (size_t windowSize = 1; windowSize <= 20; ++windowSize) { // pre-window take auto actual = seq(0) | - mapped([](int i) { return std::unique_ptr(new int(i)); }) | - take(11) | window(4) | dereference | as(); + mapped([](int i) { return std::make_unique(i); }) | take(11) | + window(4) | dereference | as(); EXPECT_EQ(expected, actual) << windowSize; } for (size_t windowSize = 1; windowSize <= 20; ++windowSize) { // post-window take auto actual = seq(0) | - mapped([](int i) { return std::unique_ptr(new int(i)); }) | - window(4) | take(11) | dereference | as(); + mapped([](int i) { return std::make_unique(i); }) | window(4) | + take(11) | dereference | as(); EXPECT_EQ(expected, actual) << windowSize; } } diff --git a/folly/gen/test/ParallelTest.cpp b/folly/gen/test/ParallelTest.cpp index b90202c6..358d86e6 100644 --- a/folly/gen/test/ParallelTest.cpp +++ b/folly/gen/test/ParallelTest.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -52,7 +53,7 @@ static auto isPrime = [](int n) { struct { template std::unique_ptr operator()(T t) const { - return std::unique_ptr(new T(std::move(t))); + return std::make_unique(std::move(t)); } } makeUnique; diff --git a/folly/io/async/AsyncSSLSocket.cpp b/folly/io/async/AsyncSSLSocket.cpp index 3a7562dc..4bb8a9b4 100644 --- a/folly/io/async/AsyncSSLSocket.cpp +++ b/folly/io/async/AsyncSSLSocket.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -1716,7 +1717,7 @@ int AsyncSSLSocket::sslVerifyCallback( void AsyncSSLSocket::enableClientHelloParsing() { parseClientHello_ = true; - clientHelloInfo_.reset(new ssl::ClientHelloInfo()); + clientHelloInfo_ = std::make_unique(); } void AsyncSSLSocket::resetClientHelloParsing(SSL *ssl) { diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index d138c336..352e41f5 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -22,6 +22,7 @@ #include +#include #include #include @@ -626,12 +627,12 @@ bool EventBase::runLoopCallbacks() { void EventBase::initNotificationQueue() { // Infinite size queue - queue_.reset(new NotificationQueue()); + queue_ = std::make_unique>(); // We allocate fnRunner_ separately, rather than declaring it directly // as a member of EventBase solely so that we don't need to include // NotificationQueue.h from EventBase.h - fnRunner_.reset(new FunctionRunner()); + fnRunner_ = std::make_unique(); // Mark this as an internal event, so event_base_loop() will return if // there are no other events besides this one installed. diff --git a/folly/io/async/test/AsyncSSLSocketTest.h b/folly/io/async/test/AsyncSSLSocketTest.h index 122bb8f7..cb7ade43 100644 --- a/folly/io/async/test/AsyncSSLSocketTest.h +++ b/folly/io/async/test/AsyncSSLSocketTest.h @@ -38,6 +38,7 @@ #include #include #include +#include namespace folly { @@ -824,13 +825,13 @@ class BlockingWriteClient : bufLen_(2500), iovCount_(2000) { // Fill buf_ - buf_.reset(new uint8_t[bufLen_]); + buf_ = std::make_unique(bufLen_); for (uint32_t n = 0; n < sizeof(buf_); ++n) { buf_[n] = n % 0xff; } // Initialize iov_ - iov_.reset(new struct iovec[iovCount_]); + iov_ = std::make_unique(iovCount_); for (uint32_t n = 0; n < iovCount_; ++n) { iov_[n].iov_base = buf_.get() + n; if (n & 0x1) { @@ -885,7 +886,7 @@ class BlockingWriteServer : : socket_(std::move(socket)), bufSize_(2500 * 2000), bytesRead_(0) { - buf_.reset(new uint8_t[bufSize_]); + buf_ = std::make_unique(bufSize_); socket_->sslAccept(this, std::chrono::milliseconds(100)); } diff --git a/folly/io/async/test/EventBaseTest.cpp b/folly/io/async/test/EventBaseTest.cpp index 5ffa8da4..25b3192c 100644 --- a/folly/io/async/test/EventBaseTest.cpp +++ b/folly/io/async/test/EventBaseTest.cpp @@ -1610,7 +1610,7 @@ TEST(EventBaseTest, IdleTime) { ASSERT_EQ(6, tos0.getTimeouts()); ASSERT_GE(6100, eventBase.getAvgLoopTime() - 1200); ASSERT_LE(6100, eventBase.getAvgLoopTime() + 1200); - tos.reset(new IdleTimeTimeoutSeries(&eventBase, timeouts)); + tos = std::make_unique(&eventBase, timeouts); }); // Kick things off with an "immedite" timeout diff --git a/folly/io/async/test/SSLSessionTest.cpp b/folly/io/async/test/SSLSessionTest.cpp index a85f7937..d874509b 100644 --- a/folly/io/async/test/SSLSessionTest.cpp +++ b/folly/io/async/test/SSLSessionTest.cpp @@ -19,6 +19,8 @@ #include #include +#include + using namespace std; using namespace testing; using folly::ssl::SSLSession; @@ -97,7 +99,7 @@ TEST_F(SSLSessionTest, BasicTest) { eventBase.loop(); ASSERT_TRUE(client.handshakeSuccess_); - sess.reset(new SSLSession(clientPtr->getSSLSession())); + sess = std::make_unique(clientPtr->getSSLSession()); ASSERT_NE(sess.get(), nullptr); } diff --git a/folly/ssl/detail/OpenSSLThreading.cpp b/folly/ssl/detail/OpenSSLThreading.cpp index 05b551a7..f68f677b 100644 --- a/folly/ssl/detail/OpenSSLThreading.cpp +++ b/folly/ssl/detail/OpenSSLThreading.cpp @@ -16,6 +16,7 @@ #include +#include #include #include @@ -152,7 +153,7 @@ static void dyn_destroy(struct CRYPTO_dynlock_value* lock, const char*, int) { void installThreadingLocks() { // static locking - locks().reset(new SSLLock[size_t(CRYPTO_num_locks())]); + locks() = std::make_unique(size_t(CRYPTO_num_locks())); for (auto it : lockTypes()) { locks()[size_t(it.first)].lockType = it.second; } diff --git a/folly/test/AtomicHashArrayTest.cpp b/folly/test/AtomicHashArrayTest.cpp index 15e76879..86d8ae5a 100644 --- a/folly/test/AtomicHashArrayTest.cpp +++ b/folly/test/AtomicHashArrayTest.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -154,7 +155,7 @@ void testNoncopyableMap() { auto arr = MyArr::create(250); for (int i = 0; i < 100; i++) { - arr->insert(make_pair(i,std::unique_ptr(new ValueT(i)))); + arr->insert(make_pair(i, std::make_unique(i))); } for (int i = 100; i < 150; i++) { arr->emplace(i,new ValueT(i)); diff --git a/folly/test/AtomicHashMapTest.cpp b/folly/test/AtomicHashMapTest.cpp index e2bedea4..7326d0d3 100644 --- a/folly/test/AtomicHashMapTest.cpp +++ b/folly/test/AtomicHashMapTest.cpp @@ -76,10 +76,10 @@ TEST(Ahm, BasicNoncopyable) { EXPECT_TRUE(myMap.begin() == myMap.end()); for (int i = 0; i < 50; ++i) { - myMap.insert(make_pair(i, std::unique_ptr(new int(i)))); + myMap.insert(make_pair(i, std::make_unique(i))); } for (int i = 50; i < 100; ++i) { - myMap.insert(i, std::unique_ptr(new int (i))); + myMap.insert(i, std::make_unique(i)); } for (int i = 100; i < 150; ++i) { myMap.emplace(i, new int (i)); @@ -482,7 +482,7 @@ TEST(Ahm, collision_test) { " Byte entries replicated in " << FLAGS_numThreads << " threads with " << FLAGS_maxLoadFactor * 100.0 << "% max load factor."; - globalAHM.reset(new AHMapT(int(numInserts * sizeFactor), config)); + globalAHM = std::make_unique(int(numInserts * sizeFactor), config); size_t sizeInit = globalAHM->capacity(); VLOG(1) << " Initial capacity: " << sizeInit; @@ -571,7 +571,7 @@ TEST(Ahm, race_insert_iterate_thread_test) { VLOG(1) << "Testing iteration and insertion with " << kInsertThreads << " threads inserting and " << kIterateThreads << " threads iterating."; - globalAHM.reset(new AHMapT(raceFinalSizeEstimate / 9, config)); + globalAHM = std::make_unique(raceFinalSizeEstimate / 9, config); vector threadIds; for (int j = 0; j < kInsertThreads + kIterateThreads; j++) { @@ -649,7 +649,7 @@ TEST(Ahm, thread_erase_insert_race) { VLOG(1) << "Testing insertion and erase with " << kInsertThreads << " thread inserting and " << kEraseThreads << " threads erasing."; - globalAHM.reset(new AHMapT(kTestEraseInsertions / 4, config)); + globalAHM = std::make_unique(kTestEraseInsertions / 4, config); vector threadIds; for (int64_t j = 0; j < kInsertThreads + kEraseThreads; j++) { @@ -820,7 +820,7 @@ void loadGlobalAhm() { std::cout << "loading global AHM with " << FLAGS_numThreads << " threads...\n"; uint64_t start = nowInUsec(); - globalAHM.reset(new AHMapT(maxBMElements, config)); + globalAHM = std::make_unique(maxBMElements, config); numOpsPerThread = FLAGS_numBMElements / FLAGS_numThreads; runThreads(insertThread); uint64_t elapsed = nowInUsec() - start; @@ -833,7 +833,7 @@ void loadGlobalQPAhm() { std::cout << "loading global QPAHM with " << FLAGS_numThreads << " threads...\n"; uint64_t start = nowInUsec(); - globalQPAHM.reset(new QPAHMapT(maxBMElements, qpConfig)); + globalQPAHM = std::make_unique(maxBMElements, qpConfig); numOpsPerThread = FLAGS_numBMElements / FLAGS_numThreads; runThreads(qpInsertThread); uint64_t elapsed = nowInUsec() - start; @@ -1020,7 +1020,7 @@ BENCHMARK(st_baseline_modulus_and_random, iters) { BENCHMARK(mt_ahm_insert, iters) { BENCHMARK_SUSPEND { - globalAHM.reset(new AHMapT(int(iters * LF), config)); + globalAHM = std::make_unique(int(iters * LF), config); numOpsPerThread = iters / FLAGS_numThreads; } runThreads(insertThread); @@ -1028,7 +1028,7 @@ BENCHMARK(mt_ahm_insert, iters) { BENCHMARK(mt_qpahm_insert, iters) { BENCHMARK_SUSPEND { - globalQPAHM.reset(new QPAHMapT(int(iters * LF), qpConfig)); + globalQPAHM = std::make_unique(int(iters * LF), qpConfig); numOpsPerThread = iters / FLAGS_numThreads; } runThreads(qpInsertThread); diff --git a/folly/test/AtomicUnorderedMapTest.cpp b/folly/test/AtomicUnorderedMapTest.cpp index 342f0b87..e38b6014 100644 --- a/folly/test/AtomicUnorderedMapTest.cpp +++ b/folly/test/AtomicUnorderedMapTest.cpp @@ -16,6 +16,7 @@ #include +#include #include #include @@ -207,7 +208,7 @@ BENCHMARK(lookup_int_int_hit, iters) { size_t capacity = 100000; BENCHMARK_SUSPEND { - ptr.reset(new AtomicUnorderedInsertMap(capacity)); + ptr = std::make_unique>(capacity); for (size_t i = 0; i < capacity; ++i) { auto k = 3 * ((5641 * i) % capacity); ptr->emplace(k, k + 1); @@ -249,7 +250,7 @@ void contendedRW(size_t itersPerThread, std::vector threads; BENCHMARK_SUSPEND { - ptr.reset(new Map(capacity)); + ptr = std::make_unique(capacity); while (threads.size() < numThreads) { threads.emplace_back([&](){ while (!go) { diff --git a/folly/test/ConcurrentSkipListTest.cpp b/folly/test/ConcurrentSkipListTest.cpp index dc3deda7..4447463e 100644 --- a/folly/test/ConcurrentSkipListTest.cpp +++ b/folly/test/ConcurrentSkipListTest.cpp @@ -286,7 +286,7 @@ TEST(ConcurrentSkipList, TestMovableData) { static const int N = 10; for (int i = 0; i < N; ++i) { - accessor.insert(std::unique_ptr(new int(i))); + accessor.insert(std::make_unique(i)); } for (int i = 0; i < N; ++i) { diff --git a/folly/test/ExpectedTest.cpp b/folly/test/ExpectedTest.cpp index fe24055d..6e377b35 100644 --- a/folly/test/ExpectedTest.cpp +++ b/folly/test/ExpectedTest.cpp @@ -230,10 +230,10 @@ TEST(Expected, Unique) { ex = makeUnexpected(-1); // empty->moved - ex = unique_ptr(new int(6)); + ex = std::make_unique(6); EXPECT_EQ(6, **ex); // full->moved - ex = unique_ptr(new int(7)); + ex = std::make_unique(7); EXPECT_EQ(7, **ex); // move it out by move construct diff --git a/folly/test/FBVectorTest.cpp b/folly/test/FBVectorTest.cpp index 472ce8d7..3194ee74 100644 --- a/folly/test/FBVectorTest.cpp +++ b/folly/test/FBVectorTest.cpp @@ -191,7 +191,7 @@ TEST(fbvector, unique_ptr) { v[0] = std::move(p); EXPECT_FALSE(v[0].get()); - v[0].reset(new int(32)); + v[0] = std::make_unique(32); std::unique_ptr somePtr; v.insert(v.begin(), std::move(somePtr)); EXPECT_EQ(*v[1], 32); diff --git a/folly/test/MoveWrapperTest.cpp b/folly/test/MoveWrapperTest.cpp index a7d64f89..3f2f217e 100644 --- a/folly/test/MoveWrapperTest.cpp +++ b/folly/test/MoveWrapperTest.cpp @@ -28,7 +28,7 @@ TEST(makeMoveWrapper, Empty) { } TEST(makeMoveWrapper, NonEmpty) { - auto u = std::unique_ptr(new int(5)); + auto u = std::make_unique(5); EXPECT_EQ(*u, 5); auto p = makeMoveWrapper(std::move(u)); EXPECT_TRUE(!u); diff --git a/folly/test/OptionalTest.cpp b/folly/test/OptionalTest.cpp index 990f1e17..b82f3164 100644 --- a/folly/test/OptionalTest.cpp +++ b/folly/test/OptionalTest.cpp @@ -223,10 +223,10 @@ TEST(Optional, Unique) { opt.clear(); // empty->moved - opt = unique_ptr(new int(6)); + opt = std::make_unique(6); EXPECT_EQ(6, **opt); // full->moved - opt = unique_ptr(new int(7)); + opt = std::make_unique(7); EXPECT_EQ(7, **opt); // move it out by move construct diff --git a/folly/test/ThreadCachedIntTest.cpp b/folly/test/ThreadCachedIntTest.cpp index 6b438f74..40b3f443 100644 --- a/folly/test/ThreadCachedIntTest.cpp +++ b/folly/test/ThreadCachedIntTest.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -86,7 +87,8 @@ TEST_F(ThreadCachedIntTest, MultithreadedSlow) { // iteration, threads[1] performs 2 iterations, threads[2] performs // 3 iterations, and so on. for (uint32_t i = 0; i < kNumThreads; ++i) { - threads[i].reset(new std::thread(Runner, &g_counter_for_mt_slow, i + 1)); + threads[i] = + std::make_unique(Runner, &g_counter_for_mt_slow, i + 1); } // Variable to grab current counter value. int32_t counter_value; @@ -141,7 +143,8 @@ TEST_F(ThreadCachedIntTest, MultithreadedFast) { // iteration, threads[1] performs 2 iterations, threads[2] performs // 3 iterations, and so on. for (uint32_t i = 0; i < kNumThreads; ++i) { - threads[i].reset(new std::thread(Runner, &g_counter_for_mt_fast, i + 1)); + threads[i] = + std::make_unique(Runner, &g_counter_for_mt_fast, i + 1); } // Let the threads run to completion. { diff --git a/folly/test/ThreadLocalTest.cpp b/folly/test/ThreadLocalTest.cpp index 6be3f228..7163701b 100644 --- a/folly/test/ThreadLocalTest.cpp +++ b/folly/test/ThreadLocalTest.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -269,7 +270,7 @@ TEST(ThreadLocal, InterleavedDestructors) { { std::lock_guard g(lock); thIterPrev = thIter; - w.reset(new ThreadLocal()); + w = std::make_unique>(); ++wVersion; } while (true) { diff --git a/folly/test/small_vector_test.cpp b/folly/test/small_vector_test.cpp index bae23e95..9f1eaf48 100644 --- a/folly/test/small_vector_test.cpp +++ b/folly/test/small_vector_test.cpp @@ -176,7 +176,7 @@ struct TestBasicGuarantee { std::unique_ptr > workingVec; for (int counter = 1; !done; ++counter) { throwCounter = 1000; - workingVec.reset(new folly::small_vector(vec)); + workingVec = std::make_unique>(vec); throwCounter = counter; EXPECT_EQ(Thrower::alive, prepopulate * 2); try { diff --git a/folly/test/sorted_vector_test.cpp b/folly/test/sorted_vector_test.cpp index 834ed4cb..77308b71 100644 --- a/folly/test/sorted_vector_test.cpp +++ b/folly/test/sorted_vector_test.cpp @@ -330,8 +330,8 @@ TEST(SortedVectorTest, EmptyTest) { TEST(SortedVectorTest, MoveTest) { sorted_vector_set> s; - s.insert(std::unique_ptr(new int(5))); - s.insert(s.end(), std::unique_ptr(new int(10))); + s.insert(std::make_unique(5)); + s.insert(s.end(), std::make_unique(10)); EXPECT_EQ(s.size(), 2); for (const auto& p : s) { @@ -339,8 +339,8 @@ TEST(SortedVectorTest, MoveTest) { } sorted_vector_map> m; - m.insert(std::make_pair(5, std::unique_ptr(new int(5)))); - m.insert(m.end(), std::make_pair(10, std::unique_ptr(new int(10)))); + m.insert(std::make_pair(5, std::make_unique(5))); + m.insert(m.end(), std::make_pair(10, std::make_unique(10))); EXPECT_EQ(*m[5], 5); EXPECT_EQ(*m[10], 10); -- 2.34.1