const_associative_property_map<UniquePairAssociativeContainer> This property map is an adaptor that converts any type that is a model of both Pair Associative Container and Unique Associative Container such as std::map into a constant Lvalue Property Map. Note that the adaptor only retains a reference to the container, so the lifetime of the container must encompass the use of the adaptor. Exampleexample1.cpp:#include <iostream> #include <map> #include <string> #include <boost/property_map.hpp> template <typename ConstAddressMap> void display(ConstAddressMap address) { typedef typename boost::property_traits<ConstAddressMap>::value_type value_type; typedef typename boost::property_traits<ConstAddressMap>::key_type key_type; key_type fred = "Fred"; key_type joe = "Joe"; value_type freds_address = get(address, fred); value_type joes_address = get(address, joe); std::cout << fred << ": " << freds_address << "\n" << joe << ": " << joes_address << "\n"; } int main() { std::map<std::string, std::string> name2address; boost::const_associative_property_map< std::map<std::string, std::string> > address_map(name2address); name2address.insert(make_pair(std::string("Fred"), std::string("710 West 13th Street"))); name2address.insert(make_pair(std::string("Joe"), std::string("710 West 13th Street"))); display(address_map); return EXIT_SUCCESS; } Where Defined
Model OfLvalue Property Map
Template Parameters
MembersIn addition to the methods and functions required by Lvalue Property Map, this class has the following members. property_traits<const_associative_property_map>::value_typeThis is the same type as UniquePairAssociativeContainer::data_type. const_associative_property_map()Default Constructor. const_associative_property_map(const UniquePairAssociativeContainer& c)Constructor. const data_type& operator[](const key_type& k) constThe operator bracket for property access. The key_type and data_type types are from the typedefs inside of UniquePairAssociativeContainer. Non-Member functionstemplate <typename UniquePairAssociativeContainer> const_associative_property_map<UniquePairAssociativeContainer> make_assoc_property_map(const UniquePairAssociativeContainer& c);A function for conveniently creating an associative property map.
|