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: key_type</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="./is-sequence.html" class="navigation-link">Prev</a> <a href="./order.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./is-sequence.html" class="navigation-link">Back</a> <a href="./order.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./intrinsic-metafunctions.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </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="./key-type.html" class="navigation-link">key_type</a></td> 13</tr></table><div class="header-separator"></div> 14<div class="section" id="key-type"> 15<h1><a class="toc-backref" href="./intrinsic-metafunctions.html#id1439">key_type</a></h1> 16<div class="section" id="id300"> 17<h3><a class="subsection-title" href="#synopsis" name="synopsis">Synopsis</a></h3> 18<pre class="literal-block"> 19template< 20 typename Sequence 21 , typename X 22 > 23struct <a href="./key-type.html" class="identifier">key_type</a> 24{ 25 typedef <em>unspecified</em> type; 26}; 27</pre> 28</div> 29<div class="section" id="id301"> 30<h3><a class="subsection-title" href="#description" name="description">Description</a></h3> 31<p>Returns the <a class="reference internal" href="./associative-sequence.html#key-part">key</a> that would be used to identify <tt class="literal"><span class="pre">X</span></tt> in <tt class="literal"><span class="pre">Sequence</span></tt>.</p> 32</div> 33<div class="section" id="id302"> 34<h3><a class="subsection-title" href="#header" name="header">Header</a></h3> 35<pre class="literal-block"> 36#include <<a href="../../../../boost/mpl/key_type.hpp" class="header">boost/mpl/key_type.hpp</a>> 37</pre> 38</div> 39<div class="section" id="id303"> 40<h3><a class="subsection-title" href="#model-of" name="model-of">Model of</a></h3> 41<p><a class="reference internal" href="./tag-dispatched-metafunction.html">Tag Dispatched Metafunction</a></p> 42</div> 43<div class="section" id="id304"> 44<h3><a class="subsection-title" href="#parameters" name="parameters">Parameters</a></h3> 45<table border="1" class="docutils table"> 46<colgroup> 47<col width="17%" /> 48<col width="30%" /> 49<col width="53%" /> 50</colgroup> 51<thead valign="bottom"> 52<tr><th class="head">Parameter</th> 53<th class="head">Requirement</th> 54<th class="head">Description</th> 55</tr> 56</thead> 57<tbody valign="top"> 58<tr><td><tt class="literal"><span class="pre">Sequence</span></tt></td> 59<td><a class="reference internal" href="./associative-sequence.html">Associative Sequence</a></td> 60<td>A sequence to query.</td> 61</tr> 62<tr><td><tt class="literal"><span class="pre">X</span></tt></td> 63<td>Any type</td> 64<td>The type to get the <a class="reference internal" href="./associative-sequence.html#key-part">key</a> for.</td> 65</tr> 66</tbody> 67</table> 68</div> 69<div class="section" id="id305"> 70<h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3> 71<p>For any <a class="reference internal" href="./associative-sequence.html">Associative Sequence</a> <tt class="literal"><span class="pre">s</span></tt>, iterators <tt class="literal"><span class="pre">pos1</span></tt> and <tt class="literal"><span class="pre">pos2</span></tt> in <tt class="literal"><span class="pre">s</span></tt>, and an 72artibrary type <tt class="literal"><span class="pre">x</span></tt>:</p> 73<pre class="literal-block"> 74typedef <a href="./key-type.html" class="identifier">key_type</a><s,x>::type k; 75</pre> 76<table class="docutils field-list" frame="void" rules="none"> 77<col class="field-name" /> 78<col class="field-body" /> 79<tbody valign="top"> 80<tr class="field"><th class="field-name">Return type:</th><td class="field-body">A type.</td> 81</tr> 82<tr class="field"><th class="field-name">Precondition:</th><td class="field-body"><tt class="literal"><span class="pre">x</span></tt> can be put in <tt class="literal"><span class="pre">s</span></tt>.</td> 83</tr> 84<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><tt class="literal"><span class="pre">k</span></tt> is the <a class="reference internal" href="./associative-sequence.html#key-part">key</a> that would be used to identify <tt class="literal"><span class="pre">x</span></tt> in <tt class="literal"><span class="pre">s</span></tt>.</td> 85</tr> 86<tr class="field"><th class="field-name">Postcondition:</th><td class="field-body">If <tt class="literal"><span class="pre"><a href="./key-type.html" class="identifier">key_type</a><</span> <span class="pre">s,<a href="./deref.html" class="identifier">deref</a><pos1>::type</span> <span class="pre">>::type</span></tt> is identical to 87<tt class="literal"><span class="pre"><a href="./key-type.html" class="identifier">key_type</a><</span> <span class="pre">s,<a href="./deref.html" class="identifier">deref</a><pos2>::type</span> <span class="pre">>::type</span></tt> then <tt class="literal"><span class="pre">pos1</span></tt> is identical to <tt class="literal"><span class="pre">pos2</span></tt>.</td> 88</tr> 89</tbody> 90</table> 91</div> 92<div class="section" id="id306"> 93<h3><a class="subsection-title" href="#complexity" name="complexity">Complexity</a></h3> 94<p>Amortized constant time.</p> 95</div> 96<div class="section" id="id307"> 97<h3><a class="subsection-title" href="#example" name="example">Example</a></h3> 98<pre class="literal-block"> 99typedef <a href="./key-type.html" class="identifier">key_type</a>< <a href="./map.html" class="identifier">map</a><>,<a href="./pair.html" class="identifier">pair</a><int,unsigned> >::type k1; 100typedef <a href="./key-type.html" class="identifier">key_type</a>< <a href="./set.html" class="identifier">set</a><>,<a href="./pair.html" class="identifier">pair</a><int,unsigned> >::type k2; 101 102<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_same< k1,int > )); 103<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_same< k2,<a href="./pair.html" class="identifier">pair</a><int,unsigned> > )); 104</pre> 105</div> 106<div class="section" id="id308"> 107<h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3> 108<p><a class="reference internal" href="./associative-sequence.html">Associative Sequence</a>, <a class="reference internal" href="./value-type.html">value_type</a>, <a class="reference internal" href="./has-key.html">has_key</a>, <a class="reference internal" href="./set.html">set</a>, <a class="reference internal" href="./map.html">map</a></p> 109<!-- Sequences/Intrinsic Metafunctions//order --> 110</div> 111</div> 112 113<div class="footer-separator"></div> 114<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./is-sequence.html" class="navigation-link">Prev</a> <a href="./order.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./is-sequence.html" class="navigation-link">Back</a> <a href="./order.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./intrinsic-metafunctions.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td> 115<td><div class="copyright-footer"><div class="copyright">Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams</div> 116Distributed under the Boost Software License, Version 1.0. (See accompanying 117file 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> 118</html> 119