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

Unified Diff: base/memory/manual_constructor.h

Issue 1070603003: base::ManualConstructor improvements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed the outdated comment Created 5 years, 8 months 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/manual_constructor.h
diff --git a/base/memory/manual_constructor.h b/base/memory/manual_constructor.h
index 9275f73b83b80e74ad9144d40094f7038ac58d5b..56081a1d3bc5362a6797a2aeca2d2516f74689f6 100644
--- a/base/memory/manual_constructor.h
+++ b/base/memory/manual_constructor.h
@@ -18,6 +18,7 @@
#include <stddef.h>
+#include "base/compiler_specific.h"
#include "base/memory/aligned_memory.h"
namespace base {
@@ -33,11 +34,7 @@ class ManualConstructor {
// Support users creating arrays of ManualConstructor<>s. This ensures that
// the array itself has the correct alignment.
static void* operator new[](size_t size) {
-#if defined(COMPILER_MSVC)
- return AlignedAlloc(size, __alignof(Type));
-#else
- return AlignedAlloc(size, __alignof__(Type));
-#endif
+ return AlignedAlloc(size, ALIGNOF(Type));
}
static void operator delete[](void* mem) {
AlignedFree(mem);
@@ -56,56 +53,9 @@ class ManualConstructor {
inline Type& operator*() { return *get(); }
inline const Type& operator*() const { return *get(); }
- // You can pass up to eight constructor arguments as arguments of Init().
- inline void Init() {
- new(space_.void_data()) Type;
- }
-
- template <typename T1>
- inline void Init(const T1& p1) {
- new(space_.void_data()) Type(p1);
- }
-
- template <typename T1, typename T2>
- inline void Init(const T1& p1, const T2& p2) {
- new(space_.void_data()) Type(p1, p2);
- }
-
- template <typename T1, typename T2, typename T3>
- inline void Init(const T1& p1, const T2& p2, const T3& p3) {
- new(space_.void_data()) Type(p1, p2, p3);
- }
-
- template <typename T1, typename T2, typename T3, typename T4>
- inline void Init(const T1& p1, const T2& p2, const T3& p3, const T4& p4) {
- new(space_.void_data()) Type(p1, p2, p3, p4);
- }
-
- template <typename T1, typename T2, typename T3, typename T4, typename T5>
- inline void Init(const T1& p1, const T2& p2, const T3& p3, const T4& p4,
- const T5& p5) {
- new(space_.void_data()) Type(p1, p2, p3, p4, p5);
- }
-
- template <typename T1, typename T2, typename T3, typename T4, typename T5,
- typename T6>
- inline void Init(const T1& p1, const T2& p2, const T3& p3, const T4& p4,
- const T5& p5, const T6& p6) {
- new(space_.void_data()) Type(p1, p2, p3, p4, p5, p6);
- }
-
- template <typename T1, typename T2, typename T3, typename T4, typename T5,
- typename T6, typename T7>
- inline void Init(const T1& p1, const T2& p2, const T3& p3, const T4& p4,
- const T5& p5, const T6& p6, const T7& p7) {
- new(space_.void_data()) Type(p1, p2, p3, p4, p5, p6, p7);
- }
-
- template <typename T1, typename T2, typename T3, typename T4, typename T5,
- typename T6, typename T7, typename T8>
- inline void Init(const T1& p1, const T2& p2, const T3& p3, const T4& p4,
- const T5& p5, const T6& p6, const T7& p7, const T8& p8) {
- new(space_.void_data()) Type(p1, p2, p3, p4, p5, p6, p7, p8);
+ template <typename... Ts>
+ inline void Init(const Ts&... params) {
+ new(space_.void_data()) Type(params...);
}
inline void Destroy() {
@@ -113,11 +63,7 @@ class ManualConstructor {
}
private:
-#if defined(COMPILER_MSVC)
- AlignedMemory<sizeof(Type), __alignof(Type)> space_;
-#else
- AlignedMemory<sizeof(Type), __alignof__(Type)> space_;
-#endif
+ AlignedMemory<sizeof(Type), ALIGNOF(Type)> space_;
};
} // namespace base
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698