at.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="generator" content="Docutils 0.7: http://docutils.sourceforge.net/" />
  7. <title>The MPL Reference Manual: at</title>
  8. <link rel="stylesheet" href="../style.css" type="text/css" />
  9. </head>
  10. <body class="docframe refmanual">
  11. <table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./intrinsic-metafunctions.html" class="navigation-link">Prev</a>&nbsp;<a href="./at-c.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group">Back&nbsp;<a href="./at-c.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./intrinsic-metafunctions.html" class="navigation-link">Up</a>&nbsp;<a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td>
  12. <td class="header-group page-location"><a href="../refmanual.html" class="navigation-link">Front Page</a> / <a href="./sequences.html" class="navigation-link">Sequences</a> / <a href="./intrinsic-metafunctions.html" class="navigation-link">Intrinsic Metafunctions</a> / <a href="./at.html" class="navigation-link">at</a></td>
  13. </tr></table><div class="header-separator"></div>
  14. <div class="section" id="at">
  15. <h1><a class="toc-backref" href="./intrinsic-metafunctions.html#id1425">at</a></h1>
  16. <div class="section" id="id177">
  17. <h3><a class="subsection-title" href="#synopsis" name="synopsis">Synopsis</a></h3>
  18. <pre class="literal-block">
  19. template&lt;
  20. typename Sequence
  21. , typename N
  22. &gt;
  23. struct <a href="./at.html" class="identifier">at</a>
  24. {
  25. typedef <em>unspecified</em> type;
  26. };
  27. template&lt;
  28. typename AssocSeq
  29. , typename Key
  30. , typename Default = <em>unspecified</em>
  31. &gt;
  32. struct <a href="./at.html" class="identifier">at</a>
  33. {
  34. typedef <em>unspecified</em> type;
  35. };
  36. </pre>
  37. </div>
  38. <div class="section" id="id178">
  39. <h3><a class="subsection-title" href="#description" name="description">Description</a></h3>
  40. <p><tt class="literal"><span class="pre"><a href="./at.html" class="identifier">at</a></span></tt> is an <a class="reference internal" href="./terminology.html#overloaded-name">overloaded name</a>:</p>
  41. <ul class="simple">
  42. <li><tt class="literal"><span class="pre"><a href="./at.html" class="identifier">at</a>&lt;Sequence,N&gt;</span></tt> returns the <tt class="literal"><span class="pre">N</span></tt>-th element from the beginning of the
  43. <a class="reference internal" href="./forward-sequence.html">Forward Sequence</a> <tt class="literal"><span class="pre">Sequence</span></tt>.</li>
  44. <li><tt class="literal"><span class="pre"><a href="./at.html" class="identifier">at</a>&lt;AssocSeq,Key,Default&gt;</span></tt> returns the first element associated with <tt class="literal"><span class="pre">Key</span></tt>
  45. in the <a class="reference internal" href="./associative-sequence.html">Associative Sequence</a> <tt class="literal"><span class="pre">AssocSeq</span></tt>, or <tt class="literal"><span class="pre">Default</span></tt> if no such element
  46. exists.</li>
  47. </ul>
  48. </div>
  49. <div class="section" id="id179">
  50. <h3><a class="subsection-title" href="#header" name="header">Header</a></h3>
  51. <pre class="literal-block">
  52. #include &lt;<a href="../../../../boost/mpl/at.hpp" class="header">boost/mpl/at.hpp</a>&gt;
  53. </pre>
  54. </div>
  55. <div class="section" id="id180">
  56. <h3><a class="subsection-title" href="#model-of" name="model-of">Model of</a></h3>
  57. <p><a class="reference internal" href="./tag-dispatched-metafunction.html">Tag Dispatched Metafunction</a></p>
  58. </div>
  59. <div class="section" id="id181">
  60. <h3><a class="subsection-title" href="#parameters" name="parameters">Parameters</a></h3>
  61. <table border="1" class="docutils table">
  62. <colgroup>
  63. <col width="17%" />
  64. <col width="30%" />
  65. <col width="53%" />
  66. </colgroup>
  67. <thead valign="bottom">
  68. <tr><th class="head">Parameter</th>
  69. <th class="head">Requirement</th>
  70. <th class="head">Description</th>
  71. </tr>
  72. </thead>
  73. <tbody valign="top">
  74. <tr><td><tt class="literal"><span class="pre">Sequence</span></tt></td>
  75. <td><a class="reference internal" href="./forward-sequence.html">Forward Sequence</a></td>
  76. <td>A sequence to be examined.</td>
  77. </tr>
  78. <tr><td><tt class="literal"><span class="pre">AssocSeq</span></tt></td>
  79. <td><a class="reference internal" href="./associative-sequence.html">Associative Sequence</a></td>
  80. <td>A sequence to be examined.</td>
  81. </tr>
  82. <tr><td><tt class="literal"><span class="pre">N</span></tt></td>
  83. <td><a class="reference internal" href="./integral-constant.html">Integral Constant</a></td>
  84. <td>An offset from the beginning of the sequence
  85. specifying the element to be retrieved.</td>
  86. </tr>
  87. <tr><td><tt class="literal"><span class="pre">Key</span></tt></td>
  88. <td>Any type</td>
  89. <td>A key for the element to be retrieved.</td>
  90. </tr>
  91. <tr><td><tt class="literal"><span class="pre">Default</span></tt></td>
  92. <td>Any type</td>
  93. <td>A default value to return if the element is
  94. not found.</td>
  95. </tr>
  96. </tbody>
  97. </table>
  98. </div>
  99. <div class="section" id="id182">
  100. <h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3>
  101. <div class="expression-semantics compound">
  102. <p class="compound-first">For any <a class="reference internal" href="./forward-sequence.html">Forward Sequence</a> <tt class="literal"><span class="pre">s</span></tt>, and <a class="reference internal" href="./integral-constant.html">Integral Constant</a> <tt class="literal"><span class="pre">n</span></tt>:</p>
  103. <pre class="compound-middle literal-block">
  104. typedef <a href="./at.html" class="identifier">at</a>&lt;s,n&gt;::type t;
  105. </pre>
  106. <table class="compound-last docutils field-list" frame="void" rules="none">
  107. <col class="field-name" />
  108. <col class="field-body" />
  109. <tbody valign="top">
  110. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">A type.</p>
  111. </td>
  112. </tr>
  113. <tr class="field"><th class="field-name">Precondition:</th><td class="field-body"><p class="first"><tt class="literal"><span class="pre">0</span> <span class="pre">&lt;=</span> <span class="pre">n::value</span> <span class="pre">&lt;</span> <span class="pre"><a href="./size.html" class="identifier">size</a>&lt;s&gt;::value</span></tt>.</p>
  114. </td>
  115. </tr>
  116. <tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">Equivalent to</p>
  117. <pre class="last literal-block">
  118. typedef <a href="./deref.html" class="identifier">deref</a>&lt; <a href="./advance.html" class="identifier">advance</a>&lt; <a href="./begin.html" class="identifier">begin</a>&lt;s&gt;::type,n &gt;::type &gt;::type t;
  119. </pre>
  120. </td>
  121. </tr>
  122. </tbody>
  123. </table>
  124. </div>
  125. <div class="expression-semantics compound">
  126. <p class="compound-first">For any <a class="reference internal" href="./associative-sequence.html">Associative Sequence</a> <tt class="literal"><span class="pre">s</span></tt>, and arbitrary types <tt class="literal"><span class="pre">key</span></tt> and <tt class="literal"><span class="pre">x</span></tt>:</p>
  127. <pre class="compound-middle literal-block">
  128. typedef <a href="./at.html" class="identifier">at</a>&lt;s,key,x&gt;::type t;
  129. </pre>
  130. <table class="compound-middle docutils field-list" frame="void" rules="none">
  131. <col class="field-name" />
  132. <col class="field-body" />
  133. <tbody valign="top">
  134. <tr class="field"><th class="field-name">Return type:</th><td class="field-body">A type.</td>
  135. </tr>
  136. <tr class="field"><th class="field-name">Semantics:</th><td class="field-body">If <tt class="literal"><span class="pre"><a href="./has-key.html" class="identifier">has_key</a>&lt;s,key&gt;::value</span> <span class="pre">==</span> <span class="pre">true</span></tt>, <tt class="literal"><span class="pre">t</span></tt> is the value type associated with <tt class="literal"><span class="pre">key</span></tt>;
  137. otherwise <tt class="literal"><span class="pre">t</span></tt> is identical to <tt class="literal"><span class="pre">x</span></tt>.</td>
  138. </tr>
  139. </tbody>
  140. </table>
  141. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  142. <pre class="compound-middle literal-block">
  143. typedef <a href="./at.html" class="identifier">at</a>&lt;s,key&gt;::type t;
  144. </pre>
  145. <table class="compound-last docutils field-list" frame="void" rules="none">
  146. <col class="field-name" />
  147. <col class="field-body" />
  148. <tbody valign="top">
  149. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">A type.</p>
  150. </td>
  151. </tr>
  152. <tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">Equivalent to</p>
  153. <pre class="last literal-block">
  154. typedef <a href="./at.html" class="identifier">at</a>&lt;s,key,<a href="./void.html" class="identifier">void_</a>&gt;::type t;
  155. </pre>
  156. </td>
  157. </tr>
  158. </tbody>
  159. </table>
  160. </div>
  161. </div>
  162. <div class="section" id="complexity">
  163. <h3>Complexity</h3>
  164. <table border="1" class="docutils table">
  165. <colgroup>
  166. <col width="47%" />
  167. <col width="53%" />
  168. </colgroup>
  169. <thead valign="bottom">
  170. <tr><th class="head">Sequence archetype</th>
  171. <th class="head">Complexity</th>
  172. </tr>
  173. </thead>
  174. <tbody valign="top">
  175. <tr><td><a class="reference internal" href="./forward-sequence.html">Forward Sequence</a></td>
  176. <td>Linear.</td>
  177. </tr>
  178. <tr><td><a class="reference internal" href="./random-access-sequence.html">Random Access Sequence</a></td>
  179. <td>Amortized constant time.</td>
  180. </tr>
  181. <tr><td><a class="reference internal" href="./associative-sequence.html">Associative Sequence</a></td>
  182. <td>Amortized constant time.</td>
  183. </tr>
  184. </tbody>
  185. </table>
  186. </div>
  187. <div class="section" id="id183">
  188. <h3><a class="subsection-title" href="#example" name="example">Example</a></h3>
  189. <pre class="literal-block">
  190. typedef <a href="./range-c.html" class="identifier">range_c</a>&lt;long,10,50&gt; range;
  191. <a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( (<a href="./at.html" class="identifier">at</a>&lt; range, <a href="./int.html" class="identifier">int_</a>&lt;0&gt; &gt;::value), ==, 10 );
  192. <a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( (<a href="./at.html" class="identifier">at</a>&lt; range, <a href="./int.html" class="identifier">int_</a>&lt;10&gt; &gt;::value), ==, 20 );
  193. <a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( (<a href="./at.html" class="identifier">at</a>&lt; range, <a href="./int.html" class="identifier">int_</a>&lt;40&gt; &gt;::value), ==, 50 );
  194. </pre>
  195. <pre class="literal-block">
  196. typedef <a href="./set.html" class="identifier">set</a>&lt; int const,long*,double &gt; s;
  197. <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_same&lt; <a href="./at.html" class="identifier">at</a>&lt;s,char&gt;::type, <a href="./void.html" class="identifier">void_</a> &gt; ));
  198. <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_same&lt; <a href="./at.html" class="identifier">at</a>&lt;s,int&gt;::type, int > ));
  199. </pre>
  200. </div>
  201. <div class="section" id="id184">
  202. <h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3>
  203. <p><a class="reference internal" href="./forward-sequence.html">Forward Sequence</a>, <a class="reference internal" href="./random-access-sequence.html">Random Access Sequence</a>, <a class="reference internal" href="./associative-sequence.html">Associative Sequence</a>, <a class="reference internal" href="./at-c.html">at_c</a>, <a class="reference internal" href="./front.html">front</a>, <a class="reference internal" href="./back.html">back</a></p>
  204. <!-- Sequences/Intrinsic Metafunctions//at_c -->
  205. </div>
  206. </div>
  207. <div class="footer-separator"></div>
  208. <table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./intrinsic-metafunctions.html" class="navigation-link">Prev</a>&nbsp;<a href="./at-c.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group">Back&nbsp;<a href="./at-c.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./intrinsic-metafunctions.html" class="navigation-link">Up</a>&nbsp;<a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td>
  209. <td><div class="copyright-footer"><div class="copyright">Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams</div>
  210. Distributed under the Boost Software License, Version 1.0. (See accompanying
  211. file LICENSE_1_0.txt or copy at <a class="reference external" href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</div></td></tr></table></body>
  212. </html>