|
Go to the documentation of this file.
9 #ifndef ADOBE_VECTOR_HPP
10 #define ADOBE_VECTOR_HPP
24 #include <boost/operators.hpp>
25 #include <boost/static_assert.hpp>
26 #include <boost/type_traits/has_nothrow_constructor.hpp>
27 #include <boost/type_traits/is_integral.hpp>
28 #include <boost/utility/enable_if.hpp>
36 #include <adobe/implementation/swap.hpp>
38 #ifdef ADOBE_STD_SERIALIZATION
58 class vector : boost::totally_ordered<vector<T, A>, vector<T, A> >
86 const allocator_type& allocator() const { return header_m.get().allocate_finish_m.first(); }
88 pointer& finish() { return header_m.get().allocate_finish_m.second(); }
89 const pointer& finish() const { return header_m.get().allocate_finish_m.second(); }
91 pointer& end_of_storage() { return header_m.get().end_of_storage_m; }
92 const pointer& end_of_storage() const { return header_m.get().end_of_storage_m; }
99 assert(header_m != 0 || x == 0);
100 if (header_m) header_m->finish() = x;
103 const T* end_of_storage() const { return header_m ? header_m->end_of_storage() : 0; }
107 size_type remaining() const { return end_of_storage() - end(); }
109 template < typename I>
110 void append(I f, I l) { append(f, l, typename std::iterator_traits<I>::iterator_category()); }
112 template < typename I>
113 void append(I f, I l, std::input_iterator_tag);
115 template < typename I>
116 void append(I f, I l, std::forward_iterator_tag);
118 template < typename I>
119 void append_move(I f, I l)
120 { append_move(f, l, typename std::iterator_traits<I>::iterator_category()); }
122 template < typename I>
123 void append_move(I f, I l, std::input_iterator_tag);
125 template < typename I>
126 void append_move(I f, I l, std::forward_iterator_tag);
128 template < typename I>
131 template < typename I>
143 set_finish( end() + n);
148 std::uninitialized_fill_n( end(), n, x);
149 set_finish( end() + n);
154 std::uninitialized_fill_n( end(), n, x);
155 set_finish( end() + n);
164 set_finish(std::uninitialized_copy(x. begin(), x. end(), end()));
168 template < typename I>
169 vector(I f, I l, typename boost::disable_if<boost::is_integral<I> >::type* = 0) : header_m(0)
172 template < typename I>
174 typename boost::disable_if<boost::is_integral<I> >::type* = 0) : header_m(allocate(a), 0)
181 typename allocator_type::template rebind<char>::other alloc( get_allocator());
182 alloc.deallocate(reinterpret_cast<char*>(header_m),
183 (end_of_storage() - begin()) * sizeof(T) + ( sizeof(header_t) - sizeof(T)));
231 { append_move(&x, &x + 1); }
240 template < typename I>
241 iterator insert( iterator p, I f, I l, typename boost::disable_if<boost::is_integral<I> >::type* = 0)
242 { return insert(p, f, l, typename std::iterator_traits<I>::iterator_category()); }
244 template < typename I>
261 #if defined(_MSC_VER) && _MSC_VER == 1600 && _ITERATOR_DEBUG_LEVEL != 0
263 y. begin(), std::tr1::false_type());
277 template < typename T, typename A>
281 if (a == allocator_type()) return 0;
285 typename allocator_type::template rebind<char>::other alloc(a);
287 header_t* result = reinterpret_cast<header_t* >(alloc.allocate( sizeof(header_t) - sizeof(T)
290 result->finish() = &result->storage_m[0];
291 result->end_of_storage() = result->finish() + n;
296 template < typename T, typename A>
297 template < typename I>
298 void vector<T, A>::append(I f, I l, std::input_iterator_tag) { while (f != l) { push_back(*f); ++f; } }
300 template < typename T, typename A>
301 template < typename I>
302 void vector<T, A>::append_move(I f, I l, std::input_iterator_tag)
305 template < typename T, typename A>
306 template < typename I>
307 void vector<T, A>::append(I f, I l, std::forward_iterator_tag)
312 set_finish(std::uninitialized_copy(f, l, end()));
315 template < typename T, typename A>
316 template < typename I>
317 void vector<T, A>::append_move(I f, I l, std::forward_iterator_tag)
325 template < typename T, typename A>
326 template < typename I>
327 typename vector<T, A>::iterator vector<T, A>::insert(iterator p, I f, I l, std::input_iterator_tag)
329 size_type o(p - begin());
330 size_type s = size();
334 return end() - s + o;
337 template < typename T, typename A>
338 template < typename I>
339 typename vector<T, A>::iterator vector<T, A>::insert(iterator p, I f, I l, std::forward_iterator_tag)
342 iterator last = end();
343 size_type before = p - begin();
345 if (remaining() < n) {
348 tmp.append_move(begin(), p);
350 tmp.append_move(p, last);
353 size_type after(last - p);
356 append_move(last - n, last);
361 std::advance(m, after);
363 append_move(p, last);
367 return begin() + before + n;
370 template < typename T, typename A>
371 template < typename I>
378 if (remaining() < n) {
381 tmp.append_move(begin(), p);
382 tmp.append_move(f, l);
383 tmp.append_move(p, last);
389 append_move(last - n, last);
394 std::advance(m, after);
396 append_move(p, last);
400 return begin() + before + n;
403 template < typename T, typename A>
406 if (capacity() < n) {
408 tmp.header_m = allocate(get_allocator(), n);
414 template < typename T, typename A>
420 if (remaining() < n) {
423 tmp.append_move(begin(), p);
424 std::uninitialized_fill_n(tmp. end(), n, x);
425 tmp.set_finish(tmp. end() + n);
426 tmp.append_move(p, last);
432 append_move(last - n, last);
434 std::fill_n(p, n, x);
436 std::uninitialized_fill_n(last, n - after, x);
437 set_finish(last + (n - after));
438 append_move(p, last);
439 std::fill_n(p, after, x);
442 return begin() + before + n;
445 template < typename T, typename A>
449 for ( iterator b(i), e(end()); b != e; ++b) {
456 template < typename T, typename A>
459 if (n < size()) erase(begin() + n, end());
463 template < typename T, typename A>
466 if (n < size()) erase(begin() + n, end());
467 else insert(end(), n - size(), x);
472 #ifdef ADOBE_STD_SERIALIZATION
474 template < typename T, typename A>
475 std::ostream& operator<<(std::ostream& out, const vector<T, A>& x)
510 template < typename T, typename A>
511 struct has_nothrow_constructor<adobe::version_1::vector<T, A> > : boost::mpl::true_ { };
|