• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4<title>Pending Issues</title>
5<link rel="stylesheet" href="boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="index.html" title="Safe Numerics">
8<link rel="up" href="index.html" title="Safe Numerics">
9<link rel="prev" href="rationale.html" title="Rationale and FAQ">
10<link rel="next" href="acknowledgements.html" title="Acknowledgements">
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 href="index.html" height="164px" src="pre-boost.jpg" alt="Library Documentation Index"></td>
15<td><h2>Safe Numerics</h2></td>
16</tr></table>
17<div class="spirit-nav">
18<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>
19</div>
20<div class="section">
21<div class="titlepage"><div><div><h2 class="title" style="clear: both">
22<a name="safe_numerics.pending_issues"></a>Pending Issues</h2></div></div></div>
23<div class="toc"><dl class="toc">
24<dt><span class="section"><a href="pending_issues.html#idm130201646352"><code class="computeroutput">safe_base</code> Only Works for Scalar Types</a></span></dt>
25<dt><span class="section"><a href="pending_issues.html#idm130201605904">Concepts are Defined but Not Enforced.</a></span></dt>
26<dt><span class="section"><a href="pending_issues.html#idm130201600176">Other Pending Issues</a></span></dt>
27</dl></div>
28<p>The library is under development. There are a number of issues still
29  pending.</p>
30<div class="section">
31<div class="titlepage"><div><div><h3 class="title">
32<a name="idm130201646352"></a><code class="computeroutput">safe_base</code> Only Works for Scalar Types</h3></div></div></div>
33<p>The following is paraphrased from an issue raised by Andrzej
34    Krzemie&#324;ski as a <a href="https://github.com/robertramey/safe_numerics/issues/44" target="_top">github
35    issue</a>. It touches upon fundamental ideas behind the library and
36    how these ideas as the implementation of the library collided with
37    reality.</p>
38<p><span class="quote">&#8220;<span class="quote">In the current implementation safe&lt;T&gt; will only work
39    with T being a C++ scalar type. Therefore making a general type
40    requirements that say what operations are allowed is superfluous, and
41    confusing (because it implies that safe&lt;&gt; is more
42    generic.</span>&#8221;</span></p>
43<p>When I started out, It became clear that I wanted "safe" types to
44    look like "numeric" types. It also became clear pretty soon that there was
45    going to be significant template meta-programming in the implementation.
46    Normal type traits like std::is_integer are defined in the std namespace
47    and one is discouraged from extending it. Also I needed some compile time
48    "max" and "lowest" values. This lead me to base the design on
49    std::numeric_limits. But std::numeric limits is inherently extensible to
50    any "numeric" type. For example, money is a numeric type but not an
51    intrinsic types. So it seemed that I needed to define a "numeric" concept
52    which required that there be an implementation of std::numeric_limits for
53    any type T - such as money in this case. When I'm doubt - I tend to think
54    big.</p>
55<p>For now though I'm not going to address it. For what it's worth, my
56    preference would be to do something like: </p>
57<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
58<span class="keyword">struct</span> <span class="identifier">range</span> <span class="special">{</span>
59    <span class="identifier">T</span> <span class="identifier">m_lowest</span><span class="special">;</span>
60    <span class="identifier">T</span> <span class="identifier">m_highest</span><span class="special">;</span>
61    <span class="comment">// default implementation</span>
62    <span class="identifier">range</span><span class="special">(</span>
63        <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">T</span> <span class="identifier">t_min</span><span class="special">,</span>
64        <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">T</span> <span class="identifier">t_max</span>
65    <span class="special">)</span> <span class="special">:</span>
66        <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">&lt;</span><span class="identifier">T</span><span class="special">&gt;</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>
67        <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">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span><span class="special">::</span><span class="identifier">max</span><span class="special">(</span><span class="identifier">t_max</span><span class="special">)</span>
68    <span class="special">{</span><span class="special">}</span>
69<span class="special">}</span><span class="special">;</span></pre>
70<p>Then redeclare <code class="computeroutput">safe_base</code>, etc., accordingly.</p>
71<p>Also not that for C++20, template value parameters are no longer
72    restricted to integer primitive types buy maybe class types as well. This
73    means the library maybe extended to user class types without changing the
74    current template signatures.</p>
75</div>
76<div class="section">
77<div class="titlepage"><div><div><h3 class="title">
78<a name="idm130201605904"></a>Concepts are Defined but Not Enforced.</h3></div></div></div>
79<p>The following is paraphrased from an issue raised by Andrzej
80    Krzemie&#324;ski as a <a href="https://github.com/robertramey/safe_numerics/issues/46" target="_top">github
81    issue</a>.</p>
82<p><span class="quote">&#8220;<span class="quote">You do not need a concept to constrain anything with it, in
83    your library. Or is the purpose of the Type requirements to show in detail
84    what it means that safe&lt;T&gt; is a 'drop-in replacement for
85    T?</span>&#8221;</span></p>
86<p>Right - currently I don't use the concept to constrain anything.
87    They are currently a purely "conceptual" tool to keep the design from
88    getting off track. This is common with other libraries such as the C++
89    standard library where the concepts are defined but not enforced by
90    compile time predicates. Hopefully in future that might change - see
91    below</p>
92<p><span class="quote">&#8220;<span class="quote">If you want to extend safe&lt;T&gt; for other integer types,
93    Type requirement still need to be fixed:</span>&#8221;</span></p>
94<p>Hmmmm - I'm not quite sure that this is true. One thing that IS true
95    is the the interface and implementation of the library will need to be
96    enhanced to permit "safe" to be applied to user defined types. This is
97    apparent now, but as my brain can only comprehend the library one piece at
98    a time, this design feature was lost during the implementation. In
99    implementing co-existence of floats with safe integers, I did refactor the
100    implementation in a way which I believe my eventually permit the
101    application to any user supplied T which implements all the required
102    operations of Numeric types. So as it is now this is pending. If the
103    library were to become widely used, there might be motivation to do this.
104    Time will tell. So for now I'm leaving these in the documentation and
105    code, even though they are not actually used.</p>
106</div>
107<div class="section">
108<div class="titlepage"><div><div><h3 class="title">
109<a name="idm130201600176"></a>Other Pending Issues</h3></div></div></div>
110<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
111<li class="listitem"><p>The library is currently limited to integers. If there is
112          interest, it could be extended to floats and possible to user
113          defined types.</p></li>
114<li class="listitem"><p>Although care has been taken to make the library portable, at
115          least some parts of the implementation - particularly
116          <code class="computeroutput">checked</code> integer arithmetic - depend upon two's
117          complement representation of integers. Hence the library is probably
118          not currently portable to all other possible C++ architectures.
119          These days, this is unlikely to be a limitation in practice.
120          Starting with C++20, integer arithmetic will be guaranteed by the
121          C++ standard to be two's complement.</p></li>
122<li class="listitem"><p><code class="computeroutput">std::common_type</code> is used in a variety of generic
123          libraries, including std::chrono. Without a specialization for
124          <code class="computeroutput">safe&lt;T&gt;</code>s one cannot use the safe wrappers e.g. as
125          a representation for <code class="computeroutput">std::chrono::duration</code>.</p></li>
126</ul></div>
127</div>
128</div>
129<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
130<td align="left"></td>
131<td align="right"><div class="copyright-footer">Copyright &#169; 2012-2018 Robert Ramey<p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">Subject to Boost
132      Software License</a></p>
133</div></td>
134</tr></table>
135<hr>
136<div class="spirit-nav">
137<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>
138</div>
139</body>
140</html>
141