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_LIST_HPP |
13 | #define BOOST_PTR_CONTAINER_PTR_LIST_HPP |
14 | |
15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) |
16 | # pragma once |
17 | #endif |
18 | |
19 | #include <boost/ptr_container/ptr_sequence_adapter.hpp> |
20 | #include <list> |
21 | |
22 | namespace boost |
23 | { |
24 | |
25 | template |
26 | < |
27 | class T, |
28 | class CloneAllocator = heap_clone_allocator, |
29 | class Allocator = std::allocator<void*> |
30 | > |
31 | class ptr_list : public |
32 | ptr_sequence_adapter< T, |
33 | std::list<void*,Allocator>, |
34 | CloneAllocator > |
35 | { |
36 | typedef ptr_sequence_adapter< T, |
37 | std::list<void*,Allocator>, |
38 | CloneAllocator > |
39 | base_class; |
40 | |
41 | typedef ptr_list<T,CloneAllocator,Allocator> this_type; |
42 | |
43 | public: |
44 | BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS( ptr_list, |
45 | base_class, |
46 | this_type ) |
47 | |
48 | typedef BOOST_DEDUCED_TYPENAME base_class::value_type value_type; |
49 | |
50 | public: |
51 | using base_class::merge; |
52 | |
53 | void merge( ptr_list& x ) |
54 | { |
55 | merge( x, std::less<T>() ); |
56 | } |
57 | |
58 | template< typename Compare > |
59 | void merge( ptr_list& x, Compare comp ) |
60 | { |
61 | this->base().merge( x.base(), void_ptr_indirect_fun<Compare,T>( comp ) ); } |
62 | |
63 | void sort() |
64 | { |
65 | sort( std::less<T>() ); |
66 | }; |
67 | |
68 | template< typename Compare > |
69 | void sort( Compare comp ) |
70 | { |
71 | this->base().sort( void_ptr_indirect_fun<Compare,T>( comp ) ); |
72 | } |
73 | |
74 | template< class Pred > |
75 | void erase_if( iterator first, iterator last, Pred pred ) |
76 | { |
77 | base_class::erase_if( first, last, pred ); |
78 | } |
79 | |
80 | template< class Pred > |
81 | void erase_if( Pred pred ) |
82 | { |
83 | this->base().remove_if( BOOST_DEDUCED_TYPENAME base_class:: |
84 | BOOST_NESTED_TEMPLATE void_ptr_delete_if<Pred,value_type> |
85 | (pred) ); |
86 | } |
87 | |
88 | }; // class 'ptr_list' |
89 | |
90 | ////////////////////////////////////////////////////////////////////////////// |
91 | // clonability |
92 | |
93 | template< typename T, typename CA, typename A > |
94 | inline ptr_list<T,CA,A>* new_clone( const ptr_list<T,CA,A>& r ) |
95 | { |
96 | return r.clone().release(); |
97 | } |
98 | |
99 | ///////////////////////////////////////////////////////////////////////// |
100 | // swap |
101 | |
102 | template< typename T, typename CA, typename A > |
103 | inline void swap( ptr_list<T,CA,A>& l, ptr_list<T,CA,A>& r ) |
104 | { |
105 | l.swap(r); |
106 | } |
107 | } |
108 | |
109 | |
110 | #endif |
111 | |