ptr_vector.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // Boost.Pointer Container
  3. //
  4. // Copyright Thorsten Ottosen 2003-2005. Use, modification and
  5. // distribution is subject to the Boost Software License, Version
  6. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // For more information, see http://www.boost.org/libs/ptr_container/
  10. //
  11. #ifndef BOOST_PTR_CONTAINER_PTR_VECTOR_HPP
  12. #define BOOST_PTR_CONTAINER_PTR_VECTOR_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif
  16. #include <vector>
  17. #include <boost/ptr_container/ptr_sequence_adapter.hpp>
  18. namespace boost
  19. {
  20. template
  21. <
  22. class T,
  23. class CloneAllocator = heap_clone_allocator,
  24. class Allocator = std::allocator<void*>
  25. >
  26. class ptr_vector : public
  27. ptr_sequence_adapter< T,
  28. std::vector<void*,Allocator>,
  29. CloneAllocator >
  30. {
  31. typedef ptr_sequence_adapter< T,
  32. std::vector<void*,Allocator>,
  33. CloneAllocator >
  34. base_class;
  35. typedef ptr_vector<T,CloneAllocator,Allocator> this_type;
  36. public:
  37. BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS( ptr_vector,
  38. base_class,
  39. this_type )
  40. explicit ptr_vector( size_type n,
  41. const allocator_type& alloc = allocator_type() )
  42. : base_class(alloc)
  43. {
  44. this->base().reserve( n );
  45. }
  46. };
  47. //////////////////////////////////////////////////////////////////////////////
  48. // clonability
  49. template< typename T, typename CA, typename A >
  50. inline ptr_vector<T,CA,A>* new_clone( const ptr_vector<T,CA,A>& r )
  51. {
  52. return r.clone().release();
  53. }
  54. /////////////////////////////////////////////////////////////////////////
  55. // swap
  56. template< typename T, typename CA, typename A >
  57. inline void swap( ptr_vector<T,CA,A>& l, ptr_vector<T,CA,A>& r )
  58. {
  59. l.swap(r);
  60. }
  61. }
  62. #endif