const_assoc_property_map.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <HTML>
  2. <!--
  3. Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2000
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <Head>
  9. <Title>Constant Associative Property Map Adaptor</Title>
  10. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  11. ALINK="#ff0000">
  12. <IMG SRC="../../../boost.png"
  13. ALT="C++ Boost" width="277" height="86">
  14. <BR Clear>
  15. <H2><A NAME="sec:const-associative-property-map"></A>
  16. </h2>
  17. <PRE>
  18. const_associative_property_map&lt;UniquePairAssociativeContainer&gt;
  19. </PRE>
  20. <P>
  21. This property map is an adaptor that converts any type that is a model
  22. of both <a
  23. href="http://www.sgi.com/tech/stl/PairAssociativeContainer.html">Pair
  24. Associative Container</a> and <a
  25. href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
  26. Associative Container</a> such as <a
  27. href="http://www.sgi.com/tech/stl/Map.html"><tt>std::map</tt></a> into
  28. a constant <a href="./LvaluePropertyMap.html">Lvalue Property Map</a>.
  29. Note that the adaptor only retains a reference to the container, so
  30. the lifetime of the container must encompass the use of the adaptor.
  31. </P>
  32. <h3>Example</h3>
  33. <a href="../example/example1.cpp">example1.cpp</a>:
  34. <pre>
  35. <font color="#008040">#include &lt;iostream&gt;</font>
  36. <font color="#008040">#include &lt;map&gt;</font>
  37. <font color="#008040">#include &lt;string&gt;</font>
  38. <font color="#008040">#include &lt;boost/property_map/property_map.hpp&gt;</font>
  39. <B>template</B> &lt;<B>typename</B> ConstAddressMap&gt;
  40. <B>void</B> display(ConstAddressMap address)
  41. {
  42. <B>typedef</B> <B>typename</B> boost::property_traits&lt;ConstAddressMap&gt;::value_type
  43. value_type;
  44. <B>typedef</B> <B>typename</B> boost::property_traits&lt;ConstAddressMap&gt;::key_type key_type;
  45. key_type fred = <font color="#0000FF">"Fred"</font>;
  46. key_type joe = <font color="#0000FF">"Joe"</font>;
  47. value_type freds_address = get(address, fred);
  48. value_type joes_address = get(address, joe);
  49. std::cout &lt;&lt; fred &lt;&lt; <font color="#0000FF">": "</font> &lt;&lt; freds_address &lt;&lt; <font color="#0000FF">"\n"</font>
  50. &lt;&lt; joe &lt;&lt; <font color="#0000FF">": "</font> &lt;&lt; joes_address &lt;&lt; <font color="#0000FF">"\n"</font>;
  51. }
  52. <B>int</B>
  53. main()
  54. {
  55. std::map&lt;std::string, std::string&gt; name2address;
  56. boost::const_associative_property_map&lt; std::map&lt;std::string, std::string&gt; &gt;
  57. address_map(name2address);
  58. name2address.insert(make_pair(std::string(<font color="#0000FF">"Fred"</font>),
  59. std::string(<font color="#0000FF">"710 West 13th Street"</font>)));
  60. name2address.insert(make_pair(std::string(<font color="#0000FF">"Joe"</font>),
  61. std::string(<font color="#0000FF">"710 West 13th Street"</font>)));
  62. display(address_map);
  63. <B>return</B> EXIT_SUCCESS;
  64. }
  65. </PRE>
  66. <H3>Where Defined</H3>
  67. <P>
  68. <a href="../../../boost/property_map/property_map.hpp"><TT>boost/property_map/property_map.hpp</TT></a>
  69. <p>
  70. <H3>Model Of</H3>
  71. <a href="./LvaluePropertyMap.html">Lvalue Property Map</a>
  72. <P>
  73. <H3>Template Parameters</H3>
  74. <P>
  75. <TABLE border>
  76. <TR>
  77. <th>Parameter</th><th>Description</th><th>Default</th>
  78. </tr>
  79. <TR>
  80. <TD><TT>UniquePairAssociativeContainer</TT></TD>
  81. <TD>Must be a model of both <a
  82. href="http://www.sgi.com/tech/stl/PairAssociativeContainer.html">Pair
  83. Associative Container</a> and <a
  84. href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
  85. Associative Container</a> .</TD>
  86. <TD>&nbsp;</td>
  87. </tr>
  88. </TABLE>
  89. <P>
  90. <H3>Members</H3>
  91. <P>
  92. In addition to the methods and functions required by <a
  93. href="./LvaluePropertyMap.html">Lvalue Property Map</a>, this
  94. class has the following members.
  95. <hr>
  96. <pre>
  97. property_traits&lt;const_associative_property_map&gt;::value_type
  98. </pre>
  99. This is the same type as
  100. <TT>UniquePairAssociativeContainer::data_type</TT>.
  101. <hr>
  102. <pre>
  103. const_associative_property_map()
  104. </pre>
  105. Default Constructor.
  106. <pre>
  107. const_associative_property_map(const UniquePairAssociativeContainer&amp; c)
  108. </pre>
  109. Constructor.
  110. <hr>
  111. <pre>
  112. const data_type&amp; operator[](const key_type&amp; k) const
  113. </pre>
  114. The operator bracket for property access.
  115. The <TT>key_type</TT> and
  116. <TT>data_type</TT> types are from the typedefs inside of
  117. <TT>UniquePairAssociativeContainer</TT>.
  118. <hr>
  119. <h3>Non-Member functions</h3>
  120. <hr>
  121. <pre>
  122. template &lt;typename UniquePairAssociativeContainer&gt;
  123. const_associative_property_map&lt;UniquePairAssociativeContainer&gt;
  124. make_assoc_property_map(const UniquePairAssociativeContainer&amp; c);
  125. </pre>
  126. A function for conveniently creating an associative property map.
  127. <hr>
  128. <br>
  129. <HR>
  130. <TABLE>
  131. <TR valign=top>
  132. <TD nowrap>Copyright &copy 2002</TD><TD>
  133. <a HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>,
  134. Indiana University (<A
  135. HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
  136. <A HREF="http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee</A>, Indiana University (<A HREF="mailto:llee1@osl.iu.edu">llee1@osl.iu.edu</A>)<br>
  137. <A HREF="http://www.osl.iu.edu/~lums">Andrew Lumsdaine</A>,
  138. Indiana University (<A
  139. HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
  140. </TD></TR></TABLE>
  141. </BODY>
  142. </HTML>