integer_concept.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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.integer">
  5. <title>Integer&lt;T&gt;</title>
  6. <?dbhtml stop-chunking?>
  7. <section>
  8. <title>Description</title>
  9. <para>A type fulfills the requirements of an Integer if it has the
  10. properties of a integer.</para>
  11. <para>More specifically, a type T is Integer if there exists a
  12. specialization of <code>std::numeric_limits&lt;T&gt; for which
  13. std::numeric_limits&lt;T&gt;::is_integer</code> is equal to
  14. <code>true</code>. See the documentation for standard library class
  15. <code>numeric_limits</code>. The standard library includes such
  16. specializations for all built-in numeric types. Note that this concept is
  17. distinct from the C++ standard library type traits
  18. <code>is_integral</code> and <code>is_arithmetic</code>. These latter
  19. fulfill the requirements of the concept Numeric. But there are types which
  20. fulfill this concept for which <code>is_arithmetic&lt;T&gt;::value ==
  21. false</code>. For example see <code>safe&lt;int&gt;</code>.</para>
  22. </section>
  23. <section>
  24. <title>Refinement of</title>
  25. <para><link linkend="safe_numerics.numeric">Numeric</link></para>
  26. </section>
  27. <section>
  28. <title>Notation</title>
  29. <informaltable>
  30. <tgroup cols="2" colsep="1" rowsep="1">
  31. <colspec align="left" colwidth="2*"/>
  32. <colspec align="left" colwidth="4*"/>
  33. <tbody>
  34. <row>
  35. <entry><code>T, U, V</code></entry>
  36. <entry>A type that is a model of the Integer</entry>
  37. </row>
  38. <row>
  39. <entry><code>t, u</code></entry>
  40. <entry>An object of type modeling Integer</entry>
  41. </row>
  42. </tbody>
  43. </tgroup>
  44. </informaltable>
  45. </section>
  46. <section>
  47. <title>Valid Expressions</title>
  48. <para>In addition to the expressions defined in <link
  49. linkend="safe_numerics.numeric">Numeric</link> the following expressions
  50. must be valid. <table>
  51. <title>General</title>
  52. <tgroup cols="2">
  53. <colspec align="left" colwidth="2*"/>
  54. <colspec align="left" colwidth="4*"/>
  55. <thead>
  56. <row>
  57. <entry align="left">Expression</entry>
  58. <entry>Value</entry>
  59. </row>
  60. </thead>
  61. <tbody>
  62. <row>
  63. <entry><code>std::numeric_limits&lt;T&gt;::is_integer</code></entry>
  64. <entry>true</entry>
  65. </row>
  66. </tbody>
  67. </tgroup>
  68. </table><informaltable>
  69. <tgroup cols="3">
  70. <colspec align="left" colwidth="1*"/>
  71. <colspec align="left" colwidth="1*"/>
  72. <colspec align="left" colwidth="4*"/>
  73. <thead>
  74. <row>
  75. <entry align="left">Expression</entry>
  76. <entry>Return Type</entry>
  77. <entry>Semantics</entry>
  78. </row>
  79. </thead>
  80. <tbody>
  81. <row>
  82. <entry><code>~t</code></entry>
  83. <entry><code>T</code></entry>
  84. <entry>bitwise complement</entry>
  85. </row>
  86. <row>
  87. <entry><code>t &lt;&lt; u</code></entry>
  88. <entry><code>T</code></entry>
  89. <entry>shift t left u bits</entry>
  90. </row>
  91. <row>
  92. <entry><code>t &gt;&gt; u</code></entry>
  93. <entry><code>T</code></entry>
  94. <entry>shift t right by u bits</entry>
  95. </row>
  96. <row>
  97. <entry><code>t &amp; u</code></entry>
  98. <entry><code>V</code></entry>
  99. <entry>and of t and u padded out to max # bits in t, u</entry>
  100. </row>
  101. <row>
  102. <entry><code>t | u</code></entry>
  103. <entry><code>V</code></entry>
  104. <entry>or of t and u padded out to max # bits in t, u</entry>
  105. </row>
  106. <row>
  107. <entry><code>t ^ u</code></entry>
  108. <entry><code>V</code></entry>
  109. <entry>exclusive or of t and u padded out to max # bits in t,
  110. u</entry>
  111. </row>
  112. <row>
  113. <entry><code>t &lt;&lt;= u</code></entry>
  114. <entry><code>T</code></entry>
  115. <entry>left shift the value of t by u bits</entry>
  116. </row>
  117. <row>
  118. <entry><code>t &gt;&gt;= u</code></entry>
  119. <entry><code>T</code></entry>
  120. <entry>right shift the value of t by u bits</entry>
  121. </row>
  122. <row>
  123. <entry><code>t &amp;= u</code></entry>
  124. <entry><code>T</code></entry>
  125. <entry>and the value of t with u and assign to t</entry>
  126. </row>
  127. <row>
  128. <entry><code>t |= u</code></entry>
  129. <entry><code>T</code></entry>
  130. <entry>or the value of t with u and assign to t</entry>
  131. </row>
  132. <row>
  133. <entry><code>t ^= u</code></entry>
  134. <entry><code>T</code></entry>
  135. <entry>exclusive or the value of t with u and assign to
  136. t</entry>
  137. </row>
  138. </tbody>
  139. </tgroup>
  140. </informaltable></para>
  141. </section>
  142. <section>
  143. <title>Models</title>
  144. <para><code>int, safe&lt;int&gt;, safe_unsigned_range&lt;0, 11&gt;,
  145. checked_result&lt;int&gt; etc.</code></para>
  146. </section>
  147. <section>
  148. <title>Header</title>
  149. <para><ulink
  150. url="../../include/boost/safe_numerics/concept/numeric.hpp"><code>#include
  151. &lt;boost/safe_numerics/concepts/integer.hpp&gt; </code></ulink></para>
  152. </section>
  153. </section>