1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>addressof</title> 5<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../index.html" title="Chapter 1. Boost.Core"> 8<link rel="up" href="../index.html" title="Chapter 1. Boost.Core"> 9<link rel="prev" href="../index.html" title="Chapter 1. Boost.Core"> 10<link rel="next" href="allocator_access.html" title="Allocator Access"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="../index.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="allocator_access.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 27<a name="core.addressof"></a><a class="link" href="addressof.html" title="addressof">addressof</a> 28</h2></div></div></div> 29<div class="toc"><dl class="toc"><dt><span class="section"><a href="addressof.html#core.addressof.header_boost_core_addressof_hpp">Header 30 <boost/core/addressof.hpp></a></span></dt></dl></div> 31<div class="simplesect"> 32<div class="titlepage"><div><div><h3 class="title"> 33<a name="idm45312833732480"></a>Authors</h3></div></div></div> 34<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 35<li class="listitem"> 36 Brad King 37 </li> 38<li class="listitem"> 39 Douglas Gregor 40 </li> 41<li class="listitem"> 42 Peter Dimov 43 </li> 44<li class="listitem"> 45 Glen Fernandes 46 </li> 47</ul></div> 48</div> 49<div class="section"> 50<div class="titlepage"><div><div><h3 class="title"> 51<a name="core.addressof.header_boost_core_addressof_hpp"></a><a class="link" href="addressof.html#core.addressof.header_boost_core_addressof_hpp" title="Header <boost/core/addressof.hpp>">Header 52 <boost/core/addressof.hpp></a> 53</h3></div></div></div> 54<p> 55 The header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">addressof</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 56 defines the function template <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span></code>. 57 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code> returns 58 the address of <code class="computeroutput"><span class="identifier">x</span></code>. Ordinarily, 59 this address can be obtained by <code class="computeroutput"><span class="special">&</span><span class="identifier">x</span></code>, but the unary <code class="computeroutput"><span class="special">&</span></code> 60 operator can be overloaded. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span></code> 61 avoids calling used-defined <code class="computeroutput"><span class="keyword">operator</span><span class="special">&()</span></code>. 62 </p> 63<p> 64 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span></code> was originally contributed by 65 Brad King based on ideas from discussion with Doug Gregor. 66 </p> 67<div class="section"> 68<div class="titlepage"><div><div><h4 class="title"> 69<a name="core.addressof.header_boost_core_addressof_hpp.synopsis"></a><a class="link" href="addressof.html#core.addressof.header_boost_core_addressof_hpp.synopsis" title="Synopsis">Synopsis</a> 70</h4></div></div></div> 71<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> 72<span class="special">{</span> 73 <span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">addressof</span><span class="special">(</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">x</span> <span class="special">);</span> 74<span class="special">}</span> 75</pre> 76</div> 77<div class="section"> 78<div class="titlepage"><div><div><h4 class="title"> 79<a name="core.addressof.header_boost_core_addressof_hpp.example"></a><a class="link" href="addressof.html#core.addressof.header_boost_core_addressof_hpp.example" title="Example">Example</a> 80</h4></div></div></div> 81<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">addressof</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 82 83<span class="keyword">struct</span> <span class="identifier">useless_type</span> <span class="special">{</span> <span class="special">};</span> 84 85<span class="keyword">class</span> <span class="identifier">nonaddressable</span> <span class="special">{</span> 86 <span class="identifier">useless_type</span> <span class="keyword">operator</span><span class="special">&()</span> <span class="keyword">const</span><span class="special">;</span> 87<span class="special">};</span> 88 89<span class="keyword">void</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">{</span> 90 <span class="identifier">nonaddressable</span> <span class="identifier">x</span><span class="special">;</span> 91 <span class="identifier">nonaddressable</span><span class="special">*</span> <span class="identifier">xp</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span> 92 <span class="comment">// nonaddressable* xpe = &x; /* error */</span> 93<span class="special">}</span> 94</pre> 95</div> 96<div class="section"> 97<div class="titlepage"><div><div><h4 class="title"> 98<a name="core.addressof.header_boost_core_addressof_hpp.notes"></a><a class="link" href="addressof.html#core.addressof.header_boost_core_addressof_hpp.notes" title="Notes">Notes</a> 99</h4></div></div></div> 100<p> 101 In C++11 and above, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span></code> 102 is conditionally <code class="computeroutput"><span class="keyword">constexpr</span></code> 103 when possible. This is indicated by <code class="computeroutput"><span class="identifier">BOOST_CORE_NO_CONSTEXPR_ADDRESSOF</span></code> 104 not being defined. 105 </p> 106<p> 107 With supported compilers, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">addressof</span></code> 108 is always <code class="computeroutput"><span class="keyword">constexpr</span></code> by leveraging 109 compiler intrinsics. This is indicated by <code class="computeroutput"><span class="identifier">BOOST_CORE_HAS_BUILTIN_ADDRESSOF</span></code> 110 being defined. 111 </p> 112</div> 113</div> 114</div> 115<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 116<td align="left"></td> 117<td align="right"><div class="copyright-footer">Copyright © 2014 Peter Dimov<br>Copyright © 2014 Glen Fernandes<br>Copyright © 2014 Andrey Semashev<p> 118 Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost 119 Software License, Version 1.0</a>. 120 </p> 121</div></td> 122</tr></table> 123<hr> 124<div class="spirit-nav"> 125<a accesskey="p" href="../index.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="allocator_access.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 126</div> 127</body> 128</html> 129