| 59 | */ |
| 60 | template <class T, class Alloc = typename AllocatorTraits<T>::Type> |
| 61 | class Array : protected Alloc |
| 62 | { |
| 63 | public: |
| 64 | typedef T* Iterator; |
| 65 | typedef const T* ConstIterator; |
| 66 | |
| 67 | explicit Array(const physx::PxEMPTY v) : Alloc(v) |
| 68 | { |
| 69 | if(mData) |
| 70 | mCapacity |= PX_SIGN_BITMASK; |
| 71 | } |
| 72 | |
| 73 | /*! |
| 74 | Default array constructor. Initialize an empty array |
| 75 | */ |
| 76 | PX_INLINE explicit Array(const Alloc& alloc = Alloc()) : Alloc(alloc), mData(0), mSize(0), mCapacity(0) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | /*! |
| 81 | Initialize array with given capacity |
| 82 | */ |
| 83 | PX_INLINE explicit Array(uint32_t size, const T& a = T(), const Alloc& alloc = Alloc()) |
| 84 | : Alloc(alloc), mData(0), mSize(0), mCapacity(0) |
| 85 | { |
| 86 | resize(size, a); |
| 87 | } |
| 88 | |
| 89 | /*! |
| 90 | Copy-constructor. Copy all entries from other array |
| 91 | */ |
| 92 | template <class A> |
| 93 | PX_INLINE explicit Array(const Array<T, A>& other, const Alloc& alloc = Alloc()) |
| 94 | : Alloc(alloc) |
| 95 | { |
| 96 | copy(other); |
| 97 | } |
| 98 | |
| 99 | // This is necessary else the basic default copy constructor is used in the case of both arrays being of the same |
| 100 | // template instance |
| 101 | // The C++ standard clearly states that a template constructor is never a copy constructor [2]. In other words, |
| 102 | // the presence of a template constructor does not suppress the implicit declaration of the copy constructor. |
| 103 | // Also never make a copy constructor explicit, or copy-initialization* will no longer work. This is because |
| 104 | // 'binding an rvalue to a const reference requires an accessible copy constructor' (http://gcc.gnu.org/bugs/) |
| 105 | // *http://stackoverflow.com/questions/1051379/is-there-a-difference-in-c-between-copy-initialization-and-assignment-initializ |
| 106 | PX_INLINE Array(const Array& other, const Alloc& alloc = Alloc()) : Alloc(alloc) |
| 107 | { |
| 108 | copy(other); |
| 109 | } |
| 110 | |
| 111 | /*! |
| 112 | Initialize array with given length |
| 113 | */ |
| 114 | PX_INLINE explicit Array(const T* first, const T* last, const Alloc& alloc = Alloc()) |
| 115 | : Alloc(alloc), mSize(last < first ? 0 : uint32_t(last - first)), mCapacity(mSize) |
| 116 | { |
| 117 | mData = allocate(mSize); |
| 118 | copy(mData, mData + mSize, first); |