_set.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. /*
  2. * Copyright (c) 2005
  3. * Francois Dumont
  4. *
  5. * This material is provided "as is", with absolutely no warranty expressed
  6. * or implied. Any use is at your own risk.
  7. *
  8. * Permission to use or copy this software for any purpose is hereby granted
  9. * without fee, provided the above notices are retained on all copies.
  10. * Permission to modify the code and to distribute modified code is granted,
  11. * provided the above notices are retained, and a notice that the code was
  12. * modified is included with the above copyright notice.
  13. */
  14. /* NOTE: This is an internal header file, included by other STL headers.
  15. * You should not attempt to use it directly.
  16. */
  17. #ifndef _STLP_PTR_SPECIALIZED_SET_H
  18. #define _STLP_PTR_SPECIALIZED_SET_H
  19. #ifndef _STLP_POINTERS_SPEC_TOOLS_H
  20. # include <stl/pointers/_tools.h>
  21. #endif
  22. _STLP_BEGIN_NAMESPACE
  23. #if defined (__BORLANDC__) || defined (__DMC__)
  24. # define typename
  25. #endif
  26. //Specific iterator traits creation
  27. _STLP_CREATE_ITERATOR_TRAITS(SetTraitsT, Const_traits)
  28. #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  29. _STLP_EXPORT template struct _STLP_CLASS_DECLSPEC less<void*>;
  30. _STLP_MOVE_TO_PRIV_NAMESPACE
  31. typedef _Rb_tree_node<void*> _Node;
  32. _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<_Rb_tree_node_base, _Node, allocator<_Node> >;
  33. _STLP_EXPORT_TEMPLATE_CLASS _Rb_tree_base<void*, allocator<void*> >;
  34. # if defined (_STLP_DEBUG)
  35. _STLP_EXPORT_TEMPLATE_CLASS _DbgCompare<void*, less<void*> >;
  36. # define _Rb_tree _STLP_NON_DBG_NAME(Rb_tree)
  37. _STLP_EXPORT_TEMPLATE_CLASS _Rb_tree<void*, _DbgCompare<void*, less<void*> >, void*, _Identity<void*>,
  38. _SetTraitsT<void*>, allocator<void*> >;
  39. # undef _Rb_tree
  40. # endif
  41. _STLP_EXPORT_TEMPLATE_CLASS _Rb_tree<void*, less<void*>, void*, _Identity<void*>,
  42. _SetTraitsT<void*>, allocator<void*> >;
  43. _STLP_MOVE_TO_STD_NAMESPACE
  44. #endif
  45. template <class _Key, _STLP_DFL_TMPL_PARAM(_Compare, less<_Key>),
  46. _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Key>) >
  47. class set
  48. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
  49. : public __stlport_class<set<_Key, _Compare, _Alloc> >
  50. #endif
  51. {
  52. #if !defined (__BORLANDC__)
  53. typedef _STLP_PRIV _AssocStorageTypes<_Key, _Compare> _AssocStorageTypes;
  54. typedef typename _AssocStorageTypes::_KeyStorageType _KeyStorageType;
  55. typedef typename _AssocStorageTypes::_CompareStorageType _CompareStorageType;
  56. #else
  57. typedef _STLP_PRIV _AssocStorageTypes<_Key, _Compare>::_KeyStorageType _KeyStorageType;
  58. typedef _STLP_PRIV _AssocStorageTypes<_Key, _Compare>::_CompareStorageType _CompareStorageType;
  59. #endif
  60. typedef typename _Alloc_traits<_KeyStorageType, _Alloc>::allocator_type _StorageTypeAlloc;
  61. typedef _STLP_PRIV _CastTraits<_KeyStorageType, _Key> cast_traits;
  62. typedef set<_Key, _Compare, _Alloc> _Self;
  63. public:
  64. typedef _Key key_type;
  65. typedef _Key value_type;
  66. typedef _Compare key_compare;
  67. typedef _Compare value_compare;
  68. protected:
  69. //Specific iterator traits creation
  70. typedef _STLP_PRIV _SetTraitsT<value_type> _SetTraits;
  71. typedef _STLP_PRIV _Rb_tree<key_type, key_compare,
  72. value_type, _STLP_PRIV _Identity<value_type>,
  73. _SetTraits, _Alloc> _Priv_Rep_type;
  74. typedef _STLP_PRIV _SetTraitsT<_KeyStorageType> _SetStorageTraits;
  75. public:
  76. //dums: need the following public for the __move_traits framework
  77. typedef _STLP_PRIV _Rb_tree<_KeyStorageType, _CompareStorageType,
  78. _KeyStorageType, _STLP_PRIV _Identity<_KeyStorageType>,
  79. _SetStorageTraits, _StorageTypeAlloc> _Rep_type;
  80. private:
  81. typedef typename _Rep_type::iterator base_iterator;
  82. typedef typename _Rep_type::const_iterator const_base_iterator;
  83. public:
  84. typedef typename _Priv_Rep_type::pointer pointer;
  85. typedef typename _Priv_Rep_type::const_pointer const_pointer;
  86. typedef typename _Priv_Rep_type::reference reference;
  87. typedef typename _Priv_Rep_type::const_reference const_reference;
  88. typedef typename _Priv_Rep_type::iterator iterator;
  89. typedef typename _Priv_Rep_type::const_iterator const_iterator;
  90. typedef typename _Priv_Rep_type::reverse_iterator reverse_iterator;
  91. typedef typename _Priv_Rep_type::const_reverse_iterator const_reverse_iterator;
  92. typedef typename _Priv_Rep_type::size_type size_type;
  93. typedef typename _Priv_Rep_type::difference_type difference_type;
  94. typedef typename _Priv_Rep_type::allocator_type allocator_type;
  95. private:
  96. _Rep_type _M_t; // red-black tree representing set
  97. _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
  98. #if defined (_STLP_DEBUG)
  99. static iterator _S_to_value_ite(const_base_iterator __ite)
  100. { return iterator(__ite._Owner(), __ite._M_iterator._M_node); }
  101. static base_iterator _S_to_storage_ite(const_iterator __ite)
  102. { return base_iterator(__ite._Owner(), __ite._M_iterator._M_node); }
  103. #else
  104. static iterator _S_to_value_ite(const_base_iterator __ite)
  105. { return iterator(__ite._M_node); }
  106. static base_iterator _S_to_storage_ite(const_iterator __ite)
  107. { return base_iterator(__ite._M_node); }
  108. #endif
  109. public:
  110. set() : _M_t(_CompareStorageType(), _StorageTypeAlloc()) {}
  111. explicit set(const _Compare& __comp,
  112. const allocator_type& __a = allocator_type())
  113. : _M_t(__comp, _STLP_CONVERT_ALLOCATOR(__a, _KeyStorageType)) {}
  114. #if defined (_STLP_MEMBER_TEMPLATES)
  115. template <class _InputIterator>
  116. set(_InputIterator __first, _InputIterator __last)
  117. : _M_t(_Compare(), _StorageTypeAlloc()) {
  118. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  119. _M_t.insert_unique(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__first),
  120. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__last));
  121. # else
  122. _M_t.insert_unique(__first, __last);
  123. # endif
  124. }
  125. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  126. template <class _InputIterator>
  127. set(_InputIterator __first, _InputIterator __last, const _Compare& __comp)
  128. : _M_t(__comp, _StorageTypeAlloc()) {
  129. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  130. _M_t.insert_unique(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__first),
  131. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__last));
  132. # else
  133. _M_t.insert_unique(__first, __last);
  134. # endif
  135. }
  136. # endif
  137. template <class _InputIterator>
  138. set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
  139. const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
  140. : _M_t(__comp, _STLP_CONVERT_ALLOCATOR(__a, _KeyStorageType)) {
  141. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  142. _M_t.insert_unique(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__first),
  143. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__last));
  144. # else
  145. _M_t.insert_unique(__first, __last);
  146. # endif
  147. }
  148. #else
  149. set(const value_type* __first, const value_type* __last)
  150. : _M_t(_Compare(), _StorageTypeAlloc()) {
  151. _M_t.insert_unique(cast_traits::to_storage_type_cptr(__first),
  152. cast_traits::to_storage_type_cptr(__last));
  153. }
  154. set(const value_type* __first, const value_type* __last,
  155. const _Compare& __comp, const allocator_type& __a = allocator_type())
  156. : _M_t(__comp, _STLP_CONVERT_ALLOCATOR(__a, _KeyStorageType)) {
  157. _M_t.insert_unique(cast_traits::to_storage_type_cptr(__first),
  158. cast_traits::to_storage_type_cptr(__last));
  159. }
  160. set(const_iterator __first, const_iterator __last)
  161. : _M_t(_Compare(), _StorageTypeAlloc())
  162. { _M_t.insert_unique(_S_to_storage_ite(__first), _S_to_storage_ite(__last)); }
  163. set(const_iterator __first, const_iterator __last,
  164. const _Compare& __comp, const allocator_type& __a = allocator_type())
  165. : _M_t(__comp, _STLP_CONVERT_ALLOCATOR(__a, _KeyStorageType))
  166. { _M_t.insert_unique(_S_to_storage_ite(__first), _S_to_storage_ite(__last)); }
  167. #endif /* _STLP_MEMBER_TEMPLATES */
  168. set(const _Self& __x) : _M_t(__x._M_t) {}
  169. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  170. set(__move_source<_Self> src)
  171. : _M_t(__move_source<_Rep_type>(src.get()._M_t)) {}
  172. #endif
  173. _Self& operator=(const _Self& __x) {
  174. _M_t = __x._M_t;
  175. return *this;
  176. }
  177. // accessors:
  178. key_compare key_comp() const { return _M_t.key_comp(); }
  179. value_compare value_comp() const { return _M_t.key_comp(); }
  180. allocator_type get_allocator() const
  181. { return _STLP_CONVERT_ALLOCATOR(_M_t.get_allocator(), value_type); }
  182. iterator begin() { return _S_to_value_ite(_M_t.begin()); }
  183. iterator end() { return _S_to_value_ite(_M_t.end()); }
  184. const_iterator begin() const { return _S_to_value_ite(_M_t.begin()); }
  185. const_iterator end() const { return _S_to_value_ite(_M_t.end()); }
  186. reverse_iterator rbegin() { return reverse_iterator(end()); }
  187. reverse_iterator rend() { return reverse_iterator(begin()); }
  188. const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
  189. const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
  190. bool empty() const { return _M_t.empty(); }
  191. size_type size() const { return _M_t.size(); }
  192. size_type max_size() const { return _M_t.max_size(); }
  193. void swap(_Self& __x) { _M_t.swap(__x._M_t); }
  194. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  195. void _M_swap_workaround(_Self& __x) { swap(__x); }
  196. #endif
  197. // insert/erase
  198. pair<iterator,bool> insert(const value_type& __x) {
  199. pair<base_iterator, bool> ret = _M_t.insert_unique(cast_traits::to_storage_type_cref(__x));
  200. return pair<iterator, bool>(_S_to_value_ite(ret.first), ret.second);
  201. }
  202. iterator insert(iterator __pos, const value_type& __x)
  203. { return _S_to_value_ite(_M_t.insert_unique(_S_to_storage_ite(__pos), cast_traits::to_storage_type_cref(__x))); }
  204. #if defined (_STLP_MEMBER_TEMPLATES)
  205. template <class _InputIterator>
  206. void insert(_InputIterator __first, _InputIterator __last) {
  207. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  208. _M_t.insert_unique(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__first),
  209. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__last));
  210. # else
  211. _M_t.insert_unique(__first, __last);
  212. # endif
  213. }
  214. #else
  215. void insert(const_iterator __first, const_iterator __last)
  216. { _M_t.insert_unique(_S_to_storage_ite(__first), _S_to_storage_ite(__last)); }
  217. void insert(const value_type* __first, const value_type* __last) {
  218. _M_t.insert_unique(cast_traits::to_storage_type_cptr(__first),
  219. cast_traits::to_storage_type_cptr(__last));
  220. }
  221. #endif
  222. void erase(iterator __pos)
  223. { _M_t.erase(_S_to_storage_ite(__pos)); }
  224. size_type erase(const key_type& __x)
  225. { return _M_t.erase_unique(cast_traits::to_storage_type_cref(__x)); }
  226. void erase(iterator __first, iterator __last)
  227. { _M_t.erase(_S_to_storage_ite(__first), _S_to_storage_ite(__last)); }
  228. void clear() { _M_t.clear(); }
  229. // set operations:
  230. _STLP_TEMPLATE_FOR_CONT_EXT
  231. const_iterator find(const _KT& __x) const
  232. { return _S_to_value_ite(_M_t.find(cast_traits::to_storage_type_crefT(__x))); }
  233. _STLP_TEMPLATE_FOR_CONT_EXT
  234. iterator find(const _KT& __x)
  235. { return _S_to_value_ite(_M_t.find(cast_traits::to_storage_type_crefT(__x))); }
  236. _STLP_TEMPLATE_FOR_CONT_EXT
  237. size_type count(const _KT& __x) const
  238. { return _M_t.find(cast_traits::to_storage_type_crefT(__x)) == _M_t.end() ? 0 : 1; }
  239. _STLP_TEMPLATE_FOR_CONT_EXT
  240. iterator lower_bound(const _KT& __x)
  241. { return _S_to_value_ite(_M_t.lower_bound(cast_traits::to_storage_type_crefT(__x))); }
  242. _STLP_TEMPLATE_FOR_CONT_EXT
  243. const_iterator lower_bound(const _KT& __x) const
  244. { return _S_to_value_ite(_M_t.lower_bound(cast_traits::to_storage_type_crefT(__x))); }
  245. _STLP_TEMPLATE_FOR_CONT_EXT
  246. iterator upper_bound(const _KT& __x)
  247. { return _S_to_value_ite(_M_t.upper_bound(cast_traits::to_storage_type_crefT(__x))); }
  248. _STLP_TEMPLATE_FOR_CONT_EXT
  249. const_iterator upper_bound(const _KT& __x) const
  250. { return _S_to_value_ite(_M_t.upper_bound(cast_traits::to_storage_type_crefT(__x))); }
  251. _STLP_TEMPLATE_FOR_CONT_EXT
  252. pair<iterator, iterator> equal_range(const _KT& __x) {
  253. pair<base_iterator, base_iterator> __ret;
  254. __ret = _M_t.equal_range(cast_traits::to_storage_type_crefT(__x));
  255. return pair<iterator, iterator>(_S_to_value_ite(__ret.first),
  256. _S_to_value_ite(__ret.second));
  257. }
  258. _STLP_TEMPLATE_FOR_CONT_EXT
  259. pair<const_iterator, const_iterator> equal_range(const _KT& __x) const {
  260. pair<const_base_iterator, const_base_iterator> __ret;
  261. __ret = _M_t.equal_range_unique(cast_traits::to_storage_type_crefT(__x));
  262. return pair<const_iterator, const_iterator>(_S_to_value_ite(__ret.first),
  263. _S_to_value_ite(__ret.second));
  264. }
  265. };
  266. //Specific iterator traits creation
  267. _STLP_CREATE_ITERATOR_TRAITS(MultisetTraitsT, Const_traits)
  268. template <class _Key, _STLP_DFL_TMPL_PARAM(_Compare, less<_Key>),
  269. _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Key>) >
  270. class multiset
  271. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
  272. : public __stlport_class<multiset<_Key, _Compare, _Alloc> >
  273. #endif
  274. {
  275. #if !defined (__BORLANDC__)
  276. typedef _STLP_PRIV _AssocStorageTypes<_Key, _Compare> _AssocStorageTypes;
  277. typedef typename _AssocStorageTypes::_KeyStorageType _KeyStorageType;
  278. typedef typename _AssocStorageTypes::_CompareStorageType _CompareStorageType;
  279. #else
  280. typedef _STLP_PRIV _AssocStorageTypes<_Key, _Compare>::_KeyStorageType _KeyStorageType;
  281. typedef _STLP_PRIV _AssocStorageTypes<_Key, _Compare>::_CompareStorageType _CompareStorageType;
  282. #endif
  283. typedef typename _Alloc_traits<_KeyStorageType, _Alloc>::allocator_type _StorageTypeAlloc;
  284. typedef _STLP_PRIV _CastTraits<_KeyStorageType, _Key> cast_traits;
  285. typedef multiset<_Key, _Compare, _Alloc> _Self;
  286. public:
  287. // typedefs:
  288. typedef _Key key_type;
  289. typedef _Key value_type;
  290. typedef _Compare key_compare;
  291. typedef _Compare value_compare;
  292. protected:
  293. //Specific iterator traits creation
  294. typedef _STLP_PRIV _MultisetTraitsT<value_type> _MultisetTraits;
  295. typedef _STLP_PRIV _Rb_tree<key_type, key_compare,
  296. value_type, _STLP_PRIV _Identity<value_type>,
  297. _MultisetTraits, _Alloc> _Priv_Rep_type;
  298. typedef _STLP_PRIV _MultisetTraitsT<_KeyStorageType> _MultisetStorageTraits;
  299. public:
  300. //dums: need the following public for the __move_traits framework
  301. typedef _STLP_PRIV _Rb_tree<_KeyStorageType, _CompareStorageType,
  302. _KeyStorageType, _STLP_PRIV _Identity<_KeyStorageType>,
  303. _MultisetStorageTraits, _StorageTypeAlloc> _Rep_type;
  304. private:
  305. typedef typename _Rep_type::iterator base_iterator;
  306. typedef typename _Rep_type::const_iterator const_base_iterator;
  307. public:
  308. typedef typename _Priv_Rep_type::pointer pointer;
  309. typedef typename _Priv_Rep_type::const_pointer const_pointer;
  310. typedef typename _Priv_Rep_type::reference reference;
  311. typedef typename _Priv_Rep_type::const_reference const_reference;
  312. typedef typename _Priv_Rep_type::iterator iterator;
  313. typedef typename _Priv_Rep_type::const_iterator const_iterator;
  314. typedef typename _Priv_Rep_type::reverse_iterator reverse_iterator;
  315. typedef typename _Priv_Rep_type::const_reverse_iterator const_reverse_iterator;
  316. typedef typename _Priv_Rep_type::size_type size_type;
  317. typedef typename _Priv_Rep_type::difference_type difference_type;
  318. typedef typename _Priv_Rep_type::allocator_type allocator_type;
  319. private:
  320. _Rep_type _M_t; // red-black tree representing multiset
  321. _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
  322. #if defined (_STLP_DEBUG)
  323. static iterator _S_to_value_ite(const_base_iterator __ite)
  324. { return iterator(__ite._Owner(), __ite._M_iterator._M_node); }
  325. static base_iterator _S_to_storage_ite(const_iterator __ite)
  326. { return base_iterator(__ite._Owner(), __ite._M_iterator._M_node); }
  327. #else
  328. static iterator _S_to_value_ite(const_base_iterator __ite)
  329. { return iterator(__ite._M_node); }
  330. static base_iterator _S_to_storage_ite(const_iterator __ite)
  331. { return base_iterator(__ite._M_node); }
  332. #endif
  333. public:
  334. multiset() : _M_t(_Compare(), _StorageTypeAlloc()) {}
  335. explicit multiset(const _Compare& __comp,
  336. const allocator_type& __a = allocator_type())
  337. : _M_t(__comp, _STLP_CONVERT_ALLOCATOR(__a, _KeyStorageType)) {}
  338. #if defined (_STLP_MEMBER_TEMPLATES)
  339. template <class _InputIterator>
  340. multiset(_InputIterator __first, _InputIterator __last)
  341. : _M_t(_Compare(), _StorageTypeAlloc()) {
  342. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  343. _M_t.insert_equal(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__first),
  344. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__last));
  345. # else
  346. _M_t.insert_equal(__first, __last);
  347. # endif
  348. }
  349. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  350. template <class _InputIterator>
  351. multiset(_InputIterator __first, _InputIterator __last,
  352. const _Compare& __comp)
  353. : _M_t(__comp, _StorageTypeAlloc()) {
  354. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  355. _M_t.insert_equal(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__first),
  356. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__last));
  357. # else
  358. _M_t.insert_equal(__first, __last);
  359. # endif
  360. }
  361. # endif
  362. template <class _InputIterator>
  363. multiset(_InputIterator __first, _InputIterator __last,
  364. const _Compare& __comp,
  365. const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
  366. : _M_t(__comp, _STLP_CONVERT_ALLOCATOR(__a, _KeyStorageType)) {
  367. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  368. _M_t.insert_equal(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__first),
  369. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__last));
  370. # else
  371. _M_t.insert_equal(__first, __last);
  372. # endif
  373. }
  374. #else
  375. multiset(const value_type* __first, const value_type* __last)
  376. : _M_t(_Compare(), _StorageTypeAlloc()) {
  377. _M_t.insert_equal(cast_traits::to_storage_type_cptr(__first),
  378. cast_traits::to_storage_type_cptr(__last));
  379. }
  380. multiset(const value_type* __first, const value_type* __last,
  381. const _Compare& __comp,
  382. const allocator_type& __a = allocator_type())
  383. : _M_t(__comp, _STLP_CONVERT_ALLOCATOR(__a, _KeyStorageType)) {
  384. _M_t.insert_equal(cast_traits::to_storage_type_cptr(__first),
  385. cast_traits::to_storage_type_cptr(__last));
  386. }
  387. multiset(const_iterator __first, const_iterator __last)
  388. : _M_t(_Compare(), _StorageTypeAlloc())
  389. { _M_t.insert_equal(_S_to_storage_ite(__first), _S_to_storage_ite(__last)); }
  390. multiset(const_iterator __first, const_iterator __last,
  391. const _Compare& __comp,
  392. const allocator_type& __a = allocator_type())
  393. : _M_t(__comp, _STLP_CONVERT_ALLOCATOR(__a, _KeyStorageType))
  394. { _M_t.insert_equal(_S_to_storage_ite(__first), _S_to_storage_ite(__last)); }
  395. #endif /* _STLP_MEMBER_TEMPLATES */
  396. multiset(const _Self& __x)
  397. : _M_t(__x._M_t) {}
  398. _Self& operator=(const _Self& __x) {
  399. _M_t = __x._M_t;
  400. return *this;
  401. }
  402. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  403. multiset(__move_source<_Self> src)
  404. : _M_t(__move_source<_Rep_type>(src.get()._M_t)) {}
  405. #endif
  406. // accessors:
  407. key_compare key_comp() const { return _M_t.key_comp(); }
  408. value_compare value_comp() const { return _M_t.key_comp(); }
  409. allocator_type get_allocator() const
  410. { return _STLP_CONVERT_ALLOCATOR(_M_t.get_allocator(), value_type); }
  411. iterator begin() { return _S_to_value_ite(_M_t.begin()); }
  412. iterator end() { return _S_to_value_ite(_M_t.end()); }
  413. const_iterator begin() const { return _S_to_value_ite(_M_t.begin()); }
  414. const_iterator end() const { return _S_to_value_ite(_M_t.end()); }
  415. reverse_iterator rbegin() { return reverse_iterator(end()); }
  416. reverse_iterator rend() { return reverse_iterator(begin()); }
  417. const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
  418. const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
  419. bool empty() const { return _M_t.empty(); }
  420. size_type size() const { return _M_t.size(); }
  421. size_type max_size() const { return _M_t.max_size(); }
  422. void swap(_Self& __x) { _M_t.swap(__x._M_t); }
  423. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  424. void _M_swap_workaround(_Self& __x) { swap(__x); }
  425. #endif
  426. // insert/erase
  427. iterator insert(const value_type& __x)
  428. { return _S_to_value_ite(_M_t.insert_equal(cast_traits::to_storage_type_cref(__x))); }
  429. iterator insert(iterator __pos, const value_type& __x) {
  430. return _S_to_value_ite(_M_t.insert_equal(_S_to_storage_ite(__pos),
  431. cast_traits::to_storage_type_cref(__x)));
  432. }
  433. #if defined (_STLP_MEMBER_TEMPLATES)
  434. template <class _InputIterator>
  435. void insert(_InputIterator __first, _InputIterator __last) {
  436. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  437. _M_t.insert_equal(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__first),
  438. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_KeyStorageType, _Key, _InputIterator>::_Ite(__last));
  439. # else
  440. _M_t.insert_equal(__first, __last);
  441. # endif
  442. }
  443. #else
  444. void insert(const value_type* __first, const value_type* __last) {
  445. _M_t.insert_equal(cast_traits::to_storage_type_cptr(__first),
  446. cast_traits::to_storage_type_cptr(__last));
  447. }
  448. void insert(const_iterator __first, const_iterator __last)
  449. { _M_t.insert_equal(_S_to_storage_ite(__first), _S_to_storage_ite(__last)); }
  450. #endif /* _STLP_MEMBER_TEMPLATES */
  451. void erase(iterator __pos)
  452. { _M_t.erase(_S_to_storage_ite(__pos)); }
  453. size_type erase(const key_type& __x)
  454. { return _M_t.erase(cast_traits::to_storage_type_cref(__x)); }
  455. void erase(iterator __first, iterator __last)
  456. { _M_t.erase(_S_to_storage_ite(__first), _S_to_storage_ite(__last)); }
  457. void clear() { _M_t.clear(); }
  458. // multiset operations:
  459. _STLP_TEMPLATE_FOR_CONT_EXT
  460. iterator find(const _KT& __x)
  461. { return _S_to_value_ite(_M_t.find(cast_traits::to_storage_type_crefT(__x))); }
  462. _STLP_TEMPLATE_FOR_CONT_EXT
  463. const_iterator find(const _KT& __x) const
  464. { return _S_to_value_ite(_M_t.find(cast_traits::to_storage_type_crefT(__x))); }
  465. _STLP_TEMPLATE_FOR_CONT_EXT
  466. size_type count(const _KT& __x) const
  467. { return _M_t.count(cast_traits::to_storage_type_crefT(__x)); }
  468. _STLP_TEMPLATE_FOR_CONT_EXT
  469. iterator lower_bound(const _KT& __x)
  470. { return _S_to_value_ite(_M_t.lower_bound(cast_traits::to_storage_type_crefT(__x))); }
  471. _STLP_TEMPLATE_FOR_CONT_EXT
  472. const_iterator lower_bound(const _KT& __x) const
  473. { return _S_to_value_ite(_M_t.lower_bound(cast_traits::to_storage_type_crefT(__x))); }
  474. _STLP_TEMPLATE_FOR_CONT_EXT
  475. iterator upper_bound(const _KT& __x)
  476. { return _S_to_value_ite(_M_t.upper_bound(cast_traits::to_storage_type_crefT(__x))); }
  477. _STLP_TEMPLATE_FOR_CONT_EXT
  478. const_iterator upper_bound(const _KT& __x) const
  479. { return _S_to_value_ite(_M_t.upper_bound(cast_traits::to_storage_type_crefT(__x))); }
  480. _STLP_TEMPLATE_FOR_CONT_EXT
  481. pair<iterator, iterator> equal_range(const _KT& __x) {
  482. pair<base_iterator, base_iterator> __ret;
  483. __ret = _M_t.equal_range(cast_traits::to_storage_type_crefT(__x));
  484. return pair<iterator, iterator>(_S_to_value_ite(__ret.first),
  485. _S_to_value_ite(__ret.second));
  486. }
  487. _STLP_TEMPLATE_FOR_CONT_EXT
  488. pair<const_iterator, const_iterator> equal_range(const _KT& __x) const {
  489. pair<const_base_iterator, const_base_iterator> __ret;
  490. __ret = _M_t.equal_range(cast_traits::to_storage_type_crefT(__x));
  491. return pair<const_iterator, const_iterator>(_S_to_value_ite(__ret.first),
  492. _S_to_value_ite(__ret.second));
  493. }
  494. };
  495. #if defined (__BORLANDC__) || defined (__DMC__)
  496. # undef typename
  497. #endif
  498. _STLP_END_NAMESPACE
  499. #endif /* _STLP_PTR_SPECIALIZED_SET_H */
  500. // Local Variables:
  501. // mode:C++
  502. // End: