diff options
author | mikhail.pozdnyakov <mikhail.pozdnyakov@intel.com> | 2015-04-09 05:11:02 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-09 12:11:37 +0000 |
commit | fcedd76a70ed85c1a24b2ac9bafe684c34d0e038 (patch) | |
tree | e9b6d60629f4ceea3cc2b5665f3b963a17062c6d /base/memory | |
parent | 427ed7b818f7cb2f3e14d6ccc5c73b0cca80e742 (diff) | |
download | chromium_src-fcedd76a70ed85c1a24b2ac9bafe684c34d0e038.zip chromium_src-fcedd76a70ed85c1a24b2ac9bafe684c34d0e038.tar.gz chromium_src-fcedd76a70ed85c1a24b2ac9bafe684c34d0e038.tar.bz2 |
base::ManualConstructor improvements
- use ALIGNOF macro
- use variadic templates
Review URL: https://codereview.chromium.org/1070603003
Cr-Commit-Position: refs/heads/master@{#324417}
Diffstat (limited to 'base/memory')
-rw-r--r-- | base/memory/manual_constructor.h | 66 |
1 files changed, 6 insertions, 60 deletions
diff --git a/base/memory/manual_constructor.h b/base/memory/manual_constructor.h index 9275f73..56081a1 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 |