Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / math / doc / html / math_toolkit / pol_tutorial / what_is_a_policy.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>So Just What is a Policy Anyway?</title>
5 <link rel="stylesheet" href="../../math.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../index.html" title="Math Toolkit 2.11.0">
8 <link rel="up" href="../pol_tutorial.html" title="Policy Tutorial">
9 <link rel="prev" href="../pol_tutorial.html" title="Policy Tutorial">
10 <link rel="next" href="policy_tut_defaults.html" title="Policies Have Sensible Defaults">
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="../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>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="math_toolkit.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
28       is a Policy Anyway?</a>
29 </h3></div></div></div>
30 <p>
31         A policy is a compile-time mechanism for customising the behaviour of a special
32         function, or a statistical distribution. With Policies you can control:
33       </p>
34 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
35 <li class="listitem">
36             What action to take when an error occurs.
37           </li>
38 <li class="listitem">
39             What happens when you call a function that is mathematically undefined
40             (for example, if you ask for the mean of a Cauchy distribution).
41           </li>
42 <li class="listitem">
43             What happens when you ask for a quantile of a discrete distribution.
44           </li>
45 <li class="listitem">
46             Whether the library is allowed to internally promote <code class="computeroutput"><span class="keyword">float</span></code>
47             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>
48             <span class="keyword">double</span></code> in order to improve precision.
49           </li>
50 <li class="listitem">
51             What precision to use when calculating the result.
52           </li>
53 </ul></div>
54 <p>
55         Some of these policies could arguably be run-time variables, but then we
56         couldn't use compile-time dispatch internally to select the best evaluation
57         method for the given policies.
58       </p>
59 <p>
60         For this reason a Policy is a <span class="emphasis"><em>type</em></span>: in fact it's an
61         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">&lt;&gt;</span></code>. This class is just a compile-time-container
62         of user-selected policies (sometimes called a type-list).
63       </p>
64 <p>
65         Over a dozen <a class="link" href="policy_tut_defaults.html" title="Policies Have Sensible Defaults">policy
66         defaults</a> are provided, so most of the time you can ignore the policy
67         framework, but you can overwrite the defaults with your own policies to give
68         detailed control, for example:
69       </p>
70 <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>
71
72 <span class="comment">// Define a policy that sets ::errno on overflow,</span>
73 <span class="comment">// and does not promote double to long double internally,</span>
74 <span class="comment">// and only aims for precision of only 3 decimal digits,</span>
75 <span class="comment">// to an error-handling policy, usually to trade precision for speed:</span>
76
77 <span class="keyword">typedef</span> <span class="identifier">policy</span>
78 <span class="special">&lt;</span>
79   <span class="identifier">domain_error</span><span class="special">&lt;</span><span class="identifier">errno_on_error</span><span class="special">&gt;,</span>
80   <span class="identifier">promote_double</span><span class="special">&lt;</span><span class="keyword">false</span><span class="special">&gt;,</span>
81   <span class="identifier">digits10</span><span class="special">&lt;</span><span class="number">3</span><span class="special">&gt;</span>
82 <span class="special">&gt;</span> <span class="identifier">my_policy</span><span class="special">;</span>
83 </pre>
84 </div>
85 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
86 <td align="left"></td>
87 <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2019 Nikhar
88       Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
89       Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
90       R&#229;de, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
91       Daryle Walker and Xiaogang Zhang<p>
92         Distributed under the Boost Software License, Version 1.0. (See accompanying
93         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>)
94       </p>
95 </div></td>
96 </tr></table>
97 <hr>
98 <div class="spirit-nav">
99 <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>
100 </div>
101 </body>
102 </html>