1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>noncopyable</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="noinit_adaptor.html" title="noinit_adaptor"> 10<link rel="next" href="null_deleter.html" title="null_deleter"> 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="noinit_adaptor.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="null_deleter.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.noncopyable"></a><a class="link" href="noncopyable.html" title="noncopyable">noncopyable</a> 28</h2></div></div></div> 29<div class="toc"><dl class="toc"><dt><span class="section"><a href="noncopyable.html#core.noncopyable.header_boost_core_noncopyable_hp">Header 30 <boost/core/noncopyable.hpp></a></span></dt></dl></div> 31<div class="simplesect"> 32<div class="titlepage"><div><div><h3 class="title"> 33<a name="idm45312827248720"></a>Authors</h3></div></div></div> 34<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 35 Dave Abrahams 36 </li></ul></div> 37</div> 38<div class="section"> 39<div class="titlepage"><div><div><h3 class="title"> 40<a name="core.noncopyable.header_boost_core_noncopyable_hp"></a><a class="link" href="noncopyable.html#core.noncopyable.header_boost_core_noncopyable_hp" title="Header <boost/core/noncopyable.hpp>">Header 41 <boost/core/noncopyable.hpp></a> 42</h3></div></div></div> 43<p> 44 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">noncopyable</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 45 defines the class <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span></code>. It is intended to be used 46 as a private base class. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span></code> 47 has private (under C++03) or deleted (under C++11) copy constructor and a 48 copy assignment operator and can't be copied or assigned; a class that derives 49 from it inherits these properties. 50 </p> 51<p> 52 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span></code> was originally contributed 53 by Dave Abrahams. 54 </p> 55<div class="section"> 56<div class="titlepage"><div><div><h4 class="title"> 57<a name="core.noncopyable.header_boost_core_noncopyable_hp.synopsis"></a><a class="link" href="noncopyable.html#core.noncopyable.header_boost_core_noncopyable_hp.synopsis" title="Synopsis">Synopsis</a> 58</h4></div></div></div> 59<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> 60<span class="special">{</span> 61 <span class="keyword">class</span> <span class="identifier">noncopyable</span><span class="special">;</span> 62<span class="special">}</span> 63</pre> 64</div> 65<div class="section"> 66<div class="titlepage"><div><div><h4 class="title"> 67<a name="core.noncopyable.header_boost_core_noncopyable_hp.example"></a><a class="link" href="noncopyable.html#core.noncopyable.header_boost_core_noncopyable_hp.example" title="Example">Example</a> 68</h4></div></div></div> 69<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">noncopyable</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 70 71<span class="keyword">class</span> <span class="identifier">X</span><span class="special">:</span> <span class="keyword">private</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span> 72<span class="special">{</span> 73<span class="special">};</span> 74</pre> 75</div> 76<div class="section"> 77<div class="titlepage"><div><div><h4 class="title"> 78<a name="core.noncopyable.header_boost_core_noncopyable_hp.rationale"></a><a class="link" href="noncopyable.html#core.noncopyable.header_boost_core_noncopyable_hp.rationale" title="Rationale">Rationale</a> 79</h4></div></div></div> 80<p> 81 Class noncopyable has protected constructor and destructor members to emphasize 82 that it is to be used only as a base class. Dave Abrahams notes concern 83 about the effect on compiler optimization of adding (even trivial inline) 84 destructor declarations. He says: 85 </p> 86<p> 87 <span class="quote">“<span class="quote">Probably this concern is misplaced, because <code class="computeroutput"><span class="identifier">noncopyable</span></code> 88 will be used mostly for classes which own resources and thus have non-trivial 89 destruction semantics.</span>”</span> 90 </p> 91<p> 92 With C++2011, using an optimized and trivial constructor and similar destructor 93 can be enforced by declaring both and marking them <code class="computeroutput"><span class="keyword">default</span></code>. 94 This is done in the current implementation. 95 </p> 96</div> 97</div> 98</div> 99<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 100<td align="left"></td> 101<td align="right"><div class="copyright-footer">Copyright © 2014 Peter Dimov<br>Copyright © 2014 Glen Fernandes<br>Copyright © 2014 Andrey Semashev<p> 102 Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost 103 Software License, Version 1.0</a>. 104 </p> 105</div></td> 106</tr></table> 107<hr> 108<div class="spirit-nav"> 109<a accesskey="p" href="noinit_adaptor.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="null_deleter.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 110</div> 111</body> 112</html> 113