ptr_vector.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
  19. #include <boost/type_traits/is_same.hpp>
  20. #include <boost/mpl/if.hpp>
  21. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  22. #pragma GCC diagnostic push
  23. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  24. #endif
  25. namespace boost
  26. {
  27. template
  28. <
  29. class T,
  30. class CloneAllocator = heap_clone_allocator,
  31. class Allocator = void
  32. >
  33. class ptr_vector : public
  34. ptr_sequence_adapter< T,
  35. std::vector<
  36. typename ptr_container_detail::void_ptr<T>::type,
  37. typename boost::mpl::if_<boost::is_same<Allocator, void>,
  38. std::allocator<typename ptr_container_detail::void_ptr<T>::type>, Allocator>::type
  39. >,
  40. CloneAllocator >
  41. {
  42. typedef
  43. ptr_sequence_adapter< T,
  44. std::vector<
  45. typename ptr_container_detail::void_ptr<T>::type,
  46. typename boost::mpl::if_<boost::is_same<Allocator, void>,
  47. std::allocator<typename ptr_container_detail::void_ptr<T>::type>, Allocator>::type
  48. >,
  49. CloneAllocator >
  50. base_class;
  51. typedef ptr_vector<T,CloneAllocator,Allocator> this_type;
  52. public:
  53. BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS( ptr_vector,
  54. base_class,
  55. this_type )
  56. explicit ptr_vector( size_type n,
  57. const allocator_type& alloc = allocator_type() )
  58. : base_class(alloc)
  59. {
  60. this->base().reserve( n );
  61. }
  62. };
  63. //////////////////////////////////////////////////////////////////////////////
  64. // clonability
  65. template< typename T, typename CA, typename A >
  66. inline ptr_vector<T,CA,A>* new_clone( const ptr_vector<T,CA,A>& r )
  67. {
  68. return r.clone().release();
  69. }
  70. /////////////////////////////////////////////////////////////////////////
  71. // swap
  72. template< typename T, typename CA, typename A >
  73. inline void swap( ptr_vector<T,CA,A>& l, ptr_vector<T,CA,A>& r )
  74. {
  75. l.swap(r);
  76. }
  77. }
  78. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  79. #pragma GCC diagnostic pop
  80. #endif
  81. #endif