forked from boostorg/config
added documentation for BOOST_EXPLICIT_TEMPLATE_TYPE & Co.
[SVN r18762]
This commit is contained in:
56
config.htm
56
config.htm
@ -911,6 +911,62 @@ void g() { return f(); }</pre>
|
|||||||
x;</font> if the compiler requires a return, even when it can never be
|
x;</font> if the compiler requires a return, even when it can never be
|
||||||
reached.</td>
|
reached.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>BOOST_EXPLICIT_TEMPLATE_TYPE(t)<br>
|
||||||
|
BOOST_EXPLICIT_TEMPLATE_NON_TYPE(t, v)<br>
|
||||||
|
|
||||||
|
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(t)<br>
|
||||||
|
BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)<br>
|
||||||
|
</td>
|
||||||
|
<td>Some compilers silently "fold" different function template
|
||||||
|
instantiations if some of the template parameters don't appear
|
||||||
|
in the function parameter list. For instance:
|
||||||
|
<pre>
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
template <int n>
|
||||||
|
void f() { std::cout << n << ' '; }
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void g() { std::cout << typeid(T).name() << ' '; }
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
f<1>();
|
||||||
|
f<2>();
|
||||||
|
|
||||||
|
g<int>();
|
||||||
|
g<double>();
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
incorrectly outputs <tt>"2 2 double double "</tt> on VC++ 6.
|
||||||
|
|
||||||
|
These macros, to be used in the function parameter list, fix the
|
||||||
|
problem without effects on the calling syntax. For instance, in
|
||||||
|
the case above write:
|
||||||
|
<pre>
|
||||||
|
template <int n>
|
||||||
|
void f(BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int, n)) { ... }
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void g(BOOST_EXPLICIT_TEMPLATE_TYPE(T)) { ... }
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
Beware that they can declare (for affected compilers) a dummy <i>
|
||||||
|
defaulted</i> parameter, so they
|
||||||
|
<br><br>a) should be always invoked *at the end* of the parameter list
|
||||||
|
<br> b) can't be used if your function template is multiply declared.
|
||||||
|
<br><br>
|
||||||
|
|
||||||
|
Furthermore, in order to add any needed comma separator, an "APPEND_*"
|
||||||
|
version must be used when the macro invocation appears after a normal
|
||||||
|
parameter declaration or after the invocation of another macro of this
|
||||||
|
same group.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td valign="top" width="50%">BOOST_USE_FACET(Type, loc)</td>
|
<td valign="top" width="50%">BOOST_USE_FACET(Type, loc)</td>
|
||||||
<td valign="top" width="50%">When the standard library does not have a comforming
|
<td valign="top" width="50%">When the standard library does not have a comforming
|
||||||
|
Reference in New Issue
Block a user