summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/property_map/example/example2.cpp
blob: 3340272358e8484df38c714cf98ba58e0e232c3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//  (C) Copyright Ronald Garcia, Jeremy Siek 2002. 
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <iostream>
#include <map>
#include <string>
#include <boost/property_map/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;
}