defs.h.xml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <chapter xml:id="defs.h">
  2. <title><tt>__vic/defs.h</tt></title>
  3. <p>Misc. fundamental definitions.</p>
  4. <chapter xml:id="nullptr">
  5. <title><tt>nullptr</tt> <sign>C++98 only</sign></title>
  6. <p>Null pointer literal. Can be used instead of <tt>NULL</tt> or <tt>0</tt>.
  7. In ISO C++ 98 mode defined as</p>
  8. <code-block lang="C++">
  9. const int nullptr = 0;
  10. </code-block>
  11. <p>This definition allows to write C++11-style code using C++98 standard.</p>
  12. <p>It is one of the few global definitions inroduced by the library. Definition
  13. can be prevented by definition <tt>__VIC_NO_NULLPTR_DEF</tt> macro before
  14. inclusion.</p>
  15. <section><title>Example</title>
  16. <code-block lang="C++"><![CDATA[
  17. int *p = nullptr;
  18. pthread_create(&tid, nullptr, thread_func, nullptr);
  19. ]]></code-block>
  20. </section>
  21. </chapter>
  22. <chapter xml:id="noexcept">
  23. <title><tt>noexcept</tt> <sign>C++98 only</sign></title>
  24. <p>A macro in C++98 mode, synonym for <tt>throw()</tt>. In other standard modes
  25. the definition is absent.</p>
  26. </chapter>
  27. <chapter xml:id="array_size">
  28. <title><tt>array_size()</tt></title>
  29. <code-block lang="C++"><![CDATA[
  30. template<class T, size_t N>
  31. constexpr size_t array_size(T (&array)[N]);
  32. ]]></code-block>
  33. <p>Returns number of elements in the array. Can be used as a compile-time
  34. expression.</p>
  35. <section><title>Example</title>
  36. <code-block lang="C++">
  37. int m[] = { 1, 2, 3, 5, 7 };
  38. size_t n = __vic::array_size(m); // n == 5
  39. int *dup = new int[n];
  40. </code-block>
  41. </section>
  42. </chapter>
  43. <chapter xml:id="non_copyable">
  44. <title><tt>non_copyable</tt></title>
  45. <code-block lang="C++"><![CDATA[
  46. class non_copyable
  47. {
  48. non_copyable(const non_copyable &) = delete;
  49. non_copyable &operator=(const non_copyable &) = delete;
  50. protected:
  51. non_copyable() = default;
  52. };
  53. ]]></code-block>
  54. <p>Inheriting of this class suppresses generation of copy constructor and
  55. copy assignment. Same as <tt>boost::noncopyable</tt>.</p>
  56. <section><title>Example</title>
  57. <code-block lang="C++">
  58. class C : private __vic::non_copyable
  59. {
  60. };
  61. C c1;
  62. C c2 = c1; // Error! Non-copyable object
  63. </code-block>
  64. </section>
  65. </chapter>
  66. <chapter xml:id="non_heap_allocatable">
  67. <title><tt>non_heap_allocatable</tt></title>
  68. <code-block lang="C++"><![CDATA[
  69. class non_heap_allocatable
  70. {
  71. void *operator new(std::size_t ) = delete;
  72. void *operator new(std::size_t , const std::nothrow_t & ) = delete;
  73. void *operator new[](std::size_t ) = delete;
  74. void *operator new[](std::size_t , const std::nothrow_t & ) = delete;
  75. protected:
  76. non_heap_allocatable() = default;
  77. };
  78. ]]></code-block>
  79. <p>Inheriting of this class prevents creation of the class object on a free
  80. store using operator <tt>new</tt>.</p>
  81. <section><title>Example</title>
  82. <code-block lang="C++">
  83. class C : private __vic::non_heap_allocatable
  84. {
  85. };
  86. C c; // Ok. Allocation on stack
  87. C *p = new C; // Error! Attempt to allocate on heap
  88. </code-block>
  89. </section>
  90. </chapter>
  91. <chapter xml:id="std--move">
  92. <title><tt>std::move()</tt>, <tt>std::forward()</tt>, <tt>std::swap()</tt>
  93. <sign>C++11</sign></title>
  94. <p>The header always includes this utilities in C++11 mode.</p>
  95. </chapter>
  96. <chapter xml:id="VIC_SWAP_HEADER">
  97. <title><tt>__VIC_SWAP_HEADER</tt></title>
  98. <p>A macro for <tt>#include</tt>. Expands to the header name that contains
  99. <tt>std::swap()</tt> definition, dependig on the used language standard.</p>
  100. <section><title>Example</title>
  101. <code-block lang="C++">
  102. #include __VIC_SWAP_HEADER
  103. </code-block>
  104. </section>
  105. </chapter>
  106. <chapter xml:id="platform-dependent-macros">
  107. <title>Platform-dependent macros</title>
  108. <p>The library provides set of compiler-independent macros that help to
  109. determine the target platform and some platform-specific traits by checking
  110. macro presence using <tt>#ifdef</tt>.</p>
  111. <p>List of hardware platforms (processors):</p>
  112. <list style="bulleted">
  113. <item><tt>__VIC_X86__</tt> - Intel x86 (IA32)</item>
  114. <item><tt>__VIC_X64__</tt> - x64 aka AMD 64</item>
  115. <item><tt>__VIC_IA64__</tt> - Intel IA64</item>
  116. <item><tt>__VIC_POWERPC__</tt> - PowerPC</item>
  117. </list>
  118. <p>Other macros:</p>
  119. <list style="bulleted">
  120. <item><tt>__VIC_STRICT_RAM_ALIGNMENT__</tt> - attempt to read unaligned
  121. data will cause bus error</item>
  122. </list>
  123. </chapter>
  124. </chapter>