C++ Boost

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 mutable 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.

Example

example1.cpp:
#include <iostream>
#include <map>
#include <string>
#include <boost/property_map/property_map.hpp>


template <typename AddressMap>
void foo(AddressMap address)
{
  typedef typename boost::property_traits<AddressMap>::value_type value_type;
  typedef typename boost::property_traits<AddressMap>::key_type key_type;

  value_type old_address, new_address;
  key_type fred = "Fred";
  old_address = get(address, fred);
  new_address = "384 Fitzpatrick Street";
  put(address, fred, new_address);

  key_type joe = "Joe";
  value_type& joes_address = address[joe];
  joes_address = "325 Cushing Avenue";
}

int
main()
{
  std::map<std::string, std::string> name2address;
  boost::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")));

  foo(address_map);
  
  for (std::map<std::string, std::string>::iterator i = name2address.begin();
       i != name2address.end(); ++i)
    std::cout << i->first << ": " << i->second << "\n";

  return EXIT_SUCCESS;
}

Where Defined

boost/property_map/property_map.hpp

Model Of

Lvalue Property Map

Template Parameters

ParameterDescriptionDefault
UniquePairAssociativeContainer Must be a model of both Pair Associative Container and Unique Associative Container .  

Members

In addition to the methods and functions required by Lvalue Property Map, this class has the following members.


property_traits<associative_property_map>::value_type
This is the same type as UniquePairAssociativeContainer::data_type.
associative_property_map()
Default Constructor.
associative_property_map(UniquePairAssociativeContainer& c)
Constructor.
data_type& operator[](const key_type& k) const
The operator bracket for property access. The key_type and data_type types are from the typedefs inside of UniquePairAssociativeContainer.

Non-Member functions


  template <typename UniquePairAssociativeContainer>
  associative_property_map<UniquePairAssociativeContainer>
  make_assoc_property_map(UniquePairAssociativeContainer& c);
A function for conveniently creating an associative property map.


Copyright © 2002 Jeremy Siek, Indiana University (jsiek@osl.iu.edu)
Lie-Quan Lee, Indiana University (llee1@osl.iu.edu)
Andrew Lumsdaine, Indiana University (lums@osl.iu.edu)