| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #ifndef CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ | 15 #ifndef CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ |
| 16 #define CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ | 16 #define CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ |
| 17 | 17 |
| 18 #include <stddef.h> | 18 #include <stddef.h> |
| 19 | 19 |
| 20 #include <limits> | 20 #include <limits> |
| 21 #include <memory> | 21 #include <memory> |
| 22 #include <new> | 22 #include <new> |
| 23 #include <utility> | 23 #include <utility> |
| 24 #include <vector> | 24 #include <vector> |
| 25 | 25 |
| 26 #include "base/compiler_specific.h" | |
| 27 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 28 #include "util/stdlib/cxx.h" | 27 #include "util/stdlib/cxx.h" |
| 29 | 28 |
| 30 #if defined(COMPILER_MSVC) && _MSC_VER < 1900 | 29 #if defined(COMPILER_MSVC) && _MSC_VER < 1900 |
| 31 #define CRASHPAD_NOEXCEPT _NOEXCEPT | 30 #define CRASHPAD_NOEXCEPT _NOEXCEPT |
| 32 #else | 31 #else |
| 33 #define CRASHPAD_NOEXCEPT noexcept | 32 #define CRASHPAD_NOEXCEPT noexcept |
| 34 #endif | 33 #endif |
| 35 | 34 |
| 36 namespace crashpad { | 35 namespace crashpad { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 void AlignedFree(void* pointer); | 47 void AlignedFree(void* pointer); |
| 49 | 48 |
| 50 } // namespace internal | 49 } // namespace internal |
| 51 | 50 |
| 52 //! \brief A standard allocator that aligns its allocations as requested, | 51 //! \brief A standard allocator that aligns its allocations as requested, |
| 53 //! suitable for use as an allocator in standard containers. | 52 //! suitable for use as an allocator in standard containers. |
| 54 //! | 53 //! |
| 55 //! This is similar to `std::allocator<T>`, with the addition of an alignment | 54 //! This is similar to `std::allocator<T>`, with the addition of an alignment |
| 56 //! guarantee. \a Alignment must be a power of 2. If \a Alignment is not | 55 //! guarantee. \a Alignment must be a power of 2. If \a Alignment is not |
| 57 //! specified, the default alignment for type \a T is used. | 56 //! specified, the default alignment for type \a T is used. |
| 58 template <class T, size_t Alignment = ALIGNOF(T)> | 57 template <class T, size_t Alignment = alignof(T)> |
| 59 struct AlignedAllocator { | 58 struct AlignedAllocator { |
| 60 public: | 59 public: |
| 61 using value_type = T; | 60 using value_type = T; |
| 62 using pointer = T*; | 61 using pointer = T*; |
| 63 using const_pointer = const T*; | 62 using const_pointer = const T*; |
| 64 using reference = T&; | 63 using reference = T&; |
| 65 using const_reference = const T&; | 64 using const_reference = const T&; |
| 66 using size_type = size_t; | 65 using size_type = size_t; |
| 67 using difference_type = ptrdiff_t; | 66 using difference_type = ptrdiff_t; |
| 68 | 67 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 bool operator!=(const AlignedAllocator<T1, Alignment>& lhs, | 122 bool operator!=(const AlignedAllocator<T1, Alignment>& lhs, |
| 124 const AlignedAllocator<T2, Alignment>& rhs) CRASHPAD_NOEXCEPT { | 123 const AlignedAllocator<T2, Alignment>& rhs) CRASHPAD_NOEXCEPT { |
| 125 return false; | 124 return false; |
| 126 } | 125 } |
| 127 | 126 |
| 128 //! \brief A `std::vector` using AlignedAllocator. | 127 //! \brief A `std::vector` using AlignedAllocator. |
| 129 //! | 128 //! |
| 130 //! This is similar to `std::vector<T>`, with the addition of an alignment | 129 //! This is similar to `std::vector<T>`, with the addition of an alignment |
| 131 //! guarantee. \a Alignment must be a power of 2. If \a Alignment is not | 130 //! guarantee. \a Alignment must be a power of 2. If \a Alignment is not |
| 132 //! specified, the default alignment for type \a T is used. | 131 //! specified, the default alignment for type \a T is used. |
| 133 template <typename T, size_t Alignment = ALIGNOF(T)> | 132 template <typename T, size_t Alignment = alignof(T)> |
| 134 using AlignedVector = std::vector<T, AlignedAllocator<T, Alignment>>; | 133 using AlignedVector = std::vector<T, AlignedAllocator<T, Alignment>>; |
| 135 | 134 |
| 136 } // namespace crashpad | 135 } // namespace crashpad |
| 137 | 136 |
| 138 #undef CRASHPAD_NOEXCEPT | 137 #undef CRASHPAD_NOEXCEPT |
| 139 | 138 |
| 140 #endif // CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ | 139 #endif // CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ |
| OLD | NEW |