bimap.qbk 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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 Bimap Reference]
  10. [section View concepts]
  11. `bimap` instantiations comprise two side views and an view of the relation
  12. specified at compile time. Each view allows read-write access to the elements contained
  13. in a definite manner, mathing an STL container signature.
  14. Views are not isolated objects and so cannot be constructed on their
  15. own; rather they are an integral part of a `bimap`. The name of the view
  16. class implementation proper is never directly exposed to the user, who
  17. has access only to the associated view type specifier.
  18. Insertion and deletion of elements are always performed through the
  19. appropriate interface of any of the three views of the `bimap`; these
  20. operations do, however, have an impact on all other views as well: for
  21. instance, insertion through a given view may fail because there exists
  22. another view that forbids the operation in order to preserve its
  23. invariant (such as uniqueness of elements). The global operations
  24. performed jointly in the any view can be reduced to six primitives:
  25. * copying
  26. * insertion of an element
  27. * hinted insertion, where a pre-existing element is suggested in order to improve
  28. the efficiency of the operation
  29. * deletion of an element
  30. * replacement of the value of an element, which may trigger the
  31. rearrangement of this element in one or more views, or may forbid the
  32. replacement
  33. * modification of an element, and its subsequent
  34. rearrangement/banning by the various views
  35. The last two primitives deserve some further explanation: in order to
  36. guarantee the invariants associated to each view (e.g. some definite
  37. ordering) elements of a `bimap` are not mutable. To overcome this
  38. restriction, the views expose member functions for updating and
  39. modifying, which allows for the mutation of elements in a controlled
  40. fashion.
  41. [endsect]
  42. [#complexity_signature_explanation]
  43. [section Complexity signature]
  44. Some member functions of a view interface are implemented by global
  45. primitives from the above list. The complexity of these operations thus
  46. depends on all views of a given `bimap`, not just the currently used view.
  47. In order to establish complexity estimates, a view is characterised by
  48. its complexity signature, consisting of the following associated
  49. functions on the number of elements:
  50. * `c(n)`: copying
  51. * `i(n)`: insertion
  52. * `h(n)`: hinted insertion
  53. * `d(n)`: deletion
  54. * `r(n)`: replacement
  55. * `m(n)`: modifying
  56. If the collection type of the relation is `left_based` or `right_based`, and we use
  57. an `l` subscript to denote the left view and an `r` for the right view, then
  58. the insertion of an element in such a container is of complexity
  59. `O(i_l(n)+i_r(n))`, where n is the number of elements. If the collection type of
  60. relation is not side-based, then there is an additional term to add that
  61. is contributed by the collection type of relation view. Using `a` to denote the
  62. above view, the complexity of insertion will now be
  63. `O(i_l(n)+i_r(n)+i_a(n))`. To abbreviate the notation, we adopt the
  64. following definitions:
  65. * `C(n) = c_l(n) + c_r(n) [ + c_a(n) ]`
  66. * `I(n) = i_l(n) + i_r(n) [ + i_a(n) ]`
  67. * `H(n) = h_l(n) + h_r(n) [ + h_a(n) ]`
  68. * `D(n) = d_l(n) + d_r(n) [ + d_a(n) ]`
  69. * `R(n) = r_l(n) + r_r(n) [ + r_a(n) ]`
  70. * `M(n) = m_l(n) + m_r(n) [ + m_a(n) ]`
  71. [endsect]
  72. [section Set type specification]
  73. Set type specifiers are passed as instantiation arguments to `bimap` and
  74. provide the information needed to incorporate the corresponding views.
  75. Currently, Boost.Bimap provides the collection type specifiers. The ['side collection type]
  76. specifiers define the constraints of the two map views of the
  77. bimap. The ['collection type of relation] specifier defines the main set view
  78. constraints. If `left_based` (the default parameter) or `right_based` is
  79. used, then the collection type of relation will be based on the left or right
  80. collection type correspondingly.
  81. [table
  82. [[Side collection type ][Collection type of relation ][Include ]]
  83. [[`set_of` ][`set_of_relation` ][`boost/bimap/set_of.hpp` ]]
  84. [[`multiset_of` ][`multiset_of_relation` ][`boost/bimap/multiset_of.hpp` ]]
  85. [[`unordered_set_of` ][`unordered_set_of_relation` ][`boost/bimap/unordered_set_of.hpp` ]]
  86. [[`unordered_multiset_of` ][`unordered_multiset_of_relation`][`boost/bimap/unordered_multiset_of.hpp` ]]
  87. [[`list_of` ][`list_of_relation` ][`boost/bimap/list_of.hpp` ]]
  88. [[`vector_of` ][`vector_of_relation` ][`boost/bimap/vector_of.hpp` ]]
  89. [[`unconstrained_set_of` ][`unconstrained_set_of_relation` ][`boost/bimap/unconstrained_set_of.hpp` ]]
  90. [[ ][`left_based` ][`boost/bimap/bimap.hpp` ]]
  91. [[ ][`right_based` ][`boost/bimap/bimap.hpp` ]]
  92. ]
  93. [endsect]
  94. [section Tags]
  95. Tags are just conventional types used as mnemonics for the types stored
  96. in a `bimap`. Boost.Bimap uses the tagged idiom to let the user specify
  97. this tags.
  98. [endsect]
  99. [section Header "boost/bimap/bimap.hpp" synopsis]
  100. namespace boost {
  101. namespace bimaps {
  102. template< class Type, typename Tag >
  103. struct tagged;
  104. // bimap template class
  105. template
  106. <
  107. class LeftCollectionType, class RightCollectionType,
  108. class AdditionalParameter_1 = detail::not_specified,
  109. class AdditionalParameter_2 = detail::not_specified
  110. >
  111. class bimap ``['- implementation defined { : public SetView } -]``
  112. {
  113. public:
  114. // Metadata
  115. typedef ``['-unspecified-]`` left_tag;
  116. typedef ``['-unspecified-]`` left_map;
  117. typedef ``['-unspecified-]`` right_tag;
  118. typedef ``['-unspecified-]`` right_map;
  119. // Shortcuts
  120. // typedef -side-_map::-type- -side-_-type-;
  121. typedef ``['-unspecified-]`` info_type;
  122. // Map views
  123. left_map left;
  124. right_map right;
  125. // Constructors
  126. bimap();
  127. template< class InputIterator >
  128. bimap(InputIterator first,InputIterator last);
  129. bimap(const bimap &);
  130. bimap& operator=(const bimap& b);
  131. // Projection of iterators
  132. template< class IteratorType >
  133. left_iterator project_left(IteratorType iter);
  134. template< class IteratorType >
  135. left_const_iterator project_left(IteratorType iter) const;
  136. template< class IteratorType >
  137. right_iterator project_right(IteratorType iter);
  138. template< class IteratorType >
  139. right_const_iterator project_right(IteratorType iter) const;
  140. template< class IteratorType >
  141. iterator project_up(IteratorType iter);
  142. template< class IteratorType >
  143. const_iterator project_up(IteratorType iter) const;
  144. // Support for tags
  145. template< class Tag >
  146. struct map_by;
  147. template< class Tag >
  148. map_by<Tag>::type by();
  149. template< class Tag >
  150. const map_by<Tag>::type & by() const;
  151. template< class Tag, class IteratorType >
  152. map_by<Tag>::iterator project(IteratorType iter);
  153. template< class Tag, class IteratorType >
  154. map_by<Tag>::const_iterator project(IteratorType iter) const
  155. };
  156. } // namespace bimap
  157. } // namespace boost
  158. [/
  159. // Metafunctions for a bimap
  160. template< class Tag, class Bimap > struct value_type_by;
  161. template< class Tag, class Bimap > struct key_type_by;
  162. template< class Tag, class Bimap > struct data_type_by;
  163. template< class Tag, class Bimap > struct iterator_type_by;
  164. template< class Tag, class Bimap > struct const_iterator_type_by;
  165. template< class Tag, class Bimap > struct reverse_iterator_type_by;
  166. template< class Tag, class Bimap > struct const_reverse_iterator_type_by;
  167. template< class Tag, class Bimap > struct local_iterator_type_by;
  168. template< class Tag, class Bimap > struct const_local_iterator_type_by;
  169. // Functions for a bimap
  170. template<class Tag, class Relation>
  171. result_of::map_by< Tag, Bimap>::type map_by(Bimap &);
  172. // Metafunctions for a relation
  173. template< class Tag, class Relation > struct value_type_of;
  174. template< class Tag, class Relation > struct pair_type_by;
  175. // Functions for a relation
  176. template<class Tag, class Relation>
  177. result_of::get< Tag, Relation>::type get(Relation &r);
  178. template<class Tag, class Relation>
  179. result_of::pair_by< Tag, Relation>::type pair_by(Relation &);
  180. ]
  181. [endsect]
  182. [section Class template bimap]
  183. This is the main component of Boost.Bimap.
  184. [section Complexity]
  185. In the descriptions of the operations of `bimap`, we adopt the scheme
  186. outlined in the complexity signature section.
  187. [endsect]
  188. [section Instantiation types]
  189. `bimap` is instantiated with the following types:
  190. # LeftCollectionType and RightCollectionType are collection type specifications
  191. optionally tagged, or any type optionally tagged, in which case that
  192. side acts as a set.
  193. # AdditionalParameter_{1/2} can be any ordered subset of:
  194. * CollectionTypeOfRelation specification
  195. * Allocator
  196. [endsect]
  197. [section Nested types]
  198. left_tag, right_tag
  199. [: Tags for each side of the bimap. If the user has not specified any tag the
  200. tags default to `member_at::left` and `member_at::right`.
  201. ]
  202. left_key_type, right_key_type
  203. [: Key type of each side. In a `bimap<A,B> ` `left_key_type` is `A` and
  204. `right_key_type` is `B`.
  205. If there are tags, it is better to use: `Bimap::map_by<Tag>::key_type`.
  206. ]
  207. left_data_type, right_data_type
  208. [: Data type of each side. In a bimap<A,B> left_key_type is B and
  209. right_key_type is A.
  210. If there are tags, it is better to use: `Bimap::map_by<Tag>::data_type`.
  211. ]
  212. left_value_type, right_value_type
  213. [: Value type used for the views.
  214. If there are tags, it is better to use: `Bimap::map_by<Tag>::value_type`.
  215. ]
  216. left_iterator, right_iterator
  217. left_const_iterator, right_const_iterator
  218. [: Iterators of the views.
  219. If there are tags, it is better to use:
  220. `Bimap::map_by<Tag>::iterator` and
  221. `Bimap::map_by<Tag>::const_iterator`
  222. ]
  223. left_map, right_map
  224. [: Map view type of each side.
  225. If there are tags, it is better to use:
  226. `Bimap::map_by<Tag>::type`.
  227. ]
  228. [endsect]
  229. [section Constructors, copy and assignment]
  230. bimap();
  231. * [*Effects:] Constructs an empty `bimap`.
  232. * [*Complexity:] Constant.
  233. template<typename InputIterator>
  234. bimap(InputIterator first,InputIterator last);
  235. * [*Requires: ] `InputIterator` is a model of Input Iterator over elements of
  236. type `relation` or a type convertible to `relation`. last is reachable from `first`.
  237. * [*Effects:] Constructs an empty `bimap` and fills it with the elements in the range
  238. `[first,last)`. Insertion of each element may or may not succeed depending on
  239. acceptance by the collection types of the `bimap`.
  240. * [link complexity_signature_explanation
  241. [*Complexity:]] O(m*H(m)), where m is the number of elements in `[first,last)`.
  242. bimap(const bimap & x);
  243. * [*Effects:] Constructs a copy of x, copying its elements as well as its
  244. internal objects (key extractors, comparison objects, allocator.)
  245. * [*Postconditions:] `*this == x`. The order of the views of the `bimap`
  246. is preserved as well.
  247. * [*Complexity:] O(x.size()*log(x.size()) + C(x.size()))
  248. ~bimap()
  249. * [*Effects:] Destroys the `bimap` and all the elements contained.
  250. The order in which the elements are destroyed is not specified.
  251. * [*Complexity:] O(n).
  252. bimap& operator=(const bimap& x);
  253. * [*Effects:] Replaces the elements and internal objects of the `bimap`
  254. with copies from x.
  255. * [*Postconditions:] `*this==x`. The order on the views of the `bimap`
  256. is preserved as well.
  257. * [*Returns: ] `*this`.
  258. * [*Complexity:] O(n + x.size()*log(x.size()) + C(x.size())).
  259. * [*Exception safety:] Strong, provided the copy and assignment operations
  260. of the types of `ctor_args_list` do not throw.
  261. [/
  262. allocator_type get_allocator() const;
  263. * [*Effects:] Returns a copy of the `allocator_type` object used to construct
  264. the `bimap`.
  265. * [*Complexity:] Constant.
  266. ]
  267. [endsect]
  268. [#reference_projection_operations]
  269. [section Projection operations]
  270. Given a `bimap` with views v1 and v2, we say than an v1-iterator
  271. it1 and an v2-iterator it2 are equivalent if:
  272. * `it1 == i1.end()` AND `it2 == i2.end()`,
  273. * OR `it1` and `it2` point to the same element.
  274. template< class IteratorType >
  275. left_iterator project_left(IteratorType iter);
  276. template< class IteratorType >
  277. left_const_iterator project_left(IteratorType iter) const;
  278. * [*Requires:] `IteratorType` is a bimap view iterator. it is a
  279. valid iterator of some view of `*this` (i.e. does not refer to some other
  280. `bimap`.)
  281. * [*Effects:] Returns a left map view iterator equivalent to `it`.
  282. * [*Complexity:] Constant.
  283. * [*Exception safety:] nothrow.
  284. template< class IteratorType >
  285. right_iterator project_right(IteratorType iter);
  286. template< class IteratorType >
  287. right_const_iterator project_right(IteratorType iter) const;
  288. * [*Requires:] `IteratorType` is a bimap view iterator. it is a
  289. valid iterator of some view of `*this` (i.e. does not refer to some other
  290. `bimap`.)
  291. * [*Effects:] Returns a right map view iterator equivalent to `it`.
  292. * [*Complexity:] Constant.
  293. * [*Exception safety:] nothrow.
  294. template< class IteratorType >
  295. iterator project_up(IteratorType iter);
  296. template< class IteratorType >
  297. const_iterator project_up(IteratorType iter) const;
  298. * [*Requires:] `IteratorType` is a bimap view iterator. it is a
  299. valid iterator of some view of `*this` (i.e. does not refer to some other
  300. `bimap`.)
  301. * [*Effects:] Returns a collection of relations view iterator equivalent to `it`.
  302. * [*Complexity:] Constant.
  303. * [*Exception safety:] nothrow.
  304. [endsect]
  305. [#reference_support_for_used_defined_names]
  306. [section Support for user defined names]
  307. template< class Tag >
  308. struct map_by;
  309. * `map_by<Tag>::type` yields the type of the map view tagged with `Tag`.
  310. `map_by<Tag>::`['-type name-] is the same as `map_by<Tag>::type::`['-type name-].
  311. * [*Requires: ] `Tag` is a valid user defined name of the bimap.
  312. template< class Tag >
  313. map_by<Tag>::type by();
  314. template< class Tag >
  315. const map_by<Tag>::type & by() const;
  316. * [*Requires: ] `Tag` is a valid user defined name of the bimap.
  317. * [*Effects:] Returns a reference to the map view tagged with `Tag` held by
  318. `*this`.
  319. * [*Complexity:] Constant.
  320. * [*Exception safety:] nothrow.
  321. template< class Tag, class IteratorType >
  322. map_by<Tag>::iterator project(IteratorType iter);
  323. template< class Tag, class IteratorType >
  324. map_by<Tag>::const_iterator project(IteratorType iter) const
  325. * [*Requires: ] `Tag` is a valid user defined name of the bimap. `IteratorType`
  326. is a bimap view iterator. it is a valid iterator of some view of `*this`
  327. (i.e. does not refer to some other `bimap`.)
  328. * [*Effects:] Returns a reference to the map view tagged with `Tag` held by
  329. `*this`.
  330. * [*Complexity:] Constant.
  331. * [*Exception safety:] nothrow.
  332. [endsect]
  333. [section Serialization]
  334. A `bimap` can be archived and retrieved by means of __BOOST_SERIALIZATION__.
  335. Boost.Bimap does not expose a public serialisation interface, as this is
  336. provided by Boost.Serialization itself. Both regular and XML archives
  337. are supported.
  338. Each of the set specifications comprising a given `bimap` contributes its
  339. own preconditions as well as guarantees on the retrieved containers. In describing
  340. these, the following concepts are used. A type `T` is ['serializable]
  341. (resp. XML-serializable) if any object of type `T` can be saved to an output
  342. archive (XML archive) and later retrieved from an input archive (XML archive)
  343. associated to the same storage. If `x`' of type `T` is loaded from the serialization
  344. information saved from another object x, we say that x' is a ['restored copy] of x.
  345. Given a __SGI_BINARY_PREDICATE__ `Pred` over `(T, T)`, and objects `p` and `q` of
  346. type `Pred`, we say that `q` is ['serialization-compatible] with `p` if
  347. * `p(x,y) == q(x`'`,y`'`)`
  348. for every `x` and `y` of type `T` and `x`' and `y`' being restored copies of `x`
  349. and `y`, respectively.
  350. [blurb [*Operation:] saving of a `bimap b` to an output archive
  351. (XML archive) ar.]
  352. * [*Requires:] Value is serializable (XML-serializable). Additionally, each
  353. of the views of b can impose other requirements.
  354. * [*Exception safety:] Strong with respect to `b`. If an exception is thrown, ar
  355. may be left in an inconsistent state.
  356. [blurb [*Operation:] loading of a `bimap` m' from an input archive
  357. (XML archive) ar.]
  358. * [*Requires:] Value is serializable (XML-serializable). Additionally, each of
  359. the views of `b`' can impose other requirements.
  360. * [*Exception safety:] Basic. If an exception is thrown, ar may be left in an
  361. inconsistent state.
  362. [endsect]
  363. [endsect]
  364. [endsect]