type_traits.h.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <chapter xml:id="type_traits.h">
  2. <title><tt>__vic/type_traits.h</tt></title>
  3. <p>Template metaprogramming support.</p>
  4. <p>All the predicate metafunctions have boolean member <tt>value</tt> and,
  5. usually, derived from <tt>integral_constant</tt>.</p>
  6. <p>All the type transformer metafunctions have type member <tt>type</tt>
  7. containing the conversion result.</p>
  8. <p>All of the template aliases are available only in C++11 mode.</p>
  9. <chapter xml:id="integral_constant">
  10. <title><tt>integral_constant</tt></title>
  11. <code-block lang="C++"><![CDATA[
  12. template<class T, T Val>
  13. struct integral_constant
  14. {
  15. using value_type = T;
  16. using type = integral_constant<T, Val>;
  17. static constexpr T value = Val;
  18. };
  19. ]]></code-block>
  20. <p>The topmost base class of the most metafunctions.</p>
  21. </chapter>
  22. <chapter xml:id="true_type">
  23. <title><tt>true_type</tt></title>
  24. <code-block lang="C++"><![CDATA[
  25. using true_type = integral_constant<bool, true>;
  26. ]]></code-block>
  27. <p>Base class for predicate metafunctions that have value <tt>true</tt>.</p>
  28. </chapter>
  29. <chapter xml:id="false_type">
  30. <title><tt>false_type</tt></title>
  31. <code-block lang="C++"><![CDATA[
  32. using false_type = integral_constant<bool, false>;
  33. ]]></code-block>
  34. <p>Base class for predicate metafunctions that have value <tt>false</tt>.</p>
  35. </chapter>
  36. <chapter xml:id="is_same">
  37. <title><tt>is_same</tt></title>
  38. <code-block lang="C++"><![CDATA[
  39. template<class T1, class T2> struct is_same;
  40. ]]></code-block>
  41. <p>A predicate. True if <tt>T1</tt> and <tt>T2</tt> are exactly the same
  42. type.</p>
  43. </chapter>
  44. <chapter xml:id="is_const">
  45. <title><tt>is_const</tt></title>
  46. <code-block lang="C++"><![CDATA[
  47. template<class T> struct is_const;
  48. ]]></code-block>
  49. <p>A predicate. True if <tt>T</tt> has <tt>const</tt> qualifier.</p>
  50. </chapter>
  51. <chapter xml:id="is_signed_integer">
  52. <title><tt>is_signed_integer</tt></title>
  53. <code-block lang="C++"><![CDATA[
  54. template<class T> struct is_signed_integer;
  55. ]]></code-block>
  56. <p>A predicate. True if <tt>T</tt> is a one of the "standard signed integer
  57. types" (see the Standard).</p>
  58. </chapter>
  59. <chapter xml:id="is_unsigned_integer">
  60. <title><tt>is_unsigned_integer</tt></title>
  61. <code-block lang="C++"><![CDATA[
  62. template<class T> struct is_unsigned_integer;
  63. ]]></code-block>
  64. <p>A predicate. True if <tt>T</tt> is a one of the "standard unsigned integer
  65. types" (see the Standard).</p>
  66. </chapter>
  67. <chapter xml:id="conjunction">
  68. <title><tt>conjunction</tt> <sign>C++11</sign></title>
  69. <code-block lang="C++"><![CDATA[
  70. template<class... B> struct conjunction;
  71. ]]></code-block>
  72. <p>A predicate. The logical conjunction of the predicates <tt>B...</tt>.
  73. False iff one of the <tt>B...</tt> is false.</p>
  74. </chapter>
  75. <chapter xml:id="disjunction">
  76. <title><tt>disjunction</tt> <sign>C++11</sign></title>
  77. <code-block lang="C++"><![CDATA[
  78. template<class... B> struct disjunction;
  79. ]]></code-block>
  80. <p>A predicate. The logical disjunction of the predicates <tt>B...</tt>.
  81. True iff one of the <tt>B...</tt> is true.</p>
  82. </chapter>
  83. <chapter xml:id="negation">
  84. <title><tt>negation</tt></title>
  85. <code-block lang="C++"><![CDATA[
  86. template<class B> struct negation;
  87. ]]></code-block>
  88. <p>A predicate. The logical negation of the predicate <tt>B</tt>.</p>
  89. </chapter>
  90. <chapter xml:id="remove_const">
  91. <title><tt>remove_const</tt></title>
  92. <code-block lang="C++"><![CDATA[
  93. template<class T> struct remove_const;
  94. template<class T> using remove_const_t = typename remove_const<T>::type;
  95. ]]></code-block>
  96. <p>A type transformer. Removes the top-level <tt>const</tt> qualifier or just
  97. returns <tt>T</tt> if it doesn't have such qualifier.</p>
  98. </chapter>
  99. <chapter xml:id="remove_volatile">
  100. <title><tt>remove_volatile</tt></title>
  101. <code-block lang="C++"><![CDATA[
  102. template<class T> struct remove_volatile;
  103. template<class T> using remove_volatile_t = typename remove_volatile<T>::type;
  104. ]]></code-block>
  105. <p>A type transformer. Removes the top-level <tt>volatile</tt> qualifier or just
  106. returns <tt>T</tt> if it doesn't have such qualifier.</p>
  107. </chapter>
  108. <chapter xml:id="remove_cv">
  109. <title><tt>remove_cv</tt></title>
  110. <code-block lang="C++"><![CDATA[
  111. template<class T> struct remove_cv;
  112. template<class T> using remove_cv_t = typename remove_cv<T>::type;
  113. ]]></code-block>
  114. <p>A type transformer. Removes any top-level cv-qualifier or just returns
  115. <tt>T</tt> if it doesn't have such qualifiers.</p>
  116. </chapter>
  117. <chapter xml:id="remove_reference">
  118. <title><tt>remove_reference</tt></title>
  119. <code-block lang="C++"><![CDATA[
  120. template<class T> struct remove_reference;
  121. template<class T> using remove_reference_t = typename remove_reference<T>::type;
  122. ]]></code-block>
  123. <p>A type transformer. Returns the type referred by <tt>T</tt> or just
  124. <tt>T</tt> if it isn't a reference type.</p>
  125. </chapter>
  126. <chapter xml:id="remove_cvref">
  127. <title><tt>remove_cvref</tt></title>
  128. <code-block lang="C++"><![CDATA[
  129. template<class T> struct remove_cvref;
  130. template<class T> using remove_cvref_t = typename remove_cvref<T>::type;
  131. ]]></code-block>
  132. <p>A type transformer. Applies <tt>remove_reference</tt> then <tt>remove_cv</tt>
  133. to <tt>T</tt>.</p>
  134. </chapter>
  135. <chapter xml:id="remove_pointer">
  136. <title><tt>remove_pointer</tt></title>
  137. <code-block lang="C++"><![CDATA[
  138. template<class T> struct remove_pointer;
  139. template<class T> using remove_pointer_t = typename remove_pointer<T>::type;
  140. ]]></code-block>
  141. <p>A type transformer. Returns the type pointed by <tt>T</tt> or just
  142. <tt>T</tt> if it isn't a pointer type.</p>
  143. </chapter>
  144. <chapter xml:id="conditional">
  145. <title><tt>conditional</tt></title>
  146. <code-block lang="C++"><![CDATA[
  147. template<bool Cond, class Then, class Else> struct conditional;
  148. template<bool Cond, class Then, class Else>
  149. using conditional_t = typename conditional<Cond, Then, Else>;
  150. ]]></code-block>
  151. <p>A type transformer. Returns <tt>Then</tt> if <tt>Cond == true</tt>.
  152. <tt>Else</tt> is returned otherwise.</p>
  153. </chapter>
  154. <chapter xml:id="enable_if">
  155. <title><tt>enable_if</tt>, <tt>disable_if</tt></title>
  156. <code-block lang="C++"><![CDATA[
  157. template<bool Test, class T = void>
  158. struct enable_if
  159. {
  160. using type = T;
  161. };
  162. template<class T>
  163. struct enable_if<false, T> {};
  164. template<bool Test, class T = void>
  165. struct disable_if : enable_if<!Test, T> {};
  166. ]]></code-block>
  167. <p>Classical tools for SFINAE-magic.</p>
  168. </chapter>
  169. <chapter xml:id="index_sequence">
  170. <title><tt>index_sequence</tt>, <tt>make_index_sequence</tt> <sign>C++11</sign></title>
  171. <code-block lang="C++"><![CDATA[
  172. template<size_t... I>
  173. struct index_sequence
  174. {
  175. static constexpr size_t size() { return sizeof...(I); }
  176. };
  177. template<size_t Size>
  178. using make_index_sequence = index_sequence<0, 1, ..., Size-1>;
  179. ]]></code-block>
  180. <p>Implementation of C++14 <tt>std::index_sequence</tt> for C++11.</p>
  181. <note>Unlike <tt>std::index_sequence</tt> it isn't a special case of some sort
  182. of <tt>std::integer_sequence</tt>.</note>
  183. </chapter>
  184. </chapter>