<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <title>So Just What is a Policy Anyway?</title> <link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.74.0"> <link rel="home" href="../../../index.html" title="Math Toolkit"> <link rel="up" href="../pol_tutorial.html" title="Policy Tutorial"> <link rel="prev" href="../pol_tutorial.html" title="Policy Tutorial"> <link rel="next" href="policy_tut_defaults.html" title="Policies Have Sensible Defaults"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <table cellpadding="2" width="100%"><tr> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> <td align="center"><a href="../../../../../../../../index.html">Home</a></td> <td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> <td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="../pol_tutorial.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../pol_tutorial.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="policy_tut_defaults.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> </div> <div class="section" lang="en"> <div class="titlepage"><div><div><h4 class="title"> <a name="math_toolkit.policy.pol_tutorial.what_is_a_policy"></a><a class="link" href="what_is_a_policy.html" title="So Just What is a Policy Anyway?"> So Just What is a Policy Anyway?</a> </h4></div></div></div> <p> A policy is a compile-time mechanism for customising the behaviour of a special function, or a statistical distribution. With Policies you can control: </p> <div class="itemizedlist"><ul type="disc"> <li> What action to take when an error occurs. </li> <li> What happens when you call a function that is mathematically undefined (for example if you ask for the mean of a Cauchy distribution). </li> <li> What happens when you ask for a quantile of a discrete distribution. </li> <li> Whether the library is allowed to internally promote <code class="computeroutput"><span class="keyword">float</span></code> to <code class="computeroutput"><span class="keyword">double</span></code> and <code class="computeroutput"><span class="keyword">double</span></code> to <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code> in order to improve precision. </li> <li> What precision to use when calculating the result. </li> </ul></div> <p> Some of these policies could arguably be runtime variables, but then we couldn't use compile-time dispatch internally to select the best evaluation method for the given policies. </p> <p> For this reason a Policy is a <span class="emphasis"><em>type</em></span>: in fact it's an instance of the class template <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">policy</span><span class="special"><></span></code>. This class is just a compile-time-container of user-selected policies (sometimes called a type-list): </p> <pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">;</span> <span class="comment">// </span><span class="comment">// Define a policy that sets ::errno on overflow, and does </span><span class="comment">// not promote double to long double internally: </span><span class="comment">// </span><span class="keyword">typedef</span> <span class="identifier">policy</span><span class="special"><</span><span class="identifier">domain_error</span><span class="special"><</span><span class="identifier">errno_on_error</span><span class="special">>,</span> <span class="identifier">promote_double</span><span class="special"><</span><span class="keyword">false</span><span class="special">></span> <span class="special">></span> <span class="identifier">mypolicy</span><span class="special">;</span> </pre> </div> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <td align="left"></td> <td align="right"><div class="copyright-footer">Copyright © 2006 , 2007, 2008, 2009 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno Lalande, Johan Råde, Gautam Sewani and Thijs van den Berg<p> Distributed under the Boost Software License, Version 1.0. (See accompanying 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>) </p> </div></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="../pol_tutorial.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../pol_tutorial.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="policy_tut_defaults.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> </div> </body> </html>