| <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="../math.css" type="text/css"> |
| <meta name="generator" content="DocBook XSL Stylesheets V1.77.1"> |
| <link rel="home" href="../index.html" title="Math Toolkit 2.2.0"> |
| <link rel="up" href="../using_udt.html" title="Chapter 13. Use with User-Defined Floating-Point Types - Boost.Multiprecision and others"> |
| <link rel="prev" href="dist_concept.html" title="Conceptual Requirements for Distribution Types"> |
| <link rel="next" href="../policy.html" title="Chapter 14. Policies: Controlling Precision, Error Handling etc"> |
| </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"> |
| <div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| <a name="math_toolkit.archetypes"></a><a class="link" href="archetypes.html" title="Conceptual Archetypes for Reals and Distributions">Conceptual Archetypes for Reals |
| and Distributions</a> |
| </h2></div></div></div> |
| <p> |
| There are a few concept archetypes available: |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| <li class="listitem"> |
| Real concept for floating-point types. |
| </li> |
| <li class="listitem"> |
| distribution Concept for statistical distributions. |
| </li> |
| </ul></div> |
| <h6> |
| <a name="math_toolkit.archetypes.h0"></a> |
| <span class="phrase"><a name="math_toolkit.archetypes.real_concept"></a></span><a class="link" href="archetypes.html#math_toolkit.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> |
| <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</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">></span></pre> |
| <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> |
| <h3> |
| <a name="math_toolkit.archetypes.h1"></a> |
| <span class="phrase"><a name="math_toolkit.archetypes.testing_the_real_concept"></a></span><a class="link" href="archetypes.html#math_toolkit.archetypes.testing_the_real_concept">Testing |
| the real concept</a> |
| </h3> |
| <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> |
| <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</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">></span></pre> |
| <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<> 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="high_precision/use_ntl.html" title="Using NTL 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> |
| <h3> |
| <a name="math_toolkit.archetypes.h2"></a> |
| <span class="phrase"><a name="math_toolkit.archetypes.distribution_concept"></a></span><a class="link" href="archetypes.html#math_toolkit.archetypes.distribution_concept">Distribution |
| Concept</a> |
| </h3> |
| <p> |
| Distribution Concept models statistical distributions. |
| </p> |
| <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</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">></span></pre> |
| <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"><</span><span class="keyword">class</span> <span class="identifier">RealType</span><span class="special">></span> |
| <span class="keyword">class</span> <span class="identifier">distribution_archetype</span><span class="special">;</span> |
| |
| <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Distribution</span><span class="special">></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> |
| <h3> |
| <a name="math_toolkit.archetypes.h3"></a> |
| <span class="phrase"><a name="math_toolkit.archetypes.testing_the_distribution_concept"></a></span><a class="link" href="archetypes.html#math_toolkit.archetypes.testing_the_distribution_concept">Testing |
| the distribution concept</a> |
| </h3> |
| <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 © 2006-2010, 2012-2014 Nikhar Agrawal, |
| Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert |
| Holin, Bruno Lalande, John Maddock, Johan Råde, Gautam Sewani, Benjamin Sobotta, |
| Thijs van den Berg, Daryle Walker and Xiaogang Zhang<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> |