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.77.1">
7 <link rel=
"home" href=
"../../index.html" title=
"Math Toolkit 2.5.1">
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">
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>
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>
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>
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:
34 <div class=
"itemizedlist"><ul class=
"itemizedlist" style=
"list-style-type: disc; ">
36 What action to take when an error occurs.
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).
43 What happens when you ask for a quantile of a discrete distribution.
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.
51 What precision to use when calculating the result.
55 Some of these policies could arguably be runtime variables, but then we couldn't
56 use compile-time dispatch internally to select the best evaluation method
57 for the given policies.
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"><></span></code>. This class is just a compile-time-container
62 of user-selected policies (sometimes called a type-list):
64 <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>
65 <span class=
"comment">//
</span>
66 <span class=
"comment">// Define a policy that sets ::errno on overflow, and does
</span>
67 <span class=
"comment">// not promote double to long double internally:
</span>
68 <span class=
"comment">//
</span>
69 <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>
72 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
73 <td align=
"left"></td>
74 <td align=
"right"><div class=
"copyright-footer">Copyright
© 2006-
2010,
2012-
2014 Nikhar Agrawal,
75 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
76 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R
åde, Gautam Sewani,
77 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang
<p>
78 Distributed under the Boost Software License, Version
1.0. (See accompanying
79 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>)
84 <div class=
"spirit-nav">
85 <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>