rationale.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Rationale</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.FunctionTypes 2.5">
  8. <link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.FunctionTypes 2.5">
  9. <link rel="prev" href="reference/macros.html" title="Macros">
  10. <link rel="next" href="acknowledgements.html" title="Acknowledgements">
  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="reference/macros.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="acknowledgements.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_functiontypes.rationale"></a><a class="link" href="rationale.html" title="Rationale">Rationale</a>
  28. </h2></div></div></div>
  29. <h4>
  30. <a name="boost_functiontypes.rationale.h0"></a>
  31. <span class="phrase"><a name="boost_functiontypes.rationale.error_handling_rationale"></a></span><a class="link" href="rationale.html#boost_functiontypes.rationale.error_handling_rationale">Error handling
  32. rationale</a>
  33. </h4>
  34. <p>
  35. The library does not define the required members of class templates in case
  36. of an error. This technique causes the compiler to stop displaying diagnostics
  37. in client code, at the point where the error actually is, instead of tracing
  38. template instantiations into the implementation of the library.
  39. </p>
  40. <p>
  41. The library's components have limited error conditions, so problematic input
  42. can be spotted easily.
  43. </p>
  44. <h4>
  45. <a name="boost_functiontypes.rationale.h1"></a>
  46. <span class="phrase"><a name="boost_functiontypes.rationale.why_mpl_sequences_"></a></span><a class="link" href="rationale.html#boost_functiontypes.rationale.why_mpl_sequences_">Why
  47. MPL Sequences?</a>
  48. </h4>
  49. <p>
  50. MPL provides algorithms on Sequences, so transformations (such as turning by-value
  51. parameter types into const references for optimized forwarding or computing
  52. a signature to specialize <a href="../../../../function/index.html" target="_top"><code class="literal">boost::function</code></a>
  53. after applying <a href="../../../../bind/index.html" target="_top"><code class="literal">boost::bind</code></a>)
  54. can be expressed more easily. The MPL Sequence concept is compatible with several
  55. other Boost libraries (most importantly <a href="../../../../fusion/index.html" target="_top">Fusion</a>),
  56. so another reason is interoperability.
  57. </p>
  58. <h4>
  59. <a name="boost_functiontypes.rationale.h2"></a>
  60. <span class="phrase"><a name="boost_functiontypes.rationale.pointer_to_member_object_types"></a></span><a class="link" href="rationale.html#boost_functiontypes.rationale.pointer_to_member_object_types">Pointer
  61. to member object types</a>
  62. </h4>
  63. <p>
  64. Despite their syntax, pointer to member object types can be seen as dereferencing
  65. functionals.
  66. </p>
  67. <h4>
  68. <a name="boost_functiontypes.rationale.h3"></a>
  69. <span class="phrase"><a name="boost_functiontypes.rationale.the_classtransform_template_parameter"></a></span><a class="link" href="rationale.html#boost_functiontypes.rationale.the_classtransform_template_parameter">The
  70. ClassTransform template parameter</a>
  71. </h4>
  72. <p>
  73. <code class="literal">This</code>-pointer, <code class="literal">this</code>-reference or just
  74. the object (or maybe even a smart pointer to the object) plus adjustments of
  75. cv-qualification - all these cases have their place, somewhere and there is
  76. no single best answer.
  77. </p>
  78. <p>
  79. Special treatment of the class type within the sequence can significantly complicate
  80. client code. A custom <code class="literal">ClassTransform</code> argument allows the
  81. client to adjust the class type before the sequence is formed and then treat
  82. all parameters uniformly.
  83. </p>
  84. <h4>
  85. <a name="boost_functiontypes.rationale.h4"></a>
  86. <span class="phrase"><a name="boost_functiontypes.rationale.why_tag_types_"></a></span><a class="link" href="rationale.html#boost_functiontypes.rationale.why_tag_types_">Why
  87. tag types?</a>
  88. </h4>
  89. <p>
  90. Let's consider the alternatives.
  91. </p>
  92. <p>
  93. The first one is just using more templates so every property has to be asked
  94. for explicitly. This approach results in more complicated client code if more
  95. than one propery has to be checked and in a exponentially larger library interface.
  96. </p>
  97. <p>
  98. The second alternative is having the client pass in bit patterns via non-type
  99. template parameters. The logic has to be performed by the client and there
  100. are much more error conditions. Further, class templates with non-type template
  101. parameters do not work within MPL lambda expressions and can cause problems
  102. with older compilers.
  103. </p>
  104. <h4>
  105. <a name="boost_functiontypes.rationale.h5"></a>
  106. <span class="phrase"><a name="boost_functiontypes.rationale.is_it_safe_to_have_the_synthesis_templates_take_a_callable__builtin_type_or_an_mpl_sequence_as_the_first_template_argument_"></a></span><a class="link" href="rationale.html#boost_functiontypes.rationale.is_it_safe_to_have_the_synthesis_templates_take_a_callable__builtin_type_or_an_mpl_sequence_as_the_first_template_argument_">Is
  107. it safe to have the synthesis templates take a callable builtin type or an
  108. MPL sequence as the first template argument?</a>
  109. </h4>
  110. <p>
  111. Yes, but it isn't immediately obvious as the set of possible MPL sequences
  112. isn't inherently disjoint from the set of callable builtin types.
  113. </p>
  114. <p>
  115. However, any attempt to make a builtin type work as an MPL sequence is a bad
  116. idea, because builtin types are accessible before the headers that make the
  117. type a sequence have been included, which can easily violate the ODR.
  118. </p>
  119. <h4>
  120. <a name="boost_functiontypes.rationale.h6"></a>
  121. <span class="phrase"><a name="boost_functiontypes.rationale.why_does_the_hidden__literal_this__literal__parameter_count_for_the__function_arity_of_member_functions_"></a></span><a class="link" href="rationale.html#boost_functiontypes.rationale.why_does_the_hidden__literal_this__literal__parameter_count_for_the__function_arity_of_member_functions_">Why
  122. does the hidden <code class="literal">this</code> parameter count for the function arity
  123. of member functions?</a>
  124. </h4>
  125. <p>
  126. It was found preferable that the following condition holds:
  127. </p>
  128. <pre class="programlisting"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">size</span><span class="special">&lt;</span> <a class="link" href="reference/decomposition.html#boost_functiontypes.reference.decomposition.parameter_types" title="parameter_types">parameter_types</a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">&gt;::</span><span class="identifier">value</span> <span class="special">==</span> <a class="link" href="reference/decomposition.html#boost_functiontypes.reference.decomposition.function_arity" title="function_arity">function_arity</a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span>
  129. </pre>
  130. <h4>
  131. <a name="boost_functiontypes.rationale.h7"></a>
  132. <span class="phrase"><a name="boost_functiontypes.rationale.why_ignore_top_level_cv_qualifiers_on_pointers_"></a></span><a class="link" href="rationale.html#boost_functiontypes.rationale.why_ignore_top_level_cv_qualifiers_on_pointers_">Why
  133. ignore top-level cv-qualifiers on pointers?</a>
  134. </h4>
  135. <p>
  136. A cv-qualified pointer is still a pointer. It usually doesn't matter and even
  137. if it does, it's a job for <a href="../../../../type_traits/index.html" target="_top">Boost.TypeTraits</a>.
  138. </p>
  139. </div>
  140. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  141. <td align="left"></td>
  142. <td align="right"><div class="copyright-footer">Copyright &#169; 2004-2007 Tobias
  143. Schwinger<p>
  144. Distributed under the Boost Software License, Version 1.0. (See accompanying
  145. 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>)
  146. </p>
  147. </div></td>
  148. </tr></table>
  149. <hr>
  150. <div class="spirit-nav">
  151. <a accesskey="p" href="reference/macros.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="acknowledgements.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  152. </div>
  153. </body>
  154. </html>