intrinsics.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Support for Compiler Intrinsics</title>
  5. <link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
  7. <link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.TypeTraits">
  8. <link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.TypeTraits">
  9. <link rel="prev" href="user_defined.html" title="User Defined Specializations">
  10. <link rel="next" href="mpl.html" title="MPL Interoperability">
  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 alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
  15. <td align="center"><a href="../../../../../index.html">Home</a></td>
  16. <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
  17. <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
  18. <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
  19. <td align="center"><a href="../../../../../more/index.htm">More</a></td>
  20. </tr></table>
  21. <hr>
  22. <div class="spirit-nav">
  23. <a accesskey="p" href="user_defined.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mpl.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section">
  26. <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  27. <a name="boost_typetraits.intrinsics"></a><a class="link" href="intrinsics.html" title="Support for Compiler Intrinsics">Support for Compiler Intrinsics</a>
  28. </h2></div></div></div>
  29. <p>
  30. There are some traits that can not be implemented within the current C++ language:
  31. to make these traits "just work" with user defined types, some kind
  32. of additional help from the compiler is required. Currently (April 2008) Visual
  33. C++ 8 and 9, GNU GCC 4.3 and MWCW 9 provide at least some of the the necessary
  34. intrinsics, and other compilers will no doubt follow in due course.
  35. </p>
  36. <p>
  37. The Following traits classes always need compiler support to do the right thing
  38. for all types (but all have safe fallback positions if this support is unavailable):
  39. </p>
  40. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  41. <li class="listitem">
  42. <a class="link" href="reference/is_final.html" title="is_final">is_final</a>
  43. </li>
  44. <li class="listitem">
  45. <a class="link" href="reference/is_union.html" title="is_union">is_union</a>
  46. </li>
  47. <li class="listitem">
  48. <a class="link" href="reference/is_pod.html" title="is_pod">is_pod</a>
  49. </li>
  50. <li class="listitem">
  51. <a class="link" href="reference/is_nothrow_move_assignable.html" title="is_nothrow_move_assignable">is_nothrow_move_assignable</a>
  52. </li>
  53. <li class="listitem">
  54. <a class="link" href="reference/is_nothrow_move_constructible.html" title="is_nothrow_move_constructible">is_nothrow_move_constructible</a>
  55. </li>
  56. <li class="listitem">
  57. <a class="link" href="reference/has_trivial_constructor.html" title="has_trivial_constructor">has_trivial_constructor</a>
  58. </li>
  59. <li class="listitem">
  60. <a class="link" href="reference/has_trivial_copy.html" title="has_trivial_copy">has_trivial_copy</a>
  61. </li>
  62. <li class="listitem">
  63. <a class="link" href="reference/has_trivial_move_constructor.html" title="has_trivial_move_constructor">has_trivial_move_constructor</a>
  64. </li>
  65. <li class="listitem">
  66. <a class="link" href="reference/has_trivial_assign.html" title="has_trivial_assign">has_trivial_assign</a>
  67. </li>
  68. <li class="listitem">
  69. <a class="link" href="reference/has_trivial_move_assign.html" title="has_trivial_move_assign">has_trivial_move_assign</a>
  70. </li>
  71. <li class="listitem">
  72. <a class="link" href="reference/has_trivial_destructor.html" title="has_trivial_destructor">has_trivial_destructor</a>
  73. </li>
  74. <li class="listitem">
  75. <a class="link" href="reference/has_nothrow_constructor.html" title="has_nothrow_constructor">has_nothrow_constructor</a>
  76. </li>
  77. <li class="listitem">
  78. <a class="link" href="reference/has_nothrow_copy.html" title="has_nothrow_copy">has_nothrow_copy</a>
  79. </li>
  80. <li class="listitem">
  81. <a class="link" href="reference/has_nothrow_assign.html" title="has_nothrow_assign">has_nothrow_assign</a>
  82. </li>
  83. <li class="listitem">
  84. <a class="link" href="reference/has_virtual_destructor.html" title="has_virtual_destructor">has_virtual_destructor</a>
  85. </li>
  86. </ul></div>
  87. <p>
  88. The following traits classes can't be portably implemented in the C++ language,
  89. although in practice, the implementations do in fact do the right thing on
  90. all the compilers we know about:
  91. </p>
  92. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  93. <li class="listitem">
  94. <a class="link" href="reference/is_empty.html" title="is_empty">is_empty</a>
  95. </li>
  96. <li class="listitem">
  97. <a class="link" href="reference/is_polymorphic.html" title="is_polymorphic">is_polymorphic</a>
  98. </li>
  99. <li class="listitem">
  100. <a class="link" href="reference/is_virtual_base_of.html" title="is_virtual_base_of">is_virtual_base_of</a>
  101. </li>
  102. </ul></div>
  103. <p>
  104. The following traits classes are dependent on one or more of the above:
  105. </p>
  106. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  107. <li class="listitem">
  108. <a class="link" href="reference/is_class.html" title="is_class">is_class</a>
  109. </li>
  110. <li class="listitem">
  111. <a class="link" href="reference/is_stateless.html" title="is_stateless">is_stateless</a>
  112. </li>
  113. </ul></div>
  114. <p>
  115. The hooks for compiler-intrinsic support are defined in <a href="../../../../../boost/type_traits/intrinsics.hpp" target="_top">boost/type_traits/intrinsics.hpp</a>,
  116. adding support for new compilers is simply a matter of defining one of more
  117. of the following macros:
  118. </p>
  119. <div class="table">
  120. <a name="boost_typetraits.intrinsics.macros_for_compiler_intrinsics"></a><p class="title"><b>Table&#160;1.9.&#160;Macros for Compiler Intrinsics</b></p>
  121. <div class="table-contents"><table class="table" summary="Macros for Compiler Intrinsics">
  122. <colgroup>
  123. <col>
  124. <col>
  125. </colgroup>
  126. <thead><tr>
  127. <th>
  128. <p>
  129. BOOST_ALIGNMENT_OF(T)
  130. </p>
  131. </th>
  132. <th>
  133. <p>
  134. Should evaluate to the alignment requirements of type T
  135. </p>
  136. </th>
  137. </tr></thead>
  138. <tbody>
  139. <tr>
  140. <td>
  141. <p>
  142. BOOST_IS_ABSTRACT(T)
  143. </p>
  144. </td>
  145. <td>
  146. <p>
  147. Should evaluate to true if T is an abstract type
  148. </p>
  149. </td>
  150. </tr>
  151. <tr>
  152. <td>
  153. <p>
  154. BOOST_IS_BASE_OF(T,U)
  155. </p>
  156. </td>
  157. <td>
  158. <p>
  159. Should evaluate to true if T is a base class of U
  160. </p>
  161. </td>
  162. </tr>
  163. <tr>
  164. <td>
  165. <p>
  166. BOOST_IS_CLASS(T)
  167. </p>
  168. </td>
  169. <td>
  170. <p>
  171. Should evaluate to true if T is a class type
  172. </p>
  173. </td>
  174. </tr>
  175. <tr>
  176. <td>
  177. <p>
  178. BOOST_IS_CONVERTIBLE(T,U)
  179. </p>
  180. </td>
  181. <td>
  182. <p>
  183. Should evaluate to true if T is convertible to U
  184. </p>
  185. </td>
  186. </tr>
  187. <tr>
  188. <td>
  189. <p>
  190. BOOST_IS_EMPTY(T)
  191. </p>
  192. </td>
  193. <td>
  194. <p>
  195. Should evaluate to true if T is an empty struct or union
  196. </p>
  197. </td>
  198. </tr>
  199. <tr>
  200. <td>
  201. <p>
  202. BOOST_IS_ENUM(T)
  203. </p>
  204. </td>
  205. <td>
  206. <p>
  207. Should evaluate to true is T is an enum
  208. </p>
  209. </td>
  210. </tr>
  211. <tr>
  212. <td>
  213. <p>
  214. BOOST_IS_FINAL(T)
  215. </p>
  216. </td>
  217. <td>
  218. <p>
  219. Should evaluate to true if T is a class type declared with the final
  220. specifier
  221. </p>
  222. </td>
  223. </tr>
  224. <tr>
  225. <td>
  226. <p>
  227. BOOST_IS_NOTHROW_MOVE_ASSIGN(T)
  228. </p>
  229. </td>
  230. <td>
  231. <p>
  232. Should evaluate to true T has a non-throwing move assign operator.
  233. </p>
  234. </td>
  235. </tr>
  236. <tr>
  237. <td>
  238. <p>
  239. BOOST_IS_NOTHROW_MOVE_CONSTRUCT(T)
  240. </p>
  241. </td>
  242. <td>
  243. <p>
  244. Should evaluate to true T has a non-throwing move constructor.
  245. </p>
  246. </td>
  247. </tr>
  248. <tr>
  249. <td>
  250. <p>
  251. BOOST_IS_POLYMORPHIC(T)
  252. </p>
  253. </td>
  254. <td>
  255. <p>
  256. Should evaluate to true if T is a polymorphic type
  257. </p>
  258. </td>
  259. </tr>
  260. <tr>
  261. <td>
  262. <p>
  263. BOOST_IS_POD(T)
  264. </p>
  265. </td>
  266. <td>
  267. <p>
  268. Should evaluate to true if T is a POD type
  269. </p>
  270. </td>
  271. </tr>
  272. <tr>
  273. <td>
  274. <p>
  275. BOOST_IS_UNION(T)
  276. </p>
  277. </td>
  278. <td>
  279. <p>
  280. Should evaluate to true if T is a union type
  281. </p>
  282. </td>
  283. </tr>
  284. <tr>
  285. <td>
  286. <p>
  287. BOOST_HAS_NOTHROW_ASSIGN(T)
  288. </p>
  289. </td>
  290. <td>
  291. <p>
  292. Should evaluate to true if <code class="computeroutput"><span class="identifier">T</span>
  293. <span class="identifier">t</span><span class="special">,</span>
  294. <span class="identifier">u</span><span class="special">;</span>
  295. <span class="identifier">t</span> <span class="special">=</span>
  296. <span class="identifier">u</span></code> can not throw
  297. </p>
  298. </td>
  299. </tr>
  300. <tr>
  301. <td>
  302. <p>
  303. BOOST_HAS_NOTHROW_CONSTRUCTOR(T)
  304. </p>
  305. </td>
  306. <td>
  307. <p>
  308. Should evaluate to true if <code class="computeroutput"><span class="identifier">T</span>
  309. <span class="identifier">x</span><span class="special">;</span></code>
  310. can not throw
  311. </p>
  312. </td>
  313. </tr>
  314. <tr>
  315. <td>
  316. <p>
  317. BOOST_HAS_NOTHROW_COPY(T)
  318. </p>
  319. </td>
  320. <td>
  321. <p>
  322. Should evaluate to true if <code class="computeroutput"><span class="identifier">T</span><span class="special">(</span><span class="identifier">t</span><span class="special">)</span></code> can not throw
  323. </p>
  324. </td>
  325. </tr>
  326. <tr>
  327. <td>
  328. <p>
  329. BOOST_HAS_TRIVIAL_ASSIGN(T)
  330. </p>
  331. </td>
  332. <td>
  333. <p>
  334. Should evaluate to true if T has a trivial assignment operator (and
  335. can therefore be replaced by a call to memcpy)
  336. </p>
  337. </td>
  338. </tr>
  339. <tr>
  340. <td>
  341. <p>
  342. BOOST_HAS_TRIVIAL_CONSTRUCTOR(T)
  343. </p>
  344. </td>
  345. <td>
  346. <p>
  347. Should evaluate to true if the default constructor for T is trivial
  348. (i.e. has no effect)
  349. </p>
  350. </td>
  351. </tr>
  352. <tr>
  353. <td>
  354. <p>
  355. BOOST_HAS_TRIVIAL_COPY(T)
  356. </p>
  357. </td>
  358. <td>
  359. <p>
  360. Should evaluate to true if T has a trivial copy constructor (and
  361. can therefore be replaced by a call to memcpy)
  362. </p>
  363. </td>
  364. </tr>
  365. <tr>
  366. <td>
  367. <p>
  368. BOOST_HAS_TRIVIAL_DESTRUCTOR(T)
  369. </p>
  370. </td>
  371. <td>
  372. <p>
  373. Should evaluate to true if T has a trivial destructor (i.e. ~T()
  374. has no effect)
  375. </p>
  376. </td>
  377. </tr>
  378. <tr>
  379. <td>
  380. <p>
  381. BOOST_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T)
  382. </p>
  383. </td>
  384. <td>
  385. <p>
  386. Should evaluate to true if T has a trivial move constructor (and
  387. can therefore be replaced by a call to memcpy)
  388. </p>
  389. </td>
  390. </tr>
  391. <tr>
  392. <td>
  393. <p>
  394. BOOST_HAS_TRIVIAL_MOVE_ASSIGN(T)
  395. </p>
  396. </td>
  397. <td>
  398. <p>
  399. Should evaluate to true if T has a trivial move assignment operator
  400. (and can therefore be replaced by a call to memcpy)
  401. </p>
  402. </td>
  403. </tr>
  404. <tr>
  405. <td>
  406. <p>
  407. BOOST_HAS_VIRTUAL_DESTRUCTOR(T)
  408. </p>
  409. </td>
  410. <td>
  411. <p>
  412. Should evaluate to true T has a virtual destructor
  413. </p>
  414. </td>
  415. </tr>
  416. </tbody>
  417. </table></div>
  418. </div>
  419. <br class="table-break">
  420. </div>
  421. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  422. <td align="left"></td>
  423. <td align="right"><div class="copyright-footer">Copyright &#169; 2000, 2011 Adobe Systems Inc, David Abrahams,
  424. Frederic Bron, Steve Cleary, Beman Dawes, Aleksey Gurtovoy, Howard Hinnant,
  425. Jesse Jones, Mat Marcus, Itay Maman, John Maddock, Alexander Nasonov, Thorsten
  426. Ottosen, Roman Perepelitsa, Robert Ramey, Jeremy Siek, Robert Stewart and Steven
  427. Watanabe<p>
  428. Distributed under the Boost Software License, Version 1.0. (See accompanying
  429. file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
  430. </p>
  431. </div></td>
  432. </tr></table>
  433. <hr>
  434. <div class="spirit-nav">
  435. <a accesskey="p" href="user_defined.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mpl.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  436. </div>
  437. </body>
  438. </html>