pending.xml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.1//EN"
  3. "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
  4. <section id="safe_numerics.pending_issues">
  5. <title>Pending Issues</title>
  6. <?dbhtml stop-chunking?>
  7. <para>The library is under development. There are a number of issues still
  8. pending.</para>
  9. <section>
  10. <title><code>safe_base</code> Only Works for Scalar Types</title>
  11. <para>The following is paraphrased from an issue raised by Andrzej
  12. Krzemieński as a <ulink
  13. url="https://github.com/robertramey/safe_numerics/issues/44">github
  14. issue</ulink>. It touches upon fundamental ideas behind the library and
  15. how these ideas as the implementation of the library collided with
  16. reality.</para>
  17. <para><quote>In the current implementation safe&lt;T&gt; will only work
  18. with T being a C++ scalar type. Therefore making a general type
  19. requirements that say what operations are allowed is superfluous, and
  20. confusing (because it implies that safe&lt;&gt; is more
  21. generic.</quote></para>
  22. <para>When I started out, It became clear that I wanted "safe" types to
  23. look like "numeric" types. It also became clear pretty soon that there was
  24. going to be significant template meta-programming in the implementation.
  25. Normal type traits like std::is_integer are defined in the std namespace
  26. and one is discouraged from extending it. Also I needed some compile time
  27. "max" and "lowest" values. This lead me to base the design on
  28. std::numeric_limits. But std::numeric limits is inherently extensible to
  29. any "numeric" type. For example, money is a numeric type but not an
  30. intrinsic types. So it seemed that I needed to define a "numeric" concept
  31. which required that there be an implementation of std::numeric_limits for
  32. any type T - such as money in this case. When I'm doubt - I tend to think
  33. big.</para>
  34. <para>For now though I'm not going to address it. For what it's worth, my
  35. preference would be to do something like: <programlisting>template&lt;typename T&gt;
  36. struct range {
  37. T m_lowest;
  38. T m_highest;
  39. // default implementation
  40. range(
  41. const &amp; T t_min,
  42. const &amp; T t_max
  43. ) :
  44. m_lowest(std::numeric_limits&lt;T&gt;::lowest(t_min),
  45. m_highest(std::numeric_limits&lt;T&gt;::max(t_max)
  46. {}
  47. };</programlisting></para>
  48. <para>Then redeclare <code>safe_base</code>, etc., accordingly.</para>
  49. <para>Also not that for C++20, template value parameters are no longer
  50. restricted to integer primitive types buy maybe class types as well. This
  51. means the library maybe extended to user class types without changing the
  52. current template signatures.</para>
  53. </section>
  54. <section>
  55. <title>Concepts are Defined but Not Enforced.</title>
  56. <para>The following is paraphrased from an issue raised by Andrzej
  57. Krzemieński as a <ulink
  58. url="https://github.com/robertramey/safe_numerics/issues/46">github
  59. issue</ulink>.</para>
  60. <para><quote>You do not need a concept to constrain anything with it, in
  61. your library. Or is the purpose of the Type requirements to show in detail
  62. what it means that safe&lt;T&gt; is a 'drop-in replacement for
  63. T?</quote></para>
  64. <para>Right - currently I don't use the concept to constrain anything.
  65. They are currently a purely "conceptual" tool to keep the design from
  66. getting off track. This is common with other libraries such as the C++
  67. standard library where the concepts are defined but not enforced by
  68. compile time predicates. Hopefully in future that might change - see
  69. below</para>
  70. <para><quote>If you want to extend safe&lt;T&gt; for other integer types,
  71. Type requirement still need to be fixed:</quote></para>
  72. <para>Hmmmm - I'm not quite sure that this is true. One thing that IS true
  73. is the the interface and implementation of the library will need to be
  74. enhanced to permit "safe" to be applied to user defined types. This is
  75. apparent now, but as my brain can only comprehend the library one piece at
  76. a time, this design feature was lost during the implementation. In
  77. implementing co-existence of floats with safe integers, I did refactor the
  78. implementation in a way which I believe my eventually permit the
  79. application to any user supplied T which implements all the required
  80. operations of Numeric types. So as it is now this is pending. If the
  81. library were to become widely used, there might be motivation to do this.
  82. Time will tell. So for now I'm leaving these in the documentation and
  83. code, even though they are not actually used.</para>
  84. </section>
  85. <section>
  86. <title>Other Pending Issues</title>
  87. <para><itemizedlist>
  88. <listitem>
  89. <para>The library is currently limited to integers. If there is
  90. interest, it could be extended to floats and possible to user
  91. defined types.</para>
  92. </listitem>
  93. <listitem>
  94. <para>Although care has been taken to make the library portable, at
  95. least some parts of the implementation - particularly
  96. <code>checked</code> integer arithmetic - depend upon two's
  97. complement representation of integers. Hence the library is probably
  98. not currently portable to all other possible C++ architectures.
  99. These days, this is unlikely to be a limitation in practice.
  100. Starting with C++20, integer arithmetic will be guaranteed by the
  101. C++ standard to be two's complement.</para>
  102. </listitem>
  103. <listitem>
  104. <para><code>std::common_type</code> is used in a variety of generic
  105. libraries, including std::chrono. Without a specialization for
  106. <code>safe&lt;T&gt;</code>s one cannot use the safe wrappers e.g. as
  107. a representation for <code>std::chrono::duration</code>.</para>
  108. </listitem>
  109. </itemizedlist></para>
  110. </section>
  111. </section>