]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <html> |
2 | <head> | |
3 | <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> | |
4 | <title>An Example that Omits Destructor Calls For Types with Trivial Destructors</title> | |
5 | <link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css"> | |
6 | <meta name="generator" content="DocBook XSL Stylesheets V1.77.1"> | |
7 | <link rel="home" href="../../index.html" title="Chapter 1. Boost.TypeTraits"> | |
8 | <link rel="up" href="../examples.html" title="Examples"> | |
9 | <link rel="prev" href="fill.html" title="An Optimised Version of std::fill"> | |
10 | <link rel="next" href="iter.html" title="An improved Version of std::iter_swap"> | |
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="fill.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../examples.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="iter.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> | |
24 | </div> | |
25 | <div class="section"> | |
26 | <div class="titlepage"><div><div><h3 class="title"> | |
27 | <a name="boost_typetraits.examples.destruct"></a><a class="link" href="destruct.html" title="An Example that Omits Destructor Calls For Types with Trivial Destructors">An Example that Omits | |
28 | Destructor Calls For Types with Trivial Destructors</a> | |
29 | </h3></div></div></div> | |
30 | <p> | |
31 | Demonstrates a simple algorithm that uses <code class="computeroutput"><span class="identifier">__has_trivial_destruct</span></code> | |
32 | to determine whether to destructors need to be called (see <a href="../../../../examples/trivial_destructor_example.cpp" target="_top">trivial_destructor_example.cpp</a>): | |
33 | </p> | |
34 | <pre class="programlisting"><span class="comment">//</span> | |
35 | <span class="comment">// algorithm destroy_array:</span> | |
36 | <span class="comment">// The reverse of std::unitialized_copy, takes a block of</span> | |
37 | <span class="comment">// initialized memory and calls destructors on all objects therein.</span> | |
38 | <span class="comment">//</span> | |
39 | ||
40 | <span class="keyword">namespace</span> <span class="identifier">detail</span><span class="special">{</span> | |
41 | ||
42 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> | |
43 | <span class="keyword">void</span> <span class="identifier">do_destroy_array</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">last</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><a class="link" href="../reference/integral_constant.html" title="integral_constant">false_type</a><span class="special">&)</span> | |
44 | <span class="special">{</span> | |
45 | <span class="keyword">while</span><span class="special">(</span><span class="identifier">first</span> <span class="special">!=</span> <span class="identifier">last</span><span class="special">)</span> | |
46 | <span class="special">{</span> | |
47 | <span class="identifier">first</span><span class="special">->~</span><span class="identifier">T</span><span class="special">();</span> | |
48 | <span class="special">++</span><span class="identifier">first</span><span class="special">;</span> | |
49 | <span class="special">}</span> | |
50 | <span class="special">}</span> | |
51 | ||
52 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> | |
53 | <span class="keyword">inline</span> <span class="keyword">void</span> <span class="identifier">do_destroy_array</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">last</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><a class="link" href="../reference/integral_constant.html" title="integral_constant">true_type</a><span class="special">&)</span> | |
54 | <span class="special">{</span> | |
55 | <span class="special">}</span> | |
56 | ||
57 | <span class="special">}</span> <span class="comment">// namespace detail</span> | |
58 | ||
59 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> | |
60 | <span class="keyword">inline</span> <span class="keyword">void</span> <span class="identifier">destroy_array</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="identifier">p1</span><span class="special">,</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">p2</span><span class="special">)</span> | |
61 | <span class="special">{</span> | |
62 | <span class="identifier">detail</span><span class="special">::</span><span class="identifier">do_destroy_array</span><span class="special">(</span><span class="identifier">p1</span><span class="special">,</span> <span class="identifier">p2</span><span class="special">,</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><a class="link" href="../reference/has_trivial_destructor.html" title="has_trivial_destructor">has_trivial_destructor</a><span class="special"><</span><span class="identifier">T</span><span class="special">>());</span> | |
63 | <span class="special">}</span> | |
64 | </pre> | |
65 | </div> | |
66 | <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> | |
67 | <td align="left"></td> | |
68 | <td align="right"><div class="copyright-footer">Copyright © 2000, 2011 Adobe Systems Inc, David Abrahams, | |
69 | Frederic Bron, Steve Cleary, Beman Dawes, Aleksey Gurtovoy, Howard Hinnant, | |
70 | Jesse Jones, Mat Marcus, Itay Maman, John Maddock, Alexander Nasonov, Thorsten | |
71 | Ottosen, Roman Perepelitsa, Robert Ramey, Jeremy Siek, Robert Stewart and Steven | |
72 | Watanabe<p> | |
73 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
74 | file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) | |
75 | </p> | |
76 | </div></td> | |
77 | </tr></table> | |
78 | <hr> | |
79 | <div class="spirit-nav"> | |
80 | <a accesskey="p" href="fill.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../examples.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="iter.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> | |
81 | </div> | |
82 | </body> | |
83 | </html> |