• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 #ifndef BOOST_PTR_CONTAINER_PTR_VECTOR_HPP
13 #define BOOST_PTR_CONTAINER_PTR_VECTOR_HPP
14 
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 # pragma once
17 #endif
18 
19 #include <vector>
20 #include <boost/ptr_container/ptr_sequence_adapter.hpp>
21 #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
22 #include <boost/type_traits/is_same.hpp>
23 #include <boost/mpl/if.hpp>
24 
25 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
26 #pragma GCC diagnostic push
27 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
28 #endif
29 
30 namespace boost
31 {
32 
33     template
34     <
35         class T,
36         class CloneAllocator = heap_clone_allocator,
37         class Allocator      = void
38     >
39     class ptr_vector : public
40         ptr_sequence_adapter< T,
41             std::vector<
42                 typename ptr_container_detail::void_ptr<T>::type,
43                 typename boost::mpl::if_<boost::is_same<Allocator, void>,
44                     std::allocator<typename ptr_container_detail::void_ptr<T>::type>, Allocator>::type
45             >,
46             CloneAllocator >
47     {
48         typedef
49 
50             ptr_sequence_adapter< T,
51                 std::vector<
52                     typename ptr_container_detail::void_ptr<T>::type,
53                     typename boost::mpl::if_<boost::is_same<Allocator, void>,
54                         std::allocator<typename ptr_container_detail::void_ptr<T>::type>, Allocator>::type
55                 >,
56                 CloneAllocator >
57 
58             base_class;
59 
60         typedef ptr_vector<T,CloneAllocator,Allocator> this_type;
61 
62     public:
63 
BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS(ptr_vector,base_class,this_type)64         BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS( ptr_vector,
65                                                       base_class,
66                                                       this_type )
67 
68         explicit ptr_vector( size_type n,
69                              const allocator_type& alloc = allocator_type() )
70           : base_class(alloc)
71         {
72             this->base().reserve( n );
73         }
74     };
75 
76     //////////////////////////////////////////////////////////////////////////////
77     // clonability
78 
79     template< typename T, typename CA, typename A >
new_clone(const ptr_vector<T,CA,A> & r)80     inline ptr_vector<T,CA,A>* new_clone( const ptr_vector<T,CA,A>& r )
81     {
82         return r.clone().release();
83     }
84 
85     /////////////////////////////////////////////////////////////////////////
86     // swap
87 
88     template< typename T, typename CA, typename A >
swap(ptr_vector<T,CA,A> & l,ptr_vector<T,CA,A> & r)89     inline void swap( ptr_vector<T,CA,A>& l, ptr_vector<T,CA,A>& r )
90     {
91         l.swap(r);
92     }
93 
94 }
95 
96 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
97 #pragma GCC diagnostic pop
98 #endif
99 
100 #endif
101