mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
Split Utility/IdentityType and Functional/OverloadedFunction tests into smaller tests.
Updated docs for ScopeExit, LocalFunction, Utility/IdentityType, and Functional/OverloadedFunction. [SVN r77484]
This commit is contained in:
parent
5825b6c329
commit
2a6cd0c9c4
@ -2,7 +2,8 @@
|
|||||||
Caminiti</p></div><div><div class="legalnotice" title="Legal Notice"><a name="boost_utility_identitytype.legal"></a><p>
|
Caminiti</p></div><div><div class="legalnotice" title="Legal Notice"><a name="boost_utility_identitytype.legal"></a><p>
|
||||||
Distributed under the Boost Software License, Version 1.0 (see accompanying
|
Distributed under the Boost Software License, Version 1.0 (see accompanying
|
||||||
file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||||
</p></div></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#boost_utility_identitytype.motivation">Motivation</a></span></dt><dt><span class="section"><a href="#boost_utility_identitytype.solution">Solution</a></span></dt><dt><span class="section"><a href="#boost_utility_identitytype.templates">Templates</a></span></dt><dt><span class="section"><a href="#boost_utility_identitytype.abstract_types">Abstract Types</a></span></dt><dt><span class="section"><a href="#boost_utility_identitytype.annex__usage">Annex: Usage</a></span></dt><dt><span class="section"><a href="#boost_utility_identitytype.annex__implementation">Annex:
|
</p></div></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#boost_utility_identitytype.motivation">Motivation</a></span></dt><dt><span class="section"><a href="#boost_utility_identitytype.solution">Solution</a></span></dt><dt><span class="section"><a href="#boost_utility_identitytype.templates">Templates</a></span></dt><dt><span class="section"><a href="#boost_utility_identitytype.abstract_types">Abstract Types</a></span></dt><dt><span class="section"><a href="#boost_utility_identitytype.compilers_and_platforms">Compilers
|
||||||
|
and Platforms</a></span></dt><dt><span class="section"><a href="#boost_utility_identitytype.annex__usage">Annex: Usage</a></span></dt><dt><span class="section"><a href="#boost_utility_identitytype.annex__implementation">Annex:
|
||||||
Implementation</a></span></dt><dt><span class="section"><a href="#reference">Reference</a></span></dt></dl></div><p>
|
Implementation</a></span></dt><dt><span class="section"><a href="#reference">Reference</a></span></dt></dl></div><p>
|
||||||
This library allows to wrap type expressions within round parenthesis so they
|
This library allows to wrap type expressions within round parenthesis so they
|
||||||
can be passed to macros even when they contain commas.
|
can be passed to macros even when they contain commas.
|
||||||
@ -126,7 +127,7 @@
|
|||||||
to pass a meta-function with multiple template parameters to the assert macro
|
to pass a meta-function with multiple template parameters to the assert macro
|
||||||
(so to handle the commas separating the template parameters). In this case,
|
(so to handle the commas separating the template parameters). In this case,
|
||||||
if the meta-function is an abstract type, it needs to be manipulated adding
|
if the meta-function is an abstract type, it needs to be manipulated adding
|
||||||
and removing a reference to it (see also <a href="../../test/tmp_assert.cpp" target="_top"><code class="literal">tmp_assert.cpp</code></a>):
|
and removing a reference to it (see also <a href="../../test/abstract.cpp" target="_top"><code class="literal">abstract.cpp</code></a>):
|
||||||
</p><p>
|
</p><p>
|
||||||
</p><pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">TMP_ASSERT</span><span class="special">(</span><span class="identifier">metafunction</span><span class="special">)</span> <span class="special">\</span>
|
</p><pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">TMP_ASSERT</span><span class="special">(</span><span class="identifier">metafunction</span><span class="special">)</span> <span class="special">\</span>
|
||||||
<span class="identifier">BOOST_STATIC_ASSERT</span><span class="special">(</span><span class="identifier">metafunction</span><span class="special">::</span><span class="identifier">value</span><span class="special">)</span>
|
<span class="identifier">BOOST_STATIC_ASSERT</span><span class="special">(</span><span class="identifier">metafunction</span><span class="special">::</span><span class="identifier">value</span><span class="special">)</span>
|
||||||
@ -147,20 +148,36 @@
|
|||||||
<span class="special">>::</span><span class="identifier">type</span>
|
<span class="special">>::</span><span class="identifier">type</span>
|
||||||
<span class="special">);</span>
|
<span class="special">);</span>
|
||||||
</pre><p>
|
</pre><p>
|
||||||
|
</p></div><div class="section boost_utility_identitytype_compilers_and_platforms" title="Compilers and Platforms"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="boost_utility_identitytype.compilers_and_platforms"></a><a class="link" href="#boost_utility_identitytype.compilers_and_platforms" title="Compilers and Platforms">Compilers
|
||||||
|
and Platforms</a></h2></div></div></div><p>
|
||||||
|
The authors originally developed and tested the library on:
|
||||||
|
</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||||
|
GNU Compiler Collection (GCC) C++ 4.5.3 (with and without C++11 features
|
||||||
|
enabled <code class="computeroutput"><span class="special">-</span><span class="identifier">std</span><span class="special">=</span><span class="identifier">c</span><span class="special">++</span><span class="number">0</span><span class="identifier">x</span></code>) on
|
||||||
|
Cygwin.
|
||||||
|
</li><li class="listitem">
|
||||||
|
Miscrosoft Visual C++ (MSVC) 8.0 on Windows 7.
|
||||||
|
</li></ol></div><p>
|
||||||
|
See the library <a href="http://www.boost.org/development/tests/release/developer/utility-identity_type.html" target="_top">regressions
|
||||||
|
test results</a> for detailed information on supported compilers and platforms.
|
||||||
</p></div><div class="section boost_utility_identitytype_annex__usage" title="Annex: Usage"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="boost_utility_identitytype.annex__usage"></a><a class="link" href="#boost_utility_identitytype.annex__usage" title="Annex: Usage">Annex: Usage</a></h2></div></div></div><p>
|
</p></div><div class="section boost_utility_identitytype_annex__usage" title="Annex: Usage"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="boost_utility_identitytype.annex__usage"></a><a class="link" href="#boost_utility_identitytype.annex__usage" title="Annex: Usage">Annex: Usage</a></h2></div></div></div><p>
|
||||||
The <code class="computeroutput"><a class="link" href="#BOOST_IDENTITY_TYPE" title="Macro BOOST_IDENTITY_TYPE">BOOST_IDENTITY_TYPE</a></code> macro
|
The <code class="computeroutput"><a class="link" href="#BOOST_IDENTITY_TYPE" title="Macro BOOST_IDENTITY_TYPE">BOOST_IDENTITY_TYPE</a></code> macro
|
||||||
can be used either when calling a user-defined macro (as shown by the examples
|
can be used either when calling a user-defined macro (as shown by the examples
|
||||||
so far), or internally in the definition of a user-defined macro (as shown
|
so far), or internally in the definition of a user-defined macro (as shown
|
||||||
below). When <code class="computeroutput"><a class="link" href="#BOOST_IDENTITY_TYPE" title="Macro BOOST_IDENTITY_TYPE">BOOST_IDENTITY_TYPE</a></code>
|
below). When <code class="computeroutput"><a class="link" href="#BOOST_IDENTITY_TYPE" title="Macro BOOST_IDENTITY_TYPE">BOOST_IDENTITY_TYPE</a></code>
|
||||||
is used in the user macro definition, the call of the user macro will only
|
is used in the user macro definition, the call of the user macro will only
|
||||||
have to specify the extra parenthesis (see also <a href="../../test/tmp_assert.cpp" target="_top"><code class="literal">tmp_assert.cpp</code></a>):
|
have to specify the extra parenthesis (see also <a href="../../test/paren.cpp" target="_top"><code class="literal">paren.cpp</code></a>):
|
||||||
</p><p>
|
</p><p>
|
||||||
</p><pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">TMP_ASSERT_PAREN</span><span class="special">(</span><span class="identifier">parenthesized_metafunction</span><span class="special">)</span> <span class="special">\</span>
|
</p><pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">TMP_ASSERT_PAREN</span><span class="special">(</span><span class="identifier">parenthesized_metafunction</span><span class="special">)</span> <span class="special">\</span>
|
||||||
<span class="comment">/* use `BOOST_IDENTITY_TYPE` in macro definition instead of invocation */</span> <span class="special">\</span>
|
<span class="comment">/* use `BOOST_IDENTITY_TYPE` in macro definition instead of invocation */</span> <span class="special">\</span>
|
||||||
<span class="identifier">BOOST_STATIC_ASSERT</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(</span><span class="identifier">parenthesized_metafunction</span><span class="special">)::</span><span class="identifier">value</span><span class="special">)</span>
|
<span class="identifier">BOOST_STATIC_ASSERT</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(</span><span class="identifier">parenthesized_metafunction</span><span class="special">)::</span><span class="identifier">value</span><span class="special">)</span>
|
||||||
|
|
||||||
|
<span class="preprocessor">#define</span> <span class="identifier">TMP_ASSERT</span><span class="special">(</span><span class="identifier">metafunction</span><span class="special">)</span> <span class="special">\</span>
|
||||||
|
<span class="identifier">BOOST_STATIC_ASSERT</span><span class="special">(</span><span class="identifier">metafunction</span><span class="special">::</span><span class="identifier">value</span><span class="special">)</span>
|
||||||
|
|
||||||
<span class="comment">// Specify only extra parenthesis `((...))`.</span>
|
<span class="comment">// Specify only extra parenthesis `((...))`.</span>
|
||||||
<span class="identifier">TMP_ASSERT_PAREN</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_const</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">></span> <span class="keyword">const</span><span class="special">>));</span>
|
<span class="identifier">TMP_ASSERT_PAREN</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_const</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">></span> <span class="keyword">const</span><span class="special">>));</span>
|
||||||
|
|
||||||
<span class="comment">// Specify both the extra parenthesis `((...))` and `BOOST_IDENTITY_TYPE` macro.</span>
|
<span class="comment">// Specify both the extra parenthesis `((...))` and `BOOST_IDENTITY_TYPE` macro.</span>
|
||||||
<span class="identifier">TMP_ASSERT</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_const</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">></span> <span class="keyword">const</span><span class="special">>)));</span>
|
<span class="identifier">TMP_ASSERT</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_const</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">></span> <span class="keyword">const</span><span class="special">>)));</span>
|
||||||
</pre><p>
|
</pre><p>
|
||||||
@ -169,6 +186,7 @@
|
|||||||
the extra parenthesis even when the macro parameters contain no comma:
|
the extra parenthesis even when the macro parameters contain no comma:
|
||||||
</p><p>
|
</p><p>
|
||||||
</p><pre class="programlisting"><span class="identifier">TMP_ASSERT_PAREN</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_const</span><span class="special"><</span><span class="keyword">int</span> <span class="keyword">const</span><span class="special">>));</span> <span class="comment">// Always extra `((...))`.</span>
|
</p><pre class="programlisting"><span class="identifier">TMP_ASSERT_PAREN</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_const</span><span class="special"><</span><span class="keyword">int</span> <span class="keyword">const</span><span class="special">>));</span> <span class="comment">// Always extra `((...))`.</span>
|
||||||
|
|
||||||
<span class="identifier">TMP_ASSERT</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_const</span><span class="special"><</span><span class="keyword">int</span> <span class="keyword">const</span><span class="special">>);</span> <span class="comment">// No extra `((...))` and no macro.</span>
|
<span class="identifier">TMP_ASSERT</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_const</span><span class="special"><</span><span class="keyword">int</span> <span class="keyword">const</span><span class="special">>);</span> <span class="comment">// No extra `((...))` and no macro.</span>
|
||||||
</pre><p>
|
</pre><p>
|
||||||
</p><p>
|
</p><p>
|
||||||
@ -221,7 +239,7 @@
|
|||||||
|
|
||||||
<a class="link" href="#BOOST_IDENTITY_TYPE" title="Macro BOOST_IDENTITY_TYPE">BOOST_IDENTITY_TYPE</a>(parenthesized_type)</pre><div class="refentry" title="Macro BOOST_IDENTITY_TYPE"><a name="BOOST_IDENTITY_TYPE"></a><div class="titlepage"></div><div class="refnamediv"><h2><span class="refentrytitle">Macro BOOST_IDENTITY_TYPE</span></h2><p>BOOST_IDENTITY_TYPE — This macro allows to wrap the specified type expression within extra round parenthesis so the type can be passed as a single macro parameter even if it contains commas (not already wrapped within round parenthesis). </p></div><h2 class="refsynopsisdiv-title">Synopsis</h2><div class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: <<a class="link" href="#header.boost.utility.identity_type_hpp" title="Header <boost/utility/identity_type.hpp>">boost/utility/identity_type.hpp</a>>
|
<a class="link" href="#BOOST_IDENTITY_TYPE" title="Macro BOOST_IDENTITY_TYPE">BOOST_IDENTITY_TYPE</a>(parenthesized_type)</pre><div class="refentry" title="Macro BOOST_IDENTITY_TYPE"><a name="BOOST_IDENTITY_TYPE"></a><div class="titlepage"></div><div class="refnamediv"><h2><span class="refentrytitle">Macro BOOST_IDENTITY_TYPE</span></h2><p>BOOST_IDENTITY_TYPE — This macro allows to wrap the specified type expression within extra round parenthesis so the type can be passed as a single macro parameter even if it contains commas (not already wrapped within round parenthesis). </p></div><h2 class="refsynopsisdiv-title">Synopsis</h2><div class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: <<a class="link" href="#header.boost.utility.identity_type_hpp" title="Header <boost/utility/identity_type.hpp>">boost/utility/identity_type.hpp</a>>
|
||||||
|
|
||||||
</span>BOOST_IDENTITY_TYPE(parenthesized_type)</pre></div><div class="refsect1" title="Description"><a name="id512092"></a><h2>Description</h2><p><span class="bold"><strong>Parameters:</strong></span> </p><div class="informaltable"><table class="table"><colgroup><col><col></colgroup><tbody><tr><td><span class="bold"><strong><code class="computeroutput">parenthesized_type</code></strong></span></td><td>The type expression to be passed as macro parameter wrapped by a single set of round parenthesis <code class="computeroutput">(...)</code>. This type expression can contain an arbitrary number of commas. </td></tr></tbody></table></div><p>
|
</span>BOOST_IDENTITY_TYPE(parenthesized_type)</pre></div><div class="refsect1" title="Description"><a name="id558453"></a><h2>Description</h2><p><span class="bold"><strong>Parameters:</strong></span> </p><div class="informaltable"><table class="table"><colgroup><col><col></colgroup><tbody><tr><td><span class="bold"><strong><code class="computeroutput">parenthesized_type</code></strong></span></td><td>The type expression to be passed as macro parameter wrapped by a single set of round parenthesis <code class="computeroutput">(...)</code>. This type expression can contain an arbitrary number of commas. </td></tr></tbody></table></div><p>
|
||||||
</p><p>This macro works on any C++03 compiler (it does not require variadic macros).</p><p>This macro must be prefixed by <code class="computeroutput">typename</code> when used within templates. However, the compiler will not be able to automatically determine function template parameters when they are wrapped with this macro (these parameters need to be explicitly specified when calling the function template).</p><p>On some compilers (like GCC), using this macro on an abstract types requires to add and remove a reference to the type. </p></div></div></div></div><div class="footnotes"><br><hr width="100" align="left"><div class="footnote"><p><sup>[<a id="ftn.boost_utility_identitytype.solution.f0" href="#boost_utility_identitytype.solution.f0" class="para">1</a>] </sup>
|
</p><p>This macro works on any C++03 compiler (it does not require variadic macros).</p><p>This macro must be prefixed by <code class="computeroutput">typename</code> when used within templates. However, the compiler will not be able to automatically determine function template parameters when they are wrapped with this macro (these parameters need to be explicitly specified when calling the function template).</p><p>On some compilers (like GCC), using this macro on an abstract types requires to add and remove a reference to the type. </p></div></div></div></div><div class="footnotes"><br><hr width="100" align="left"><div class="footnote"><p><sup>[<a id="ftn.boost_utility_identitytype.solution.f0" href="#boost_utility_identitytype.solution.f0" class="para">1</a>] </sup>
|
||||||
Using variadic macros, it would be possible to require a single set of extra
|
Using variadic macros, it would be possible to require a single set of extra
|
||||||
parenthesis <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(</span></code><code class="literal"><span class="emphasis"><em>type</em></span></code><code class="computeroutput"><span class="special">)</span></code> instead of two <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span></code><code class="literal"><span class="emphasis"><em>type</em></span></code><code class="computeroutput"><span class="special">))</span></code> but variadic macros are not part of C++03
|
parenthesis <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(</span></code><code class="literal"><span class="emphasis"><em>type</em></span></code><code class="computeroutput"><span class="special">)</span></code> instead of two <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span></code><code class="literal"><span class="emphasis"><em>type</em></span></code><code class="computeroutput"><span class="special">))</span></code> but variadic macros are not part of C++03
|
||||||
|
@ -24,7 +24,8 @@ This library allows to wrap type expressions within round parenthesis so they ca
|
|||||||
[import ../test/var_error.cpp]
|
[import ../test/var_error.cpp]
|
||||||
[import ../test/var.cpp]
|
[import ../test/var.cpp]
|
||||||
[import ../test/template.cpp]
|
[import ../test/template.cpp]
|
||||||
[import ../test/tmp_assert.cpp]
|
[import ../test/abstract.cpp]
|
||||||
|
[import ../test/paren.cpp]
|
||||||
|
|
||||||
[section Motivation]
|
[section Motivation]
|
||||||
|
|
||||||
@ -101,22 +102,33 @@ This can be worked around by manipulating the type adding and removing a referen
|
|||||||
|
|
||||||
Let's program a macro that performs a static assertion on a [@http://en.wikipedia.org/wiki/Template_metaprogramming Template Meta-Programming] (TMP) meta-function (similarly to Boost.MPL [@http://www.boost.org/doc/libs/1_36_0/libs/mpl/doc/refmanual/assert.html `BOOST_MPL_ASSERT`]).
|
Let's program a macro that performs a static assertion on a [@http://en.wikipedia.org/wiki/Template_metaprogramming Template Meta-Programming] (TMP) meta-function (similarly to Boost.MPL [@http://www.boost.org/doc/libs/1_36_0/libs/mpl/doc/refmanual/assert.html `BOOST_MPL_ASSERT`]).
|
||||||
The [macroref BOOST_IDENTITY_TYPE] macro can be used to pass a meta-function with multiple template parameters to the assert macro (so to handle the commas separating the template parameters).
|
The [macroref BOOST_IDENTITY_TYPE] macro can be used to pass a meta-function with multiple template parameters to the assert macro (so to handle the commas separating the template parameters).
|
||||||
In this case, if the meta-function is an abstract type, it needs to be manipulated adding and removing a reference to it (see also [@../../test/tmp_assert.cpp =tmp_assert.cpp=]):
|
In this case, if the meta-function is an abstract type, it needs to be manipulated adding and removing a reference to it (see also [@../../test/abstract.cpp =abstract.cpp=]):
|
||||||
|
|
||||||
[tmp_assert_abstract]
|
[abstract]
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[section Compilers and Platforms]
|
||||||
|
|
||||||
|
The authors originally developed and tested the library on:
|
||||||
|
|
||||||
|
# GNU Compiler Collection (GCC) C++ 4.5.3 (with and without C++11 features enabled `-std=c++0x`) on Cygwin.
|
||||||
|
# Miscrosoft Visual C++ (MSVC) 8.0 on Windows 7.
|
||||||
|
|
||||||
|
See the library [@http://www.boost.org/development/tests/release/developer/utility-identity_type.html regressions test results] for detailed information on supported compilers and platforms.
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section Annex: Usage]
|
[section Annex: Usage]
|
||||||
|
|
||||||
The [macroref BOOST_IDENTITY_TYPE] macro can be used either when calling a user-defined macro (as shown by the examples so far), or internally in the definition of a user-defined macro (as shown below).
|
The [macroref BOOST_IDENTITY_TYPE] macro can be used either when calling a user-defined macro (as shown by the examples so far), or internally in the definition of a user-defined macro (as shown below).
|
||||||
When [macroref BOOST_IDENTITY_TYPE] is used in the user macro definition, the call of the user macro will only have to specify the extra parenthesis (see also [@../../test/tmp_assert.cpp =tmp_assert.cpp=]):
|
When [macroref BOOST_IDENTITY_TYPE] is used in the user macro definition, the call of the user macro will only have to specify the extra parenthesis (see also [@../../test/paren.cpp =paren.cpp=]):
|
||||||
|
|
||||||
[tmp_assert_alternative]
|
[paren]
|
||||||
|
|
||||||
However, note that the user will /always/ have to specify the extra parenthesis even when the macro parameters contain no comma:
|
However, note that the user will /always/ have to specify the extra parenthesis even when the macro parameters contain no comma:
|
||||||
|
|
||||||
[tmp_assert_alternative_always]
|
[paren_always]
|
||||||
|
|
||||||
In some cases, using [macroref BOOST_IDENTITY_TYPE] within the user macro definition might provide the best syntax for the user.
|
In some cases, using [macroref BOOST_IDENTITY_TYPE] within the user macro definition might provide the best syntax for the user.
|
||||||
For example, this is the case for `BOOST_MPL_ASSERT` because the majority of template meta-programming expressions contain unwrapped commas so it is less confusing for the user to always specify the extra parenthesis `((...))` instead of using [macroref BOOST_IDENTITY_TYPE]:
|
For example, this is the case for `BOOST_MPL_ASSERT` because the majority of template meta-programming expressions contain unwrapped commas so it is less confusing for the user to always specify the extra parenthesis `((...))` instead of using [macroref BOOST_IDENTITY_TYPE]:
|
||||||
|
@ -10,5 +10,7 @@ import testing ;
|
|||||||
compile-fail var_error.cpp ;
|
compile-fail var_error.cpp ;
|
||||||
run var.cpp ;
|
run var.cpp ;
|
||||||
run template.cpp ;
|
run template.cpp ;
|
||||||
run tmp_assert.cpp ;
|
run abstract.cpp ;
|
||||||
|
run noncopyable.cpp ;
|
||||||
|
run paren.cpp ;
|
||||||
|
|
||||||
|
35
identity_type/test/abstract.cpp
Normal file
35
identity_type/test/abstract.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
// Copyright (C) 2009-2012 Lorenzo Caminiti
|
||||||
|
// Distributed under the Boost Software License, Version 1.0
|
||||||
|
// (see accompanying file LICENSE_1_0.txt or a copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
// Home at http://www.boost.org/libs/utility/identity_type
|
||||||
|
|
||||||
|
#include <boost/utility/identity_type.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/type_traits/add_reference.hpp>
|
||||||
|
#include <boost/type_traits/remove_reference.hpp>
|
||||||
|
|
||||||
|
//[abstract
|
||||||
|
#define TMP_ASSERT(metafunction) \
|
||||||
|
BOOST_STATIC_ASSERT(metafunction::value)
|
||||||
|
|
||||||
|
template<typename T, bool b>
|
||||||
|
struct abstract {
|
||||||
|
static const bool value = b;
|
||||||
|
virtual void f(T const& x) = 0; // Pure virtual function.
|
||||||
|
};
|
||||||
|
|
||||||
|
TMP_ASSERT(
|
||||||
|
boost::remove_reference< // Add and remove
|
||||||
|
BOOST_IDENTITY_TYPE(( // reference for
|
||||||
|
boost::add_reference< // abstract type.
|
||||||
|
abstract<int, true>
|
||||||
|
>::type
|
||||||
|
))
|
||||||
|
>::type
|
||||||
|
);
|
||||||
|
//]
|
||||||
|
|
||||||
|
int main() { return 0; }
|
||||||
|
|
25
identity_type/test/noncopyable.cpp
Normal file
25
identity_type/test/noncopyable.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
// Copyright (C) 2009-2012 Lorenzo Caminiti
|
||||||
|
// Distributed under the Boost Software License, Version 1.0
|
||||||
|
// (see accompanying file LICENSE_1_0.txt or a copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
// Home at http://www.boost.org/libs/utility/identity_type
|
||||||
|
|
||||||
|
#include <boost/utility/identity_type.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
|
//[noncopyable
|
||||||
|
#define TMP_ASSERT(metafunction) \
|
||||||
|
BOOST_STATIC_ASSERT(metafunction::value)
|
||||||
|
|
||||||
|
template<typename T, T init>
|
||||||
|
struct noncopyable : boost::noncopyable {
|
||||||
|
static const T value = init;
|
||||||
|
};
|
||||||
|
|
||||||
|
TMP_ASSERT(BOOST_IDENTITY_TYPE((noncopyable<bool, true>)));
|
||||||
|
//]
|
||||||
|
|
||||||
|
int main() { return 0; }
|
||||||
|
|
@ -8,44 +8,26 @@
|
|||||||
#include <boost/utility/identity_type.hpp>
|
#include <boost/utility/identity_type.hpp>
|
||||||
#include <boost/static_assert.hpp>
|
#include <boost/static_assert.hpp>
|
||||||
#include <boost/type_traits/is_const.hpp>
|
#include <boost/type_traits/is_const.hpp>
|
||||||
#include <boost/type_traits/add_reference.hpp>
|
|
||||||
#include <boost/type_traits/remove_reference.hpp>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
//[tmp_assert_abstract
|
//[paren
|
||||||
#define TMP_ASSERT(metafunction) \
|
|
||||||
BOOST_STATIC_ASSERT(metafunction::value)
|
|
||||||
|
|
||||||
template<typename T, bool b>
|
|
||||||
struct abstract {
|
|
||||||
static const bool value = b;
|
|
||||||
virtual void f(T const& x) = 0; // Pure virtual function.
|
|
||||||
};
|
|
||||||
|
|
||||||
TMP_ASSERT(
|
|
||||||
boost::remove_reference< // Add and remove
|
|
||||||
BOOST_IDENTITY_TYPE(( // reference for
|
|
||||||
boost::add_reference< // abstract type.
|
|
||||||
abstract<int, true>
|
|
||||||
>::type
|
|
||||||
))
|
|
||||||
>::type
|
|
||||||
);
|
|
||||||
//]
|
|
||||||
|
|
||||||
//[tmp_assert_alternative
|
|
||||||
#define TMP_ASSERT_PAREN(parenthesized_metafunction) \
|
#define TMP_ASSERT_PAREN(parenthesized_metafunction) \
|
||||||
/* use `BOOST_IDENTITY_TYPE` in macro definition instead of invocation */ \
|
/* use `BOOST_IDENTITY_TYPE` in macro definition instead of invocation */ \
|
||||||
BOOST_STATIC_ASSERT(BOOST_IDENTITY_TYPE(parenthesized_metafunction)::value)
|
BOOST_STATIC_ASSERT(BOOST_IDENTITY_TYPE(parenthesized_metafunction)::value)
|
||||||
|
|
||||||
|
#define TMP_ASSERT(metafunction) \
|
||||||
|
BOOST_STATIC_ASSERT(metafunction::value)
|
||||||
|
|
||||||
// Specify only extra parenthesis `((...))`.
|
// Specify only extra parenthesis `((...))`.
|
||||||
TMP_ASSERT_PAREN((boost::is_const<std::map<int, char> const>));
|
TMP_ASSERT_PAREN((boost::is_const<std::map<int, char> const>));
|
||||||
|
|
||||||
// Specify both the extra parenthesis `((...))` and `BOOST_IDENTITY_TYPE` macro.
|
// Specify both the extra parenthesis `((...))` and `BOOST_IDENTITY_TYPE` macro.
|
||||||
TMP_ASSERT(BOOST_IDENTITY_TYPE((boost::is_const<std::map<int, char> const>)));
|
TMP_ASSERT(BOOST_IDENTITY_TYPE((boost::is_const<std::map<int, char> const>)));
|
||||||
//]
|
//]
|
||||||
|
|
||||||
//[tmp_assert_alternative_always
|
//[paren_always
|
||||||
TMP_ASSERT_PAREN((boost::is_const<int const>)); // Always extra `((...))`.
|
TMP_ASSERT_PAREN((boost::is_const<int const>)); // Always extra `((...))`.
|
||||||
|
|
||||||
TMP_ASSERT(boost::is_const<int const>); // No extra `((...))` and no macro.
|
TMP_ASSERT(boost::is_const<int const>); // No extra `((...))` and no macro.
|
||||||
//]
|
//]
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user