example2.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // (C) Copyright Ronald Garcia, 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 ConstAddressMap>
  10. void display(ConstAddressMap address)
  11. {
  12. typedef typename boost::property_traits<ConstAddressMap>::value_type
  13. value_type;
  14. typedef typename boost::property_traits<ConstAddressMap>::key_type key_type;
  15. key_type fred = "Fred";
  16. key_type joe = "Joe";
  17. value_type freds_address = get(address, fred);
  18. value_type joes_address = get(address, joe);
  19. std::cout << fred << ": " << freds_address << "\n"
  20. << joe << ": " << joes_address << "\n";
  21. }
  22. int
  23. main()
  24. {
  25. std::map<std::string, std::string> name2address;
  26. boost::const_associative_property_map< std::map<std::string, std::string> >
  27. address_map(name2address);
  28. name2address.insert(make_pair(std::string("Fred"),
  29. std::string("710 West 13th Street")));
  30. name2address.insert(make_pair(std::string("Joe"),
  31. std::string("710 West 13th Street")));
  32. display(address_map);
  33. return EXIT_SUCCESS;
  34. }