1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5<title>Synopsis</title> 6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css"> 7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> 9<link rel="up" href="../conversion.html" title="Chapter 11. The Conversion Library 1.7"> 10<link rel="prev" href="polymorphic_casts.html" title="Polymorphic casts"> 11<link rel="next" href="history.html" title="History"> 12</head> 13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 14<table cellpadding="2" width="100%"><tr> 15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td> 16<td align="center"><a href="../../../index.html">Home</a></td> 17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> 18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 20<td align="center"><a href="../../../more/index.htm">More</a></td> 21</tr></table> 22<hr> 23<div class="spirit-nav"> 24<a accesskey="p" href="polymorphic_casts.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../conversion.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="history.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 25</div> 26<div class="section"> 27<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 28<a name="conversion.synopsis"></a><a class="link" href="synopsis.html" title="Synopsis">Synopsis</a> 29</h2></div></div></div> 30<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> 31 32<span class="comment">// Throws: std::bad_cast if ( dynamic_cast<Derived>(x) == 0 )</span> 33<span class="comment">// Returns: dynamic_cast<Derived>(x)</span> 34<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Derived</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Base</span><span class="special">></span> 35<span class="keyword">inline</span> <span class="identifier">Derived</span> <span class="identifier">polymorphic_cast</span><span class="special">(</span><span class="identifier">Base</span><span class="special">*</span> <span class="identifier">x</span><span class="special">);</span> 36 37<span class="comment">// Effects: assert( dynamic_cast<Derived>(x) == x );</span> 38<span class="comment">// Returns: static_cast<Derived>(x)</span> 39<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Derived</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Base</span><span class="special">></span> 40<span class="keyword">inline</span> <span class="identifier">Derived</span> <span class="identifier">polymorphic_downcast</span><span class="special">(</span><span class="identifier">Base</span><span class="special">*</span> <span class="identifier">x</span><span class="special">);</span> 41 42<span class="comment">// Effects: assert( dynamic_cast<Derived>(&x) == &x );</span> 43<span class="comment">// Returns: static_cast<Derived>(x)</span> 44<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Derived</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Base</span><span class="special">></span> 45<span class="keyword">inline</span> <span class="identifier">Derived</span> <span class="identifier">polymorphic_downcast</span><span class="special">(</span><span class="identifier">Base</span><span class="special">&</span> <span class="identifier">x</span><span class="special">);</span> 46 47<span class="comment">// Throws: std::bad_cast if ( dynamic_pointer_cast<Derived>(x) == 0 )</span> 48<span class="comment">// Returns: dynamic_pointer_cast<Derived>(x)</span> 49<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Derived</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Base</span><span class="special">></span> 50<span class="keyword">inline</span> <span class="keyword">auto</span> <span class="identifier">polymorphic_pointer_cast</span><span class="special">(</span><span class="identifier">Base</span> <span class="identifier">x</span><span class="special">);</span> 51 52<span class="comment">// Effects: assert( dynamic_pointer_cast<Derived>(x) == x );</span> 53<span class="comment">// Returns: static_pointer_cast<Derived>(x)</span> 54<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Derived</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Base</span><span class="special">></span> 55<span class="keyword">inline</span> <span class="keyword">auto</span> <span class="identifier">polymorphic_pointer_downcast</span><span class="special">(</span><span class="identifier">Base</span> <span class="identifier">x</span><span class="special">);</span> 56 57<span class="special">}</span> 58</pre> 59</div> 60<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 61<td align="left"></td> 62<td align="right"><div class="copyright-footer">Copyright © 2001 Beman Dawes<br>Copyright © 2014-2020 Antony Polukhin<p> 63 Distributed under the Boost Software License, Version 1.0. (See accompanying 64 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>) 65 </p> 66</div></td> 67</tr></table> 68<hr> 69<div class="spirit-nav"> 70<a accesskey="p" href="polymorphic_casts.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../conversion.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="history.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 71</div> 72</body> 73</html> 74