Array1D(int size, bool init = false, T initValue = T()) : mSize(size) { Alloc alloc; mData = alloc.allocate(mSize); if (init) { for (int i = 0; i < mSize; ++i) { alloc.construct(&mData[i], initValue); } } }
inline void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const T& item, Alloc& alloc) { ForwardIterator next = first; BOOST_TRY { for (; n > 0; ++first, --n) alloc.construct(first, item); } BOOST_CATCH(...) { for (; next != first; ++next) alloc.destroy(next); BOOST_RETHROW } BOOST_CATCH_END }
inline ForwardIterator uninitialized_copy_with_alloc(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& alloc) { ForwardIterator next = dest; BOOST_TRY { for (; first != last; ++first, ++dest) alloc.construct(dest, *first); } BOOST_CATCH(...) { for (; next != dest; ++next) alloc.destroy(next); BOOST_RETHROW } BOOST_CATCH_END return dest; }
__AGENCY_ANNOTATION typename std::enable_if< has_construct<Alloc,typename std::iterator_traits<Iterator>::pointer, Args...>::value, Iterator >::type construct_each_impl2(Alloc& a, Iterator first, Iterator last, Args&&... args) { for(; first != last; ++first) { a.construct(&*first, std::forward<Args>(args)...); } return first; } // end construct_each_impl2()
void allocator_traits<Alloc>::construct(Alloc& a, T* p, Args&&... args) { a.construct(p, std::forward<Args>(args)...); //TODO: It may not be implemented! }