Line data Source code
1 : #ifndef VSET_MULTI_SET_HPP
2 : #define VSET_MULTI_SET_HPP
3 :
4 : #include <fas/typemanip/has_typename.hpp>
5 : #include <vset/vtree/vtree.hpp>
6 : #include <vset/vtree/strategy.hpp>
7 :
8 : namespace vset{
9 :
10 : template<typename V, typename C = std::less<V>, typename A = std::allocator<V> >
11 : class multiset;
12 :
13 : /** @internal*/
14 : namespace aspect_maker
15 : {
16 : FAS_HAS_TYPENAME(is_aspect_maker, aspect_maker)
17 :
18 : template<typename V, typename C, typename A>
19 : struct make
20 : {
21 : typedef typename A::template apply<V, C>::type aspect;
22 : };
23 :
24 : template<typename V, typename C, typename A, bool >
25 : struct multiset_impl;
26 :
27 : template<typename V, typename C, typename A>
28 : struct multiset_impl<V, C, A, true>
29 : {
30 : typedef vtree::vtree< typename make<V, C, A>::aspect > type;
31 : };
32 :
33 : template<typename V, typename C, typename A>
34 : struct multiset_impl<V, C, A, false>
35 : {
36 : typedef vtree::vtree< vtree::strategy::vtree_std_alloc<V, C, 512> > type;
37 : //typedef vtree::vtree< typename make<V, C, A>::aspect > type;
38 : };
39 :
40 :
41 : template<typename V, typename C, typename A>
42 : struct multiset
43 : {
44 : typedef typename multiset_impl<V, C, A, aspect_maker::is_aspect_maker<A>::value >::type type;
45 : };
46 : }
47 :
48 :
49 : /**
50 : @brief ассоциативный контейнер vset::multiset содержит упорядоченный набор объектов типа V (допускаются ключи с одинаковыми значениями).
51 : Сортировка производится с помощью функции сравнения ключей Compare. Операции поиска, вставки и удаления имеют отличную от `std::multiset`
52 : логорифмичскую сложность и определяется стратегией хранения, которая внедряется через аллокатор.
53 : @tparam V - тип хранимых объектов
54 : @tparam C - функции сравнения ключей
55 : @tparam A - аллокатор
56 :
57 : */
58 : template<typename V, typename C, typename A >
59 8 : class multiset
60 : : public aspect_maker::multiset<V, C, A >::type
61 : {
62 : typedef typename aspect_maker::multiset<V, C, A >::type super;
63 :
64 : public:
65 : /** Key: _key_type_ */
66 : typedef typename super::key_type key_type;
67 : /** Key: _value_type_ */
68 : typedef typename super::value_type value_type;
69 : /** Compare: _key_compare_ */
70 : typedef typename super::key_compare key_compare;
71 : /** Compare: _value_compare_ */
72 : typedef typename super::value_compare value_compare;
73 : /** Allocator */
74 : typedef typename super::allocator_type allocator_type;
75 : /** std::iterator_traits<iterator>::reference */
76 : typedef typename super::reference reference;
77 : /** std::iterator_traits<iterator>::const_reference */
78 : typedef typename super::const_reference const_reference;
79 : /** std::iterator_traits<iterator>::pointer */
80 : typedef typename super::pointer pointer;
81 : /** std::iterator_traits<iterator>::const_pointer */
82 : typedef typename super::const_pointer const_pointer;
83 : /** Итератор произвольного доступа */
84 : typedef typename super::iterator iterator;
85 : /** Константный итератор произвольного доступа */
86 : typedef typename super::const_iterator const_iterator;
87 : /** std::reverse_iterator<iterator> */
88 : typedef typename super::reverse_iterator reverse_iterator;
89 : /** std::reverse_iterator<const_iterator> */
90 : typedef typename super::const_reverse_iterator const_reverse_iterator;
91 : /** Знаковый целочисленный тип (обычно std::ptrdiff_t) */
92 : typedef typename super::difference_type difference_type;
93 : /** Беззнаковый целочисленный тип (обычно size_t) */
94 : typedef typename super::size_type size_type;
95 :
96 : /**
97 : * @brief Конструктор по умолчанию. Создаёт пустой контейнер.
98 : */
99 6 : multiset(): super() {}
100 :
101 : /**
102 : * @brief Конструктор создаёт пустой контейнер.
103 : * @param comp функции сравнения ключей
104 : * @param alloc функции сравнения ключей
105 : */
106 2 : explicit multiset(const key_compare& comp, const allocator_type& alloc = allocator_type() )
107 2 : : super(comp, alloc)
108 : {
109 2 : }
110 :
111 : /**
112 : * @brief Создаёт контейнер с содержимым из диапазона [first, last).
113 : * @param first итератор начала диапазона
114 : * @param last итератор конеца диапазона
115 : */
116 : template<typename InputIterator>
117 : multiset(InputIterator first, InputIterator last)
118 : : super( first, last)
119 : {
120 : }
121 :
122 : /**
123 : * @brief Создаёт контейнер с содержимым из диапазона [first, last).
124 : * @param first итератор начала диапазона
125 : * @param last итератор конеца диапазона
126 : * @param comp функции сравнения ключей
127 : * @param alloc функции сравнения ключей
128 : */
129 : template<typename InputIterator>
130 : multiset(InputIterator first, InputIterator last, const value_compare& comp, const allocator_type& alloc= allocator_type() )
131 : : super( first, last, comp, alloc)
132 : {
133 : }
134 :
135 : /**
136 : * @brief Конструктор копирования
137 : * @details Для персистентных контейнеров копирование запрещено
138 : */
139 : multiset(const multiset& other)
140 : : super( other )
141 : {}
142 :
143 : #ifdef __GXX_EXPERIMENTAL_CXX0X__
144 : /**
145 : * @brief Move-конструктор (c++11). Создает контейнер с содержимым other с использованием move-семантики.
146 : * Если alloc не был предоставлен, то он будет получен с помощью move-конструктора от аллокатора принадлежащего other.
147 : * @param other другой контейнер, который будет использован в качестве источника данных для инициализации элементов контейнера
148 : */
149 : multiset(multiset&& other)
150 : : super( std::move(other) )
151 : {
152 : }
153 :
154 : /**
155 : * @brief Создает контейнер с содержимым списка инициализации init (c++11).
156 : * @param init — список инициализации элементов контейнера
157 : * @param comp функции сравнения ключей
158 : * @param alloc функции сравнения ключей
159 : */
160 : multiset( const std::initializer_list<value_type>& init,
161 : const value_compare& comp= value_compare(),
162 : const allocator_type& alloc= allocator_type()
163 : ) : super( init, comp, alloc )
164 : {
165 : }
166 :
167 : #endif
168 :
169 : /**
170 : * @brief Заменяет содержимое копией содержимого other
171 : * @param other другой контейнер, который будет использоваться в качестве источника
172 : */
173 : multiset& operator=(const multiset& other)
174 : {
175 : super::operator = (other);
176 : return *this;
177 : }
178 :
179 : #ifdef __GXX_EXPERIMENTAL_CXX0X__
180 :
181 : /**
182 : * @brief Заменяет содержимое содержимым other использованием семантики переноса (c++11)
183 : * @param other другой контейнер, который будет использоваться в качестве источника
184 : */
185 : multiset& operator=(multiset&& other)
186 : {
187 : super::operator = (std::move(other) );
188 : return *this;
189 : }
190 :
191 : /**
192 : * @brief Заменяет содержимое элементами, которые указаны в списке идентификаторов инициализатора (c++11).
193 : * @param il список инициализации для использования в качестве источника данных
194 : */
195 : multiset& operator=( std::initializer_list<value_type> il)
196 : {
197 : super::operator = (std::move(il) );
198 : return *this;
199 : }
200 :
201 : #endif
202 : };
203 :
204 : }
205 : #endif
|