Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: third_party/WebKit/Source/wtf/PtrUtil.h

Issue 2455313003: Add WTF::MakeUnique to mirror C++14's std::make_unique. (Closed)
Patch Set: rename MakeUnique -> makeUnique Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/DEPS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/PtrUtil.h
diff --git a/third_party/WebKit/Source/wtf/PtrUtil.h b/third_party/WebKit/Source/wtf/PtrUtil.h
index a26aa4cfe2e67008cc175e83c97cbe0fab630051..bba00bbc207591196335ed16fbdd699472eeecba 100644
--- a/third_party/WebKit/Source/wtf/PtrUtil.h
+++ b/third_party/WebKit/Source/wtf/PtrUtil.h
@@ -5,6 +5,7 @@
#ifndef PtrUtil_h
#define PtrUtil_h
+#include "base/memory/ptr_util.h"
#include "wtf/TypeTraits.h"
#include <memory>
@@ -27,8 +28,27 @@ std::unique_ptr<T[]> wrapArrayUnique(T* ptr) {
return std::unique_ptr<T[]>(ptr);
}
+// WTF::makeUnique is base::MakeUnique. See base/ptr_util.h for documentation.
+template <typename T, typename... Args>
+auto makeUnique(Args&&... args)
+ -> decltype(base::MakeUnique<T>(std::forward<Args>(args)...)) {
+ static_assert(
+ !WTF::IsGarbageCollectedType<T>::value,
+ "Garbage collected types should not be stored in std::unique_ptr!");
+ return base::MakeUnique<T>(std::forward<Args>(args)...);
+}
+
+template <typename T>
+auto makeUnique(size_t size) -> decltype(base::MakeUnique<T>(size)) {
+ static_assert(
+ !WTF::IsGarbageCollectedType<T>::value,
+ "Garbage collected types should not be stored in std::unique_ptr!");
+ return base::MakeUnique<T>(size);
+}
+
} // namespace WTF
+using WTF::makeUnique;
using WTF::wrapUnique;
using WTF::wrapArrayUnique;
« no previous file with comments | « third_party/WebKit/Source/wtf/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698