// ======================================================================== // // Copyright 2009-2017 Intel Corporation // // // // Licensed under the Apache License, Version 2.0 (the "License"); // // you may not use this file except in compliance with the License. // // You may obtain a copy of the License at // // // // http://www.apache.org/licenses/LICENSE-2.0 // // // // Unless required by applicable law or agreed to in writing, software // // distributed under the License is distributed on an "AS IS" BASIS, // // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // // See the License for the specific language governing permissions and // // limitations under the License. // // ======================================================================== // namespace embree { template class vector_t { public: typedef T value_type; typedef T* iterator; typedef const T* const_iterator; #if defined(VECTOR_INIT_ALLOCATOR) template __forceinline vector_t (M alloc) : alloc(alloc), size_active(0), size_alloced(0), items(nullptr) {} template __forceinline vector_t (M alloc, size_t sz) : alloc(alloc), size_active(0), size_alloced(0), items(nullptr) { internal_resize_init(sz); } #else __forceinline vector_t () : size_active(0), size_alloced(0), items(nullptr) {} __forceinline explicit vector_t (size_t sz) : size_active(0), size_alloced(0), items(nullptr) { internal_resize_init(sz); } #endif __forceinline ~vector_t() { clear(); } __forceinline vector_t (const vector_t& other) { size_active = other.size_active; size_alloced = other.size_alloced; items = alloc.allocate(size_alloced); for (size_t i=0; i 0); return items[0]; }; __forceinline T& back () const { assert(size_active > 0); return items[size_active-1]; }; __forceinline T* data() { return items; }; __forceinline const T* data() const { return items; }; /******************** Modifiers **************************/ __forceinline void push_back(const T& nt) { const T v = nt; // need local copy as input reference could point to this vector internal_grow(size_active+1); ::new (&items[size_active++]) T(v); } __forceinline void pop_back() { assert(!empty()); size_active--; alloc.destroy(&items[size_active]); } __forceinline void clear() { /* destroy elements */ for (size_t i=0; i