1 // (C) Copyright Jeremy Siek 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <iostream>
7 #include <map>
8 #include <string>
9 #include <boost/property_map/property_map.hpp>
10
11
12 template <typename AddressMap>
foo(AddressMap address)13 void foo(AddressMap address)
14 {
15 typedef typename boost::property_traits<AddressMap>::value_type value_type;
16 typedef typename boost::property_traits<AddressMap>::key_type key_type;
17
18 value_type old_address, new_address;
19 key_type fred = "Fred";
20 old_address = get(address, fred);
21 new_address = "384 Fitzpatrick Street";
22 put(address, fred, new_address);
23
24 key_type joe = "Joe";
25 value_type& joes_address = address[joe];
26 joes_address = "325 Cushing Avenue";
27 }
28
29 int
main()30 main()
31 {
32 std::map<std::string, std::string> name2address;
33 boost::associative_property_map< std::map<std::string, std::string> >
34 address_map(name2address);
35
36 name2address.insert(make_pair(std::string("Fred"),
37 std::string("710 West 13th Street")));
38 name2address.insert(make_pair(std::string("Joe"),
39 std::string("710 West 13th Street")));
40
41 foo(address_map);
42
43 for (std::map<std::string, std::string>::iterator i = name2address.begin();
44 i != name2address.end(); ++i)
45 std::cout << i->first << ": " << i->second << "\n";
46
47 return EXIT_SUCCESS;
48 }
49