blob: d32535cbe55ea96da14de0de67ff3f45cef2acf9 [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Conceptual Archetypes for Reals and Distributions</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="../using_udt.html" title="Use with User-Defined Floating-Point Types">
<link rel="prev" href="dist_concept.html" title="Conceptual Requirements for Distribution Types">
<link rel="next" href="../policy.html" title="Policies">
</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="dist_concept.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../using_udt.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.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="math_toolkit.using_udt.archetypes"></a><a class="link" href="archetypes.html" title="Conceptual Archetypes for Reals and Distributions">Conceptual Archetypes
for Reals and Distributions</a>
</h3></div></div></div>
<p>
There are a few concept archetypes available:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
Real concept for floating-point types.
</li>
<li>
distribution Concept for statistical distributions.
</li>
</ul></div>
<a name="math_toolkit.using_udt.archetypes.real_concept"></a><h6>
<a name="id1411511"></a>
<a class="link" href="archetypes.html#math_toolkit.using_udt.archetypes.real_concept">Real concept</a>
</h6>
<p>
<code class="computeroutput"><span class="identifier">std_real_concept</span></code> is an archetype
for theReal types, including the built-in float, double, long double.
</p>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concepts</span><span class="special">/</span><span class="identifier">std_real_concept</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<p>
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span>
<span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
<span class="keyword">namespace</span> <span class="identifier">concepts</span>
<span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">std_real_concept</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">}}</span> <span class="comment">// namespaces
</span></pre>
<p>
The main purpose in providing this type is to verify that standard library
functions are found via a using declaration - bringing those functions into
the current scope - and not just because they happen to be in global scope.
</p>
<p>
In order to ensure that a call to say <code class="computeroutput"><span class="identifier">pow</span></code>
can be found either via argument dependent lookup, or failing that then in
the std namespace: all calls to standard library functions are unqualified,
with the std:: versions found via a <code class="computeroutput"><span class="keyword">using</span></code>
declaration to make them visible in the current scope. Unfortunately it's
all to easy to forget the <code class="computeroutput"><span class="keyword">using</span></code>
declaration, and call the double version of the function that happens to
be in the global scope by mistake.
</p>
<p>
For example if the code calls ::pow rather than std::pow, the code will cleanly
compile, but truncation of long doubles to double will cause a significant
loss of precision. In contrast a template instantiated with std_real_concept
will <span class="bold"><strong>only</strong></span> compile if the all the standard
library functions used have been brought into the current scope with a using
declaration.
</p>
<a name="math_toolkit.using_udt.archetypes.testing_the_real_concept"></a><h4>
<a name="id1411690"></a>
<a class="link" href="archetypes.html#math_toolkit.using_udt.archetypes.testing_the_real_concept">Testing
the real concept</a>
</h4>
<p>
There is a test program <a href="../../../../../test/std_real_concept_check.cpp" target="_top">libs/math/test/std_real_concept_check.cpp</a>
that instantiates every template in this library with type <code class="computeroutput"><span class="identifier">std_real_concept</span></code> to verify its usage of
standard library functions.
</p>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">concepts</span><span class="special">/</span><span class="identifier">real_concept</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<p>
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span>
<span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
<span class="keyword">namespace</span> <span class="identifier">concepts</span><span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">real_concept</span><span class="special">;</span>
<span class="special">}}}</span> <span class="comment">// namespaces
</span></pre>
<p>
<code class="computeroutput"><span class="identifier">real_concept</span></code> is an archetype
for <a class="link" href="concepts.html" title="Conceptual Requirements for Real Number Types">user defined real types</a>,
it declares its standard library functions in its own namespace: these will
only be found if they are called unqualified allowing argument dependent
lookup to locate them. In addition this type is useable at runtime: this
allows code that would not otherwise be exercised by the built-in floating
point types to be tested. There is no std::numeric_limits&lt;&gt; support
for this type, since numeric_limits is not a conceptual requirement for
<a class="link" href="concepts.html" title="Conceptual Requirements for Real Number Types">RealType</a>s.
</p>
<p>
NTL RR is an example of a type meeting the requirements that this type models,
but note that use of a thin wrapper class is required: refer to <a class="link" href="use_ntl.html" title="Using With NTL - a High-Precision Floating-Point Library">"Using
With NTL - a High-Precision Floating-Point Library"</a>.
</p>
<p>
There is no specific test case for type <code class="computeroutput"><span class="identifier">real_concept</span></code>,
instead, since this type is usable at runtime, each individual test case
as well as testing <code class="computeroutput"><span class="keyword">float</span></code>, <code class="computeroutput"><span class="keyword">double</span></code> and <code class="computeroutput"><span class="keyword">long</span>
<span class="keyword">double</span></code>, also tests <code class="computeroutput"><span class="identifier">real_concept</span></code>.
</p>
<a name="math_toolkit.using_udt.archetypes.distribution_concept"></a><h4>
<a name="id1411912"></a>
<a class="link" href="archetypes.html#math_toolkit.using_udt.archetypes.distribution_concept">Distribution
Concept</a>
</h4>
<p>
Distribution Concept models statistical distributions.
</p>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">concepts</span><span class="special">/</span><span class="identifier">distribution</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<p>
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span>
<span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
<span class="keyword">namespace</span> <span class="identifier">concepts</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RealType</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">distribution_archetype</span><span class="special">;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Distribution</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">DistributionConcept</span><span class="special">;</span>
<span class="special">}}}</span> <span class="comment">// namespaces
</span></pre>
<p>
The class template <code class="computeroutput"><span class="identifier">distribution_archetype</span></code>
is a model of the <a class="link" href="dist_concept.html" title="Conceptual Requirements for Distribution Types">Distribution
concept</a>.
</p>
<p>
The class template <code class="computeroutput"><span class="identifier">DistributionConcept</span></code>
is a <a href="../../../../../../../libs/concept_check/index.html" target="_top">concept checking
class</a> for distribution types.
</p>
<a name="math_toolkit.using_udt.archetypes.testing_the_distribution_concept"></a><h4>
<a name="id1412138"></a>
<a class="link" href="archetypes.html#math_toolkit.using_udt.archetypes.testing_the_distribution_concept">Testing
the distribution concept</a>
</h4>
<p>
The test program <a href="../../../../../test/compile_test/distribution_concept_check.cpp" target="_top">distribution_concept_check.cpp</a>
is responsible for using <code class="computeroutput"><span class="identifier">DistributionConcept</span></code>
to verify that all the distributions in this library conform to the <a class="link" href="dist_concept.html" title="Conceptual Requirements for Distribution Types">Distribution concept</a>.
</p>
<p>
The class template <code class="computeroutput"><span class="identifier">DistributionConcept</span></code>
verifies the existence (but not proper function) of the non-member accessors
required by the <a class="link" href="dist_concept.html" title="Conceptual Requirements for Distribution Types">Distribution
concept</a>. These are checked by calls like
</p>
<p>
v = pdf(dist, x); // (Result v is ignored).
</p>
<p>
And in addition, those that accept two arguments do the right thing when
the arguments are of different types (the result type is always the same
as the distribution's value_type). (This is implemented by some additional
forwarding-functions in derived_accessors.hpp, so that there is no need for
any code changes. Likewise boilerplate versions of the hazard/chf/coefficient_of_variation
functions are implemented in there too.)
</p>
</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 &#169; 2006 , 2007, 2008, 2009, 2010 John Maddock, Paul A. Bristow,
Hubert Holin, Xiaogang Zhang, Bruno Lalande, Johan R&#229;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="dist_concept.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../using_udt.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.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>