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

Unified Diff: base/memory/aligned_memory.h

Issue 2670873002: Remove base's ALIGNOF/ALIGNAS in favor of alignof/alignas. (Closed)
Patch Set: rebase Created 3 years, 10 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 | « base/lazy_instance_unittest.cc ('k') | base/memory/aligned_memory_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/aligned_memory.h
diff --git a/base/memory/aligned_memory.h b/base/memory/aligned_memory.h
index d8290115dbeefe3f5cf2d62a72cc9179dc81963f..ddd50bef51e144ad9a42a4182305b4c8003c6fd7 100644
--- a/base/memory/aligned_memory.h
+++ b/base/memory/aligned_memory.h
@@ -8,7 +8,7 @@
// is constructed and destructed (you don't want static initialization and
// destruction), use AlignedMemory:
//
-// static AlignedMemory<sizeof(MyClass), ALIGNOF(MyClass)> my_class;
+// static AlignedMemory<sizeof(MyClass), alignof(MyClass)> my_class;
//
// // ... at runtime:
// new(my_class.void_data()) MyClass();
@@ -48,51 +48,25 @@
namespace base {
-// AlignedMemory is specialized for all supported alignments.
-// Make sure we get a compiler error if someone uses an unsupported alignment.
template <size_t Size, size_t ByteAlignment>
-struct AlignedMemory {};
-
-#define BASE_DECL_ALIGNED_MEMORY(byte_alignment) \
- template <size_t Size> \
- class AlignedMemory<Size, byte_alignment> { \
- public: \
- ALIGNAS(byte_alignment) uint8_t data_[Size]; \
- void* void_data() { return static_cast<void*>(data_); } \
- const void* void_data() const { return static_cast<const void*>(data_); } \
- template <typename Type> \
- Type* data_as() { \
- return static_cast<Type*>(void_data()); \
- } \
- template <typename Type> \
- const Type* data_as() const { \
- return static_cast<const Type*>(void_data()); \
- } \
- \
- private: \
- void* operator new(size_t); \
- void operator delete(void*); \
+class AlignedMemory {
+ public:
+ alignas(ByteAlignment) uint8_t data_[Size];
+ void* void_data() { return static_cast<void*>(data_); }
+ const void* void_data() const { return static_cast<const void*>(data_); }
+ template <typename Type>
+ Type* data_as() {
+ return static_cast<Type*>(void_data());
+ }
+ template <typename Type>
+ const Type* data_as() const {
+ return static_cast<const Type*>(void_data());
}
-// Specialization for all alignments is required because MSVC (as of VS 2008)
-// does not understand ALIGNAS(ALIGNOF(Type)) or ALIGNAS(template_param).
-// Greater than 4096 alignment is not supported by some compilers, so 4096 is
-// the maximum specified here.
-BASE_DECL_ALIGNED_MEMORY(1);
-BASE_DECL_ALIGNED_MEMORY(2);
-BASE_DECL_ALIGNED_MEMORY(4);
-BASE_DECL_ALIGNED_MEMORY(8);
-BASE_DECL_ALIGNED_MEMORY(16);
-BASE_DECL_ALIGNED_MEMORY(32);
-BASE_DECL_ALIGNED_MEMORY(64);
-BASE_DECL_ALIGNED_MEMORY(128);
-BASE_DECL_ALIGNED_MEMORY(256);
-BASE_DECL_ALIGNED_MEMORY(512);
-BASE_DECL_ALIGNED_MEMORY(1024);
-BASE_DECL_ALIGNED_MEMORY(2048);
-BASE_DECL_ALIGNED_MEMORY(4096);
-
-#undef BASE_DECL_ALIGNED_MEMORY
+ private:
+ void* operator new(size_t);
+ void operator delete(void*);
+};
BASE_EXPORT void* AlignedAlloc(size_t size, size_t alignment);
« no previous file with comments | « base/lazy_instance_unittest.cc ('k') | base/memory/aligned_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698