123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
- <title>Pending Issues</title>
- <link rel="stylesheet" href="boostbook.css" type="text/css">
- <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
- <link rel="home" href="index.html" title="Safe Numerics">
- <link rel="up" href="index.html" title="Safe Numerics">
- <link rel="prev" href="rationale.html" title="Rationale and FAQ">
- <link rel="next" href="acknowledgements.html" title="Acknowledgements">
- </head>
- <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
- <table cellpadding="2" width="100%"><tr>
- <td valign="top"><img href="index.html" height="164px" src="pre-boost.jpg" alt="Library Documentation Index"></td>
- <td><h2>Safe Numerics</h2></td>
- </tr></table>
- <div class="spirit-nav">
- <a accesskey="p" href="rationale.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="acknowledgements.html"><img src="images/next.png" alt="Next"></a>
- </div>
- <div class="section">
- <div class="titlepage"><div><div><h2 class="title" style="clear: both">
- <a name="safe_numerics.pending_issues"></a>Pending Issues</h2></div></div></div>
- <div class="toc"><dl class="toc">
- <dt><span class="section"><a href="pending_issues.html#idm130201646352"><code class="computeroutput">safe_base</code> Only Works for Scalar Types</a></span></dt>
- <dt><span class="section"><a href="pending_issues.html#idm130201605904">Concepts are Defined but Not Enforced.</a></span></dt>
- <dt><span class="section"><a href="pending_issues.html#idm130201600176">Other Pending Issues</a></span></dt>
- </dl></div>
- <p>The library is under development. There are a number of issues still
- pending.</p>
- <div class="section">
- <div class="titlepage"><div><div><h3 class="title">
- <a name="idm130201646352"></a><code class="computeroutput">safe_base</code> Only Works for Scalar Types</h3></div></div></div>
- <p>The following is paraphrased from an issue raised by Andrzej
- Krzemieński as a <a href="https://github.com/robertramey/safe_numerics/issues/44" target="_top">github
- issue</a>. It touches upon fundamental ideas behind the library and
- how these ideas as the implementation of the library collided with
- reality.</p>
- <p><span class="quote">“<span class="quote">In the current implementation safe<T> will only work
- with T being a C++ scalar type. Therefore making a general type
- requirements that say what operations are allowed is superfluous, and
- confusing (because it implies that safe<> is more
- generic.</span>”</span></p>
- <p>When I started out, It became clear that I wanted "safe" types to
- look like "numeric" types. It also became clear pretty soon that there was
- going to be significant template meta-programming in the implementation.
- Normal type traits like std::is_integer are defined in the std namespace
- and one is discouraged from extending it. Also I needed some compile time
- "max" and "lowest" values. This lead me to base the design on
- std::numeric_limits. But std::numeric limits is inherently extensible to
- any "numeric" type. For example, money is a numeric type but not an
- intrinsic types. So it seemed that I needed to define a "numeric" concept
- which required that there be an implementation of std::numeric_limits for
- any type T - such as money in this case. When I'm doubt - I tend to think
- big.</p>
- <p>For now though I'm not going to address it. For what it's worth, my
- preference would be to do something like: </p>
- <pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span>
- <span class="keyword">struct</span> <span class="identifier">range</span> <span class="special">{</span>
- <span class="identifier">T</span> <span class="identifier">m_lowest</span><span class="special">;</span>
- <span class="identifier">T</span> <span class="identifier">m_highest</span><span class="special">;</span>
- <span class="comment">// default implementation</span>
- <span class="identifier">range</span><span class="special">(</span>
- <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">T</span> <span class="identifier">t_min</span><span class="special">,</span>
- <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">T</span> <span class="identifier">t_max</span>
- <span class="special">)</span> <span class="special">:</span>
- <span class="identifier">m_lowest</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span><span class="special">::</span><span class="identifier">lowest</span><span class="special">(</span><span class="identifier">t_min</span><span class="special">)</span><span class="special">,</span>
- <span class="identifier">m_highest</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span><span class="special">::</span><span class="identifier">max</span><span class="special">(</span><span class="identifier">t_max</span><span class="special">)</span>
- <span class="special">{</span><span class="special">}</span>
- <span class="special">}</span><span class="special">;</span></pre>
- <p>Then redeclare <code class="computeroutput">safe_base</code>, etc., accordingly.</p>
- <p>Also not that for C++20, template value parameters are no longer
- restricted to integer primitive types buy maybe class types as well. This
- means the library maybe extended to user class types without changing the
- current template signatures.</p>
- </div>
- <div class="section">
- <div class="titlepage"><div><div><h3 class="title">
- <a name="idm130201605904"></a>Concepts are Defined but Not Enforced.</h3></div></div></div>
- <p>The following is paraphrased from an issue raised by Andrzej
- Krzemieński as a <a href="https://github.com/robertramey/safe_numerics/issues/46" target="_top">github
- issue</a>.</p>
- <p><span class="quote">“<span class="quote">You do not need a concept to constrain anything with it, in
- your library. Or is the purpose of the Type requirements to show in detail
- what it means that safe<T> is a 'drop-in replacement for
- T?</span>”</span></p>
- <p>Right - currently I don't use the concept to constrain anything.
- They are currently a purely "conceptual" tool to keep the design from
- getting off track. This is common with other libraries such as the C++
- standard library where the concepts are defined but not enforced by
- compile time predicates. Hopefully in future that might change - see
- below</p>
- <p><span class="quote">“<span class="quote">If you want to extend safe<T> for other integer types,
- Type requirement still need to be fixed:</span>”</span></p>
- <p>Hmmmm - I'm not quite sure that this is true. One thing that IS true
- is the the interface and implementation of the library will need to be
- enhanced to permit "safe" to be applied to user defined types. This is
- apparent now, but as my brain can only comprehend the library one piece at
- a time, this design feature was lost during the implementation. In
- implementing co-existence of floats with safe integers, I did refactor the
- implementation in a way which I believe my eventually permit the
- application to any user supplied T which implements all the required
- operations of Numeric types. So as it is now this is pending. If the
- library were to become widely used, there might be motivation to do this.
- Time will tell. So for now I'm leaving these in the documentation and
- code, even though they are not actually used.</p>
- </div>
- <div class="section">
- <div class="titlepage"><div><div><h3 class="title">
- <a name="idm130201600176"></a>Other Pending Issues</h3></div></div></div>
- <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
- <li class="listitem"><p>The library is currently limited to integers. If there is
- interest, it could be extended to floats and possible to user
- defined types.</p></li>
- <li class="listitem"><p>Although care has been taken to make the library portable, at
- least some parts of the implementation - particularly
- <code class="computeroutput">checked</code> integer arithmetic - depend upon two's
- complement representation of integers. Hence the library is probably
- not currently portable to all other possible C++ architectures.
- These days, this is unlikely to be a limitation in practice.
- Starting with C++20, integer arithmetic will be guaranteed by the
- C++ standard to be two's complement.</p></li>
- <li class="listitem"><p><code class="computeroutput">std::common_type</code> is used in a variety of generic
- libraries, including std::chrono. Without a specialization for
- <code class="computeroutput">safe<T></code>s one cannot use the safe wrappers e.g. as
- a representation for <code class="computeroutput">std::chrono::duration</code>.</p></li>
- </ul></div>
- </div>
- </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 © 2012-2018 Robert Ramey<p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">Subject to Boost
- Software License</a></p>
- </div></td>
- </tr></table>
- <hr>
- <div class="spirit-nav">
- <a accesskey="p" href="rationale.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="acknowledgements.html"><img src="images/next.png" alt="Next"></a>
- </div>
- </body>
- </html>
|