unordered_set_of.qbk 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. [/license
  2. Boost.Bimap
  3. Copyright (c) 2006-2007 Matias Capeletto
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. ]
  8. [/ QuickBook Document version 1.4 ]
  9. [section unordered_set_of Reference]
  10. [section Header "boost/bimap/unordered_set_of.hpp" synopsis]
  11. namespace boost {
  12. namespace bimaps {
  13. template
  14. <
  15. class KeyType,
  16. class HashFunctor = hash< KeyType >,
  17. class EqualKey = std::equal_to< KeyType >
  18. >
  19. struct unordered_set_of;
  20. template
  21. <
  22. class HashFunctor = hash< _relation >,
  23. class EqualKey = std::equal_to< _relation >
  24. >
  25. struct unordered_set_of_relation;
  26. } // namespace bimap
  27. } // namespace boost
  28. [endsect]
  29. [section Header "boost/bimap/unordered_multiset_of.hpp" synopsis]
  30. namespace boost {
  31. namespace bimaps {
  32. template
  33. <
  34. class KeyType,
  35. class HashFunctor = hash< KeyType >,
  36. class EqualKey = std::equal_to< KeyType >
  37. >
  38. struct unordered_multiset_of;
  39. template
  40. <
  41. class HashFunctor = hash< _relation >,
  42. class EqualKey = std::equal_to< _relation >
  43. >
  44. struct unordered_multiset_of_relation;
  45. } // namespace bimap
  46. } // namespace boost
  47. [endsect]
  48. [section Collection type specifiers unordered_set_of and unordered_multiset_of]
  49. These collection types specifiers allow for set views without and
  50. with allowance of duplicate elements, respectively. The syntax of
  51. `set_of` and `multiset_of` coincide, thus we describe them
  52. in a grouped manner.
  53. [endsect]
  54. [section unordered_\[multi\]set_of Views]
  55. An unordered_\[multi\]set_of set view is a tr1::unordered\[multi\]set signature compatible
  56. interface to the underlying heap of elements contained in a `bimap`.
  57. The interface and semantics of `unordered_[multi]set_of` views are
  58. modeled according to the proposal for unordered associative containers given
  59. in the __CPP_STANDARD_LIBRARY_TECHNICAL_REPORT__, also known as TR1.
  60. An `unordered_[multi]set_of` view is particularized according to a given
  61. `Hash` function object which returns hash values for the keys and a
  62. binary predicate `Pred` acting as an equivalence relation on values of Key.
  63. There are two variants: unordered_set_of, which do not allow duplicate elements
  64. (with respect to its associated comparison predicate) and unordered_multiset_of,
  65. which accept those duplicates. The interface of these two variants is the same
  66. to a great extent, so they are documented together with their differences
  67. explicitly noted when they exist.
  68. If you look the bimap by a side, you will use a map view and if you looked
  69. it as a whole you will be using a set view.
  70. Except where noted, `unordered_[multi]set_of` views (both unique and non-unique) are models
  71. of [^Unordered Associative Container].
  72. Validity of iterators and references to elements is preserved in all cases.
  73. Occasionally, the exception safety guarantees provided are actually stronger
  74. than required by the extension draft. We only provide descriptions of those
  75. types and operations that are either not present in the concepts modeled or
  76. do not exactly conform to the requirements for unordered associative containers.
  77. namespace boost {
  78. namespace bimap {
  79. namespace views {
  80. template< ``['-implementation defined parameter list-]`` >
  81. class ``['-implementation defined view name-]``
  82. {
  83. public:
  84. // types
  85. typedef ``['-unspecified-]`` key_type;
  86. typedef ``['-unspecified-]`` value_type;
  87. typedef ``['-unspecified-]`` key_compare;
  88. typedef ``['-unspecified-]`` value_compare;
  89. typedef ``['-unspecified-]`` hasher;
  90. typedef ``['-unspecified-]`` key_equal;
  91. typedef ``['-unspecified-]`` allocator_type;
  92. typedef ``['-unspecified-]`` reference;
  93. typedef ``['-unspecified-]`` const_reference;
  94. typedef ``['-unspecified-]`` iterator;
  95. typedef ``['-unspecified-]`` const_iterator;
  96. typedef ``['-unspecified-]`` size_type;
  97. typedef ``['-unspecified-]`` difference_type;
  98. typedef ``['-unspecified-]`` pointer;
  99. typedef ``['-unspecified-]`` const_pointer;
  100. typedef ``['-unspecified-]`` local_iterator;
  101. typedef ``['-unspecified-]`` const_local_iterator;
  102. typedef ``['-unspecified-]`` info_type;
  103. // construct/destroy/copy:
  104. this_type & operator=(const this_type & x);
  105. allocator_type get_allocator() const;
  106. // size and capacity
  107. bool empty() const;
  108. size_type size() const;
  109. size_type max_size() const;
  110. // iterators
  111. iterator begin();
  112. const_iterator begin() const;
  113. iterator end();
  114. const_iterator end() const;
  115. // modifiers
  116. std::pair< iterator, bool > ``[link reference_unordered_set_of_insert_value insert]``(const value_type & x);
  117. iterator ``[link reference_unordered_set_of_insert_iterator_value insert]``(iterator position, const value_type & x);
  118. template< class InputIterator >
  119. void ``[link reference_unordered_set_of_insert_iterator_iterator insert]``(InputIterator first, InputIterator last);
  120. iterator ``[link reference_unordered_set_of_erase_iterator erase]``(iterator position);
  121. template< class CompatibleKey >
  122. size_type ``[link reference_unordered_set_of_erase_key erase]``(const CompatibleKey & x);
  123. iterator ``[link reference_unordered_set_of_erase_iterator_iterator erase]``(iterator first, iterator last);
  124. bool ``[link reference_unordered_set_of_replace_iterator_value replace]``(iterator position, const value_type & x);
  125. // Only in map views
  126. // {
  127. typedef ``['-unspecified-]`` mapped_type;
  128. typedef ``['-unspecified-]`` data_type; // Equal to mapped_type
  129. template< class CompatibleKey >
  130. bool ``[link reference_unordered_set_of_replace_key_iterator_key replace_key]``(iterator position, const CompatibleKey & x);
  131. template< class CompatibleData >
  132. bool ``[link reference_unordered_set_of_replace_data_iterator_data replace_data]``(iterator position, const CompatibleData & x);
  133. template< class KeyModifier >
  134. bool ``[link reference_unordered_set_of_modify_key_iterator_modifier modify_key]``(iterator position, KeyModifier mod);
  135. template< class DataModifier >
  136. bool ``[link reference_unordered_set_of_modify_data_iterator_modifier modify_data]``(iterator position, DataModifier mod);
  137. // }
  138. void clear();
  139. // observers
  140. key_from_value key_extractor() const;
  141. hasher hash_function() const;
  142. key_equal key_eq() const;
  143. // lookup
  144. template< class CompatibleKey >
  145. iterator ``[link reference_unordered_set_of_find_key find]``(const CompatibleKey & x);
  146. template< class CompatibleKey >
  147. const_iterator ``[link reference_unordered_set_of_find_key find]``(const CompatibleKey & x) const;
  148. template< class CompatibleKey >
  149. size_type ``[link reference_unordered_set_of_count_key count]``(const CompatibleKey & x) const;
  150. template< class CompatibleKey >
  151. std::pair<iterator,iterator>
  152. ``[link reference_unordered_set_of_equal_range_key equal_range]``(const CompatibleKey & x);
  153. template< class CompatibleKey >
  154. std::pair<const_iterator,const_iterator>
  155. ``[link reference_unordered_set_of_equal_range_key equal_range]``(const CompatibleKey & x) const;
  156. // bucket interface
  157. size_type bucket_count() const;
  158. size_type max_bucket_count() const;
  159. size_type bucket_size(size_type n) const;
  160. size_type bucket(const key_type & k) const;
  161. local_iterator begin(size_type n);
  162. const_local_iterator begin(size_type n) const;
  163. local_iterator end(size_type n);
  164. const_local_iterator end(size_type n) const;
  165. // hash policy
  166. float load_factor() const;
  167. float max_load_factor() const;
  168. void max_load_factor(float z);
  169. void ``[link reference_unordered_set_of_rehash_size rehash]``(size_type n);
  170. // Only in maps views
  171. // {
  172. typedef ``['-unspecified-]`` mapped_type;
  173. // Only in for `unordered_set_of` collection type
  174. // {
  175. template<class CompatibleKey>
  176. const mapped_type & ``[link reference_unordered_set_of_at_key_const at]``(const CompatibleKey & k) const;
  177. // Only if the other collection type is mutable
  178. // {
  179. template<class CompatibleKey>
  180. mapped_type & ``[link reference_unordered_set_of_operator_bracket_key operator\[\]]``(const CompatibleKey & k);
  181. template<class CompatibleKey>
  182. mapped_type & ``[link reference_unordered_set_of_at_key at]``(const CompatibleKey & k);
  183. // }
  184. // Only if info_hook is used
  185. // {
  186. template< class CompatibleKey >
  187. info_type & ``[link reference_unordered_set_of_info_at_key info_at]``(const CompatibleKey & k);
  188. template< class CompatibleKey >
  189. const info_type & ``[link reference_unordered_set_of_info_at_key info_at]``(const CompatibleKey & k) const;
  190. // }
  191. // }
  192. };
  193. } // namespace views
  194. } // namespace bimap
  195. } // namespace boost
  196. In the case of a `bimap< unordered_{multi}set_of<Left>, ... >`
  197. In the set view:
  198. typedef signature-compatible with relation< Left, ... > key_type;
  199. typedef signature-compatible with relation< const Left, ... > value_type;
  200. In the left map view:
  201. typedef Left key_type;
  202. typedef ... mapped_type;
  203. typedef signature-compatible with std::pair< const Left, ... > value_type;
  204. In the right map view:
  205. typedef ... key_type;
  206. typedef Left mapped_type;
  207. typedef signature-compatible with std::pair< ... ,const Left > value_type;
  208. [#unordered_set_of_complexity_signature]
  209. [section Complexity signature]
  210. Here and in the descriptions of operations of `unordered_[multi]set_of` views,
  211. we adopt the scheme outlined in the
  212. [link complexity_signature_explanation complexity signature section].
  213. The complexity signature of `unordered_[multi]set_of` view is:
  214. * copying: `c(n) = n * log(n)`,
  215. * insertion: average case `i(n) = 1` (constant), worst case `i(n) = n`,
  216. * hinted insertion: average case `h(n) = 1` (constant), worst case `h(n) = n`,
  217. * deletion: average case `d(n) = 1` (constant), worst case `d(n) = n`,
  218. * replacement:
  219. * if the new element key is equivalent to the original, `r(n) = 1` (constant),
  220. * otherwise, average case `r(n) = 1` (constant), worst case `r(n) = n`,
  221. * modifying: average case `m(n) = 1` (constant), worst case `m(n) = n`.
  222. [endsect]
  223. [section Instantiation types]
  224. `unordered_[multi]set_of` views are instantiated internally to `bimap`
  225. specified by means of the collection type specifiers and the `bimap` itself.
  226. Instantiations are dependent on the following types:
  227. * `Value` from `bimap`,
  228. * `Allocator` from `bimap`,
  229. * `Hash` from the collection type specifier,
  230. * `Pred` from the collection type specifier.
  231. `Hash` is a __SGI_UNARY_FUNCTION__ taking a single argument of type
  232. `key_type` and returning a value of type `std::size_t` in the range
  233. `[0, std::numeric_limits<std::size_t>::max())`.
  234. Pred is a __SGI_BINARY_PREDICATE__ inducing an equivalence relation on elements of
  235. `key_type`. It is required that the `Hash` object return the same value for
  236. keys equivalent under `Pred`.
  237. [endsect]
  238. [section Nested types]
  239. iterator
  240. const_iterator
  241. local_iterator
  242. const_local_iterator
  243. [: These types are models of __SGI_FORWARD_ITERATOR__.
  244. ]
  245. [endsect]
  246. [section Constructors, copy and assignment]
  247. As explained in the concepts section,
  248. views do not have public constructors or destructors. Assignment, on the other
  249. hand, is provided.
  250. Upon construction, `max_load_factor()` is 1.0.
  251. this_type & operator=(const this_type & x);
  252. * [*Effects: ] `a = b`;
  253. where a and b are the `bimap` objects to which `*this`
  254. and x belong, respectively.
  255. * [*Returns: ] `*this.`
  256. [endsect]
  257. [section Modifiers]
  258. [#reference_unordered_set_of_insert_value]
  259. std::pair<iterator,bool> insert(const value_type & x);
  260. * [*Effects:] Inserts `x` into the `bimap` to which the view belongs if
  261. * the view is non-unique OR no other element with equivalent key exists,
  262. * AND insertion is allowed by all other views of the `bimap`.
  263. * [*Returns:] The return value is a pair `p`. `p.second` is `true` if and only if
  264. insertion took place. On successful insertion, `p.first` points to the element
  265. inserted; otherwise, `p.first` points to an element that caused the insertion to
  266. be banned. Note that more than one element can be causing insertion not to be
  267. allowed.
  268. * [link unordered_set_of_complexity_signature
  269. [*Complexity:]] O(I(n)).
  270. * [*Exception safety:] Strong.
  271. [#reference_unordered_set_of_insert_iterator_value]
  272. iterator insert(iterator position, const value_type & x);
  273. * [*Requires: ] `position` is a valid iterator of the view.
  274. * [*Effects: ] `position` is used as a hint to improve the efficiency of the operation.
  275. Inserts `x` into the `bimap` to which the view belongs if
  276. * the view is non-unique OR no other element with equivalent key exists,
  277. * AND insertion is allowed by all other views of the `bimap`.
  278. * [*Returns:] On successful insertion, an iterator to the newly inserted element.
  279. Otherwise, an iterator to an element that caused the insertion to be banned.
  280. Note that more than one element can be causing insertion not to be allowed.
  281. * [link unordered_set_of_complexity_signature [*Complexity:]] O(H(n)).
  282. * [*Exception safety:] Strong.
  283. [#reference_unordered_set_of_insert_iterator_iterator]
  284. template< class InputIterator>
  285. void insert(InputIterator first, InputIterator last);
  286. * [*Requires: ] `InputIterator` is a model of __SGI_INPUT_ITERATOR__ over elements of type
  287. `value_type`. `first` and `last` are not iterators into any views of the
  288. `bimap` to which this view belongs. `last` is reachable from first.
  289. * [*Effects: ]
  290. `iterator hint = end();`
  291. `while(first != last) hint = insert(hint, *first++);`
  292. * [link unordered_set_of_complexity_signature
  293. [*Complexity:]] O(m*H(n+m)), where m is the number of elements in `[first, last)`.
  294. * [*Exception safety:] Basic.
  295. [#reference_unordered_set_of_erase_iterator]
  296. iterator erase(iterator position);
  297. * [*Requires: ] `position` is a valid dereferenceable `iterator` of the view.
  298. * [*Effects:] Deletes the element pointed to by `position`.
  299. * [*Returns:] An `iterator` pointing to the element immediately following the one
  300. that was deleted, or `end()` if no such element exists.
  301. * [link unordered_set_of_complexity_signature
  302. [*Complexity:]] O(D(n)).
  303. * [*Exception safety:] nothrow.
  304. [#reference_unordered_set_of_erase_key]
  305. template< class CompatibleKey >
  306. size_type erase(const CompatibleKey & x);
  307. * [*Effects:] Deletes the elements with key equivalent to `x`.
  308. * [*Returns:] Number of elements deleted.
  309. * [link unordered_set_of_complexity_signature
  310. [*Complexity:]] Average case, O(1 + m*D(n)), worst case O(n + m*D(n)),
  311. where m is the number of elements deleted.
  312. * [*Exception safety:] Basic.
  313. [#reference_unordered_set_of_erase_iterator_iterator]
  314. iterator erase(iterator first, iterator last);
  315. * [*Requires: ] `[first,last)` is a valid range of the view.
  316. * [*Effects:] Deletes the elements in `[first,last)`.
  317. * [*Returns: ] `last`.
  318. * [link unordered_set_of_complexity_signature
  319. [*Complexity:]] O(m*D(n)), where m is the number of elements in `[first,last)`.
  320. * [*Exception safety:] nothrow.
  321. [#reference_unordered_set_of_replace_iterator_value]
  322. bool replace(iterator position, const value_type & x);
  323. * [*Requires: ] `position` is a valid dereferenceable `iterator` of the view.
  324. * [*Effects:] Assigns the value `x` to the element pointed to by `position` into
  325. the `bimap` to which the view belongs if, for the value `x`
  326. * the view is non-unique OR no other element with equivalent key exists
  327. (except possibly `*position`),
  328. * AND replacing is allowed by all other views of the `bimap`.
  329. * [*Postconditions:] Validity of position is preserved in all cases.
  330. * [*Returns: ] `true` if the replacement took place, `false` otherwise.
  331. * [link unordered_set_of_complexity_signature
  332. [*Complexity:]] O(R(n)).
  333. * [*Exception safety:] Strong. If an exception is thrown by some user-provided
  334. operation the `bimap` to which the view belongs remains in its original state.
  335. [#reference_unordered_set_of_replace_key_iterator_key]
  336. template< class CompatibleKey >
  337. bool replace_key(iterator position, const CompatibleKey & x);
  338. * [*Requires: ] `position` is a valid dereferenceable iterator of the set view.
  339. `CompatibleKey` can be assigned to `key_type`.
  340. * [*Effects:] Assigns the value `x` to `e.first`, where `e` is the element pointed
  341. to by `position` into the `bimap` to which the set view belongs if,
  342. * the map view is non-unique OR no other element with equivalent key exists
  343. (except possibly `*position`),
  344. * AND replacing is allowed by all other views of the `bimap`.
  345. * [*Postconditions:] Validity of position is preserved in all cases.
  346. * [*Returns: ] `true` if the replacement took place, `false` otherwise.
  347. * [link unordered_set_of_complexity_signature
  348. [*Complexity:]] O(R(n)).
  349. * [*Exception safety:] Strong. If an exception is thrown by some user-provided
  350. operation, the `bimap` to which the set view belongs remains in
  351. its original state.
  352. [#reference_unordered_set_of_replace_data_iterator_data]
  353. template< class CompatibleData >
  354. bool replace_data(iterator position, const CompatibleData & x);
  355. * [*Requires: ] `position` is a valid dereferenceable iterator of the set view.
  356. `CompatibleKey` can be assigned to `mapped_type`.
  357. * [*Effects:] Assigns the value `x` to `e.second`, where `e` is the element pointed
  358. to by `position` into the `bimap` to which the set view belongs if,
  359. * the map view is non-unique OR no other element with equivalent key exists
  360. (except possibly `*position`),
  361. * AND replacing is allowed by all other views of the `bimap`.
  362. * [*Postconditions:] Validity of position is preserved in all cases.
  363. * [*Returns: ] `true` if the replacement took place, `false` otherwise.
  364. * [link unordered_set_of_complexity_signature
  365. [*Complexity:]] O(R(n)).
  366. * [*Exception safety:] Strong. If an exception is thrown by some user-provided
  367. operation, the `bimap` to which the set view belongs remains in
  368. its original state.
  369. [#reference_unordered_set_of_modify_key_iterator_modifier]
  370. template< class KeyModifier >
  371. bool modify_key(iterator position, KeyModifier mod);
  372. * [*Requires: ] `KeyModifier` is a model of __SGI_UNARY_FUNCTION__ accepting arguments of
  373. type: `key_type&`; `position` is a valid dereferenceable iterator of the view.
  374. * [*Effects:] Calls `mod(e.first)` where e is the element pointed to by position and
  375. rearranges `*position` into all the views of the `bimap`.
  376. If the rearrangement fails, the element is erased.
  377. Rearrangement is successful if
  378. * the map view is non-unique OR no other element with equivalent key exists,
  379. * AND rearrangement is allowed by all other views of the `bimap`.
  380. * [*Postconditions:] Validity of `position` is preserved if the operation succeeds.
  381. * [*Returns: ] `true` if the operation succeeded, `false` otherwise.
  382. * [link unordered_set_of_complexity_signature
  383. [*Complexity:]] O(M(n)).
  384. * [*Exception safety:] Basic. If an exception is thrown by some user-provided
  385. operation (except possibly mod), then the element pointed to by position is erased.
  386. * [*Note:] Only provided for map views.
  387. [#reference_unordered_set_of_modify_data_iterator_modifier]
  388. template< class DataModifier >
  389. bool modify_data(iterator position, DataModifier mod);
  390. * [*Requires: ] `DataModifier` is a model of __SGI_UNARY_FUNCTION__ accepting arguments of
  391. type: `mapped_type&`; `position` is a valid dereferenceable iterator of the view.
  392. * [*Effects:] Calls `mod(e.second)` where e is the element pointed to by position and
  393. rearranges `*position` into all the views of the `bimap`.
  394. If the rearrangement fails, the element is erased.
  395. Rearrangement is successful if
  396. * the oppositte map view is non-unique OR no other element with equivalent key in that
  397. view exists,
  398. * AND rearrangement is allowed by all other views of the `bimap`.
  399. * [*Postconditions:] Validity of `position` is preserved if the operation succeeds.
  400. * [*Returns: ] `true` if the operation succeeded, `false` otherwise.
  401. * [link unordered_set_of_complexity_signature
  402. [*Complexity:]] O(M(n)).
  403. * [*Exception safety:] Basic. If an exception is thrown by some user-provided
  404. operation (except possibly mod), then the element pointed to by position is erased.
  405. * [*Note:] Only provided for map views.
  406. [/
  407. [#reference_unordered_set_of_modify_iterator_modifier]
  408. template< class Modifier>
  409. bool modify(iterator position, Modifier mod);
  410. * [*Requires: ] `Modifier` is a model of __SGI_BINARY_FUNCTION__ accepting arguments of
  411. type: `first_type&` and `second_type&` for ['Map View] or `left_type&` and `right_type&`
  412. for ['Set View]; `position` is a valid dereferenceable iterator of the view.
  413. * [*Effects:] Calls `mod(e.first,e.second)` for ['Map View:] or calls `mod(e.left,e.right)`
  414. for ['Set View] where `e` is the element pointed to by `position` and
  415. rearranges `*position` into all the views of the `bimap`.
  416. If the rearrangement fails, the element is erased.
  417. Rearrangement is successful if
  418. * the view is non-unique OR no other element with equivalent key exists,
  419. * AND rearrangement is allowed by all other views of the `bimap`.
  420. * [*Postconditions:] Validity of position is preserved if the operation succeeds.
  421. * [*Returns: ] `true` if the operation succeeded, `false` otherwise.
  422. * [link unordered_set_of_complexity_signature
  423. [*Complexity:]] O(M(n)).
  424. * [*Exception safety:] Basic. If an exception is thrown by some user-provided
  425. operation (except possibly `mod`), then the element pointed to by `position` is erased.
  426. /]
  427. [endsect]
  428. [section Lookup]
  429. `unordered_[multi]set_of` views provide the full lookup functionality required by unordered
  430. associative containers, namely `find`, `count`, and `equal_range`. Additionally,
  431. these member functions are templatized to allow for non-standard arguments,
  432. so extending the types of search operations allowed. The kind of arguments
  433. permissible when invoking the lookup member functions is defined by the
  434. following concept.
  435. [/
  436. Consider a pair `(Hash, Pred)` where `Hash` is a hash functor over values of type
  437. `Key` and `Pred` is a __SGI_BINARY_PREDICATE__ inducing an equivalence relation on `Key`,
  438. with the additional constraint that equivalent keys have the same hash value.
  439. A triplet of types `(CompatibleKey, CompatibleHash, CompatiblePred)` is said to
  440. be a ['compatible extension] of `(Hash, Pred)` if
  441. * `CompatibleHash` is a hash functor on values of type `CompatibleKey`,
  442. * `CompatiblePred` is a __SGI_BINARY_PREDICATE__ over `(Key, CompatibleKey)`,
  443. * `CompatiblePred` is a __SGI_BINARY_PREDICATE__ over `(CompatibleKey, Key)`,
  444. * if `c_eq(ck,k1)` then `c_eq(k1,ck)`,
  445. * if `c_eq(ck,k1)` and `eq(k1,k2)` then `c_eq(ck,k2)`,
  446. * if `c_eq(ck,k1)` and `c_eq(ck,k2)` then `eq(k1,k2)`,
  447. * if `c_eq(ck,k1)` then `c_hash(ck)==hash(k1)`,
  448. for every `c_hash` of type `CompatibleHash`, `c_eq` of type `CompatiblePred`, hash of
  449. type `Hash`, `eq` of type `Pred`, `ck` of type `CompatibleKey` and `k1`, `k2` of type `Key`.
  450. ]
  451. A type `CompatibleKey` is said to be a ['compatible key] of `(Hash, Pred)`
  452. if `(CompatibleKey, Hash, Pred)` is a compatible extension of `(Hash, Pred)`. This
  453. implies that `Hash` and `Pred` accept arguments of type `CompatibleKey`, which usually
  454. means they have several overloads of their corresponding `operator()` member
  455. functions.
  456. [/
  457. In the context of a compatible extension or a compatible key, the expression
  458. "equivalent key" takes on its obvious interpretation.
  459. ]
  460. [#reference_unordered_set_of_find_key]
  461. template< class CompatibleKey >
  462. iterator find(const CompatibleKey & x);
  463. template< class CompatibleKey >
  464. const_iterator find(const CompatibleKey & x) const;
  465. * [*Effects:] Returns a pointer to an element whose key is equivalent to `x`,
  466. or `end()` if such an element does not exist.
  467. * [*Complexity:] Average case O(1) (constant), worst case O(n).
  468. [#reference_unordered_set_of_count_key]
  469. template< class CompatibleKey >
  470. size_type count(const CompatibleKey & x) const;
  471. * [*Effects:] Returns the number of elements with key equivalent to `x`.
  472. * [*Complexity:] Average case O(count(x)), worst case O(n).
  473. [#reference_unordered_set_of_equal_range_key]
  474. template< class CompatibleKey >
  475. std::pair<iterator,iterator>
  476. equal_range(const CompatibleKey & x);
  477. template< class CompatibleKey >
  478. std::pair<const_iterator,const_iterator>
  479. equal_range(const CompatibleKey & x) const;
  480. * [*Effects:] Returns a range containing all elements with keys equivalent
  481. to `x` (and only those).
  482. * [*Complexity:] Average case O(count(x)), worst case O(n).
  483. [endsect]
  484. [section at(), info_at() and operator\[\] - set_of only]
  485. [#reference_unordered_set_of_at_key_const]
  486. template< class CompatibleKey >
  487. const mapped_type & at(const CompatibleKey & k) const;
  488. * [*Requires: ] `CompatibleKey` is a compatible key of `key_compare`.
  489. * [*Effects:] Returns the `mapped_type` reference that is associated with `k`, or
  490. throws `std::out_of_range` if such key does not exist.
  491. * [*Complexity:] Average case O(1) (constant), worst case O(n).
  492. * [*Note:] Only provided when `unordered_set_of` is used.
  493. The symmetry of bimap imposes some constraints on `operator[]` and the
  494. non constant version of at() that are not found in `std::maps`.
  495. Tey are only provided if the other collection type is mutable
  496. (`list_of`, `vector_of` and `unconstrained_set_of`).
  497. [#reference_unordered_set_of_operator_bracket_key]
  498. template< class CompatibleKey >
  499. mapped_type & operator[](const CompatibleKey & k);
  500. * [*Requires: ] `CompatibleKey` is a compatible key of `key_compare`.
  501. * [*Effects: ] `return insert(value_type(k,mapped_type()))->second;`
  502. * [*Complexity:] If the insertion is performed O(I(n)), else: Average case
  503. O(1) (constant), worst case O(n).
  504. * [*Note:] Only provided when `unordered_set_of` is used and the other collection
  505. type is mutable.
  506. [#reference_unordered_set_of_at_key]
  507. template< class CompatibleKey >
  508. mapped_type & at(const CompatibleKey & k);
  509. * [*Requires: ] `CompatibleKey` is a compatible key of `key_compare`.
  510. * [*Effects: ] Returns the `mapped_type` reference that is associated with `k`, or
  511. throws `std::out_of_range` if such key does not exist.
  512. * [*Complexity:] Average case O(1) (constant), worst case O(n).
  513. * [*Note:] Only provided when `unordered_set_of` is used and the other collection
  514. type is mutable.
  515. [/
  516. The symmetry of bimap imposes some constraints to the `operator[]` that are not
  517. found in `std::maps`.
  518. If other views are unique, `bimap::duplicate_value` is thrown whenever an assignment is
  519. attempted to a value that is already a key in this views.
  520. As for bimap::value_not_found, this exception is thrown while trying to access
  521. a non-existent key: this behavior differs from that of std::map, which automatically
  522. assigns a default value to non-existent keys referred to by `operator[]`.
  523. const mapped_type & operator[](const typename key_type & k) const;
  524. * [*Effects:] Returns the `mapped_type` reference that is associated with `k`, or
  525. throws `bimap::value_not_found` if such an element does not exist.
  526. * [*Complexity:] O(log(n)).
  527. ``['-unspecified mapped_type proxy-]`` operator[](const typename key_type & k);
  528. * [*Effects:] Returns a proxy to a `mapped_type` associated with `k` and the
  529. bimap. The proxy behaves as a reference to the `mapped_type` object. If this
  530. proxy is read and `k` was not in the bimap, the bimap::value_not_found is
  531. thrown. If it is written then `bimap::duplicate_value` is thrown if the
  532. assignment is not allowed by one of the other views of the `bimap`.
  533. * [link unordered_set_of_complexity_signature
  534. [*Complexity:]] If the assignment operator of the proxy is not used, then
  535. the order is O(log(n)). If it is used, the order is O(I(n)) if `k` was not
  536. in the bimap and O(R(n)) if it existed in the bimap.
  537. ]
  538. [#reference_unordered_set_of_info_at_key]
  539. template< class CompatibleKey >
  540. info_type & info_at(const CompatibleKey & k);
  541. template< class CompatibleKey >
  542. const info_type & info_at(const CompatibleKey & k) const;
  543. * [*Requires: ] `CompatibleKey` is a compatible key of `key_compare`.
  544. * [*Effects:] Returns the `info_type` reference that is associated with `k`, or
  545. throws `std::out_of_range` if such key does not exist.
  546. * [*Complexity:] Average case O(1) (constant), worst case O(n).
  547. * [*Note:] Only provided when `unordered_set_of` and `info_hook` are used
  548. [endsect]
  549. [section Hash policy]
  550. [#reference_unordered_set_of_rehash_size]
  551. void rehash(size_type n);
  552. * [*Effects:] Increases if necessary the number of internal buckets so that
  553. `size()/bucket_count()` does not exceed the maximum load factor, and
  554. `bucket_count()>=n`.
  555. * [*Postconditions:] Validity of iterators and references to the elements
  556. contained is preserved.
  557. * [*Complexity:] Average case O(size()), worst case O(size(n)2).
  558. * [*Exception safety:] Strong.
  559. [endsect]
  560. [section Serialization]
  561. Views cannot be serialized on their own, but only as part of the
  562. `bimap` into which they are embedded. In describing the
  563. additional preconditions and guarantees associated to `unordered_[multi]set_of` views
  564. with respect to serialization of their embedding containers, we use
  565. the concepts defined in the `bimap` serialization section.
  566. [blurb [*Operation:] saving of a `bimap` b to an output archive
  567. (XML archive) ar.]
  568. * [*Requires:] No additional requirements to those imposed by the container.
  569. [blurb [*Operation:] loading of a `bimap` b' from an input
  570. archive (XML archive) ar.]
  571. * [*Requires:] Additionally to the general requirements, `key_eq()` must
  572. be serialization-compatible with `m.get<i>().key_eq()`, where i is the
  573. position of the `unordered_[multi]set_of` view in the container.
  574. * [*Postconditions:] On successful loading, the range `[begin(), end())`
  575. contains restored copies of every element in
  576. `[m.get<i>().begin(), m.get<i>().end())`, though not necessarily in
  577. the same order.
  578. [blurb [*Operation:] saving of an `iterator` or `const_iterator` `it` to an output
  579. archive (XML archive) ar.]
  580. * [*Requires: ] `it` is a valid `iterator` of the view. The associated
  581. `bimap` has been previously saved.
  582. [blurb [*Operation:] loading of an iterator or `const_iterator it`' from an
  583. input archive (XML archive) ar.]
  584. * [*Postconditions:] On successful loading, if `it` was dereferenceable then
  585. `*it`' is the restored copy of `*it`, otherwise `it`'` == end()`.
  586. * [*Note:] It is allowed that `it` be a `const_iterator` and the restored
  587. `it`' an `iterator`, or viceversa.
  588. [blurb [*Operation:] saving of a local_iterator or const_local_iterator it
  589. to an output archive (XML archive) ar.]
  590. * [*Requires: ] `it` is a valid local iterator of the view. The associated
  591. `bimap` has been previously saved.
  592. [blurb [*Operation:] loading of a `local_iterator` or `const_local_iterator`
  593. `it`' from an input archive (XML archive) ar.]
  594. * [*Postconditions:] On successful loading, if `it` was dereferenceable then
  595. `*it`' is the restored copy of `*it`; if `it` was `m.get<i>().end(n)` for some n,
  596. then `it`'` == m`'`.get<i>().end(n)` (where `b` is the original `bimap`,
  597. `b`' its restored copy and `i` is the ordinal of the index.)
  598. * [*Note:] It is allowed that `it` be a `const_local_iterator` and the restored
  599. `it`' a `local_iterator`, or viceversa.
  600. [endsect]
  601. [endsect]
  602. [endsect]