example1.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <iostream>
  6. #include <map>
  7. #include <string>
  8. #include <boost/property_map/property_map.hpp>
  9. template <typename AddressMap>
  10. void foo(AddressMap address)
  11. {
  12. typedef typename boost::property_traits<AddressMap>::value_type value_type;
  13. typedef typename boost::property_traits<AddressMap>::key_type key_type;
  14. value_type old_address, new_address;
  15. key_type fred = "Fred";
  16. old_address = get(address, fred);
  17. new_address = "384 Fitzpatrick Street";
  18. put(address, fred, new_address);
  19. key_type joe = "Joe";
  20. value_type& joes_address = address[joe];
  21. joes_address = "325 Cushing Avenue";
  22. }
  23. int
  24. main()
  25. {
  26. std::map<std::string, std::string> name2address;
  27. boost::associative_property_map< std::map<std::string, std::string> >
  28. address_map(name2address);
  29. name2address.insert(make_pair(std::string("Fred"),
  30. std::string("710 West 13th Street")));
  31. name2address.insert(make_pair(std::string("Joe"),
  32. std::string("710 West 13th Street")));
  33. foo(address_map);
  34. for (std::map<std::string, std::string>::iterator i = name2address.begin();
  35. i != name2address.end(); ++i)
  36. std::cout << i->first << ": " << i->second << "\n";
  37. return EXIT_SUCCESS;
  38. }