📄 bimap_and_boost.qbk
字号:
[/licenseBoost.BimapCopyright (c) 2006-2007 Matias CapelettoDistributed under the Boost Software License, Version 1.0.(See accompanying file LICENSE_1_0.txt or copy athttp://www.boost.org/LICENSE_1_0.txt)][/ QuickBook Document version 1.4 ][section Bimap and Boost][section Bimap and MultiIndex]['MISC] - [*M]ulti-[*I]ndex [*S]pecialized [*C]ontainers[:['Let's be generic, construct frameworks, describe the world in anunified way...]][:['No!, it is better to be specialized, design easy-to-use components,offer plug-and-play objects...]][:[*Why not take advantage of the best of both worlds?]]__MI_FRAMEWORK__With Boost.Bimap, you can build associative containers in which bothtypes can be used as key. There is a library in Boost that alreadyallows the creation of this kind of container: Boost.MultiIndex. Itoffers great flexibility and lets you construct almost any containerthat you could dream of. The framework is very clean. You migh want toread this library's tutorial to learn about the power that has beenachieved.But generality comes at a price: the interface that results might not bethe best for every specialization. People may end up wrapping a B.MIcontainer in its own class every time they want to use it as abidirectional map. Boost.Bimap takes advantage of the narrower scope toproduce a better interface for bidirectional maps[footnote In the same fashion, Boost.MRU will allow the creation of ['mostrecent updated] aware containers, hiding the complexity of Boost.MultiIndex.].There is no learning curve if you know how to use standard containers.Great effort was put into mapping the naming scheme of the STL to Boost.Bimap.The library is designed to match the common STL containers.Boost.MultiIndex is, in fact, the core of the bimap container.However, Boost.Bimap do not aim to tackle every problem with two indexedtypes. There exist some problems that are better modelled with Boost.MultiIndex.[blurb[*Problem I - An employee register]['Store an ID and a name for an employee, with fast search on each member.]This type of problem is better modelled as a database table, and[*Boost.MultiIndex] is the preferred choice. It is possible that other datawill need to be indexed later.][blurb[*Problem II - A partners container]['Store the names of couples and be able to get the name of a person'spartner.]This problem is better modelled as a collection of relations, and [*Boost.Bimap]fits nicely here.]You can also read [link boost_bimap.the_tutorial.additional_information Additional Information] for moreinformation about the relation of this two libraries.[endsect][section Boost Libraries that work well with Boost.Bimap][section Introduction][table[[Name][Description][author][Purpose]][[ __BOOST_SERIALIZATION__ ][Serialization for persistence and marshalling][Robert Ramey][Serialization support for bimap containers and iterators]][[ __BOOST_ASSIGN__ ][Filling containers with constant or generated data has never been easier][Thorsten Ottosen][Help to fill a bimap or views of it]][[ __BOOST_HASH__ ][A TR1 hash function object that can be extended to hash user defined types][Daniel James][Default hashing function]][[ __BOOST_LAMBDA__ ][Define small unnamed function objects at the actual call site, and more][from Jaakko Järvi, Gary Powell][Functors for modify, range, lower_bound and upper_bound]][[ __BOOST_RANGE__ ][A new infrastructure for generic algorithms that builds on top of the newiterator concepts][Thorsten Ottosen][Range based algorithms]][[ __BOOST_FOREACH__ ][BOOST_FOREACH macro for easily iterating over the elements of a sequence][Eric Niebler][Iteration]][[ __BOOST_TYPEOF__ ][Typeof operator emulation][Arkadiy Vertleyb, Peder Holt][Using BOOST_AUTO while we wait for C++0x]][[ __BOOST_XPRESSIVE__ ][Regular expressions that can be written as strings or as expression templates][Eric Niebler][Help to fill a bimap from a string]][[ __BOOST_PROPERTY_MAP__ ][Concepts defining interfaces which map key objects to value objects][Jeremy Siek][Integration with BGL]]][endsect][section Boost.Serialization]A bimap can be archived and retrieved by means of the Boost.Serialization Library.Both regular and XML archives are supported. The usage is straightforward and doesnot differ from that of any other serializable type. For instance:[import ../example/bimap_and_boost/serialization.cpp][@../../example/bimap_and_boost/serialization.cpp Go to source code][code_bimap_and_boost_serialization]Serialization capabilities are automatically provided by just linking with theappropriate Boost.Serialization library module: it is not necessary to explicitlyinclude any header from Boost.Serialization, apart from those declaring the typeof archive used in the process. If not used, however, serialization support canbe disabled by globally defining the macro BOOST_BIMAP_DISABLE_SERIALIZATION.Disabling serialization for Boost.MultiIndex can yield a small improvement inbuild times, and may be necessary in those defective compilers that fail tocorrectly process Boost.Serialization headers.[warning Boost.Bimap and Boost.MultiIndex share a lot of serialization code.The macro `BOOST_BIMAP_DISABLE_SERIALIZATION` disables serialization in *both*libraries. The same happens when `BOOST_MULTI_INDEX_DISABLE_SERIALIZATION` isdefined.]Retrieving an archived bimap restores not only the elements, but also the orderthey were arranged in the views of the container. There is an exception to this rule,though: for unordered sets, no guarantee is made about the order in which elementswill be iterated in the restored container; in general, it is unwise to rely onthe ordering of elements of a hashed view, since it can change in arbitrary waysduring insertion or rehashing --this is precisely the reason why hashed indicesand TR1 unordered associative containers do not define an equality operator.Iterators of a bimap can also be serialized. Serialization of aniterator must be done only after serializing its corresponding container.[endsect][section Boost.Assign]The purpose of this library is to make it easy to fill containers with data byoverloading operator,() and operator()(). These two operators make it possibleto construct lists of values that are then copied into a container.These lists are particularly useful in learning, testing, and prototypingsituations, but can also be handy otherwise. The library comes with predefinedoperators for the containers of the standard library, but most functionality willwork with any standard compliant container. The library also makes it possibleto extend user defined types so for example a member function can be called fora list of values instead of its normal arguments.Boost.Assign can be used with bimap containers.The views of a bimap are signature-compatible with their standardcounterparts, so we can use other Boost.Assign utilities with them.[import ../example/bimap_and_boost/assign.cpp][@../../example/bimap_and_boost/assign.cpp Go to source code][code_bimap_and_boost_assign][endsect][section Boost.Hash]The hash function is the very core of the fast lookup capabilities of theunordered sets: a hasher is just a Unary Function returning an std::size_t valuefor any given key. In general, it is impossible that every key map to adifferent hash value, for the space of keys can be greater than the number of permissible hash codes: what makes for a good hasher is that the probability of a collision (two different keys with the same hash value) is as close to zero as possible.This is a statistical property depending on the typical distribution of keys in a given application, so it is not feasible to have a general-purpose hash function with excellent results in every possible scenario; the default value for this parameter uses Boost.Hash, which often provides good enough results.Boost.Hash can be[@http://www.boost.org/doc/html/hash/custom.htmlextended for custom data types],enabling to use the default parameter of the unordered set types with any user types.[endsect][section Boost.Lambda]The Boost Lambda Library (BLL in the sequel) is a C++ template library, which implementsform of lambda abstractions for C++. The term originates from functional programming andlambda calculus, where a lambda abstraction defines an unnamed function.Lambda expressions are very useful to construct the function objects required by some ofthe functions in a bimap view.Boost.Bimap defines new placeholders in `<boost/bimap/support/lambda.hpp>`to allow a sounder solution. The placeholders are named _key and _data and bothare equivalent to boost::lambda::_1. There are two reasons to include this placeholders:the code looks better with them and they avoid the clash problem between lambda::_1 and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -