forked from boostorg/bind
__cdecl support added.
[SVN r27590]
This commit is contained in:
35
bind.html
35
bind.html
@@ -76,8 +76,8 @@
|
|||||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#Files">Files</A></h4>
|
<h4 style="MARGIN-LEFT: 40pt"><A href="#Files">Files</A></h4>
|
||||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#Dependencies">Dependencies</A></h4>
|
<h4 style="MARGIN-LEFT: 40pt"><A href="#Dependencies">Dependencies</A></h4>
|
||||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#NumberOfArguments">Number of Arguments</A></h4>
|
<h4 style="MARGIN-LEFT: 40pt"><A href="#NumberOfArguments">Number of Arguments</A></h4>
|
||||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#stdcall">"__stdcall", "__fastcall", and
|
<h4 style="MARGIN-LEFT: 40pt"><A href="#stdcall">"__stdcall", "__cdecl", "__fastcall",
|
||||||
"pascal" Support</A></h4>
|
and "pascal" Support</A></h4>
|
||||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#visit_each"><b>visit_each</b> support</A></h4>
|
<h4 style="MARGIN-LEFT: 40pt"><A href="#visit_each"><b>visit_each</b> support</A></h4>
|
||||||
<h3 style="MARGIN-LEFT: 20pt"><A href="#Acknowledgements">Acknowledgements</A></h3>
|
<h3 style="MARGIN-LEFT: 20pt"><A href="#Acknowledgements">Acknowledgements</A></h3>
|
||||||
<h2><a name="Purpose">Purpose</a></h2>
|
<h2><a name="Purpose">Purpose</a></h2>
|
||||||
@@ -270,12 +270,13 @@ std::vector<pf> v;
|
|||||||
|
|
||||||
std::for_each(v.begin(), v.end(), bind(apply<void>(), _1, 5));
|
std::for_each(v.begin(), v.end(), bind(apply<void>(), _1, 5));
|
||||||
</pre>
|
</pre>
|
||||||
<P>Sometimes it is necessary not to evaluate the first argument, but <STRONG>not</STRONG>
|
<P>Although the first argument is, by default, not evaluated, all other arguments
|
||||||
to evaluate some of the other arguments, even when they are nested <STRONG>bind</STRONG>
|
are. Sometimes it is necessary not to evaluate arguments subsequent to the
|
||||||
subexpressions. This can be achieved with the help of another function object, <STRONG>
|
first, even when they are nested <STRONG>bind</STRONG> subexpressions. This can
|
||||||
protect</STRONG>, that masks the type so that <STRONG>bind</STRONG> does
|
be achieved with the help of another function object, <STRONG>protect</STRONG>,
|
||||||
not recognize and evaluate it. When called, <STRONG>protect</STRONG> simply
|
that masks the type so that <STRONG>bind</STRONG> does not recognize and
|
||||||
forwards the argument list to the other function object unmodified.</P>
|
evaluate it. When called, <STRONG>protect</STRONG> simply forwards the argument
|
||||||
|
list to the other function object unmodified.</P>
|
||||||
<P>The header <STRONG>boost/bind/protect.hpp</STRONG> contains an implementation of <STRONG>
|
<P>The header <STRONG>boost/bind/protect.hpp</STRONG> contains an implementation of <STRONG>
|
||||||
protect</STRONG>. To protect a <STRONG>bind</STRONG> function object from
|
protect</STRONG>. To protect a <STRONG>bind</STRONG> function object from
|
||||||
evaluation, use <tt>protect(bind(f, ...))</tt>.</P>
|
evaluation, use <tt>protect(bind(f, ...))</tt>.</P>
|
||||||
@@ -795,7 +796,7 @@ namespace
|
|||||||
<h3><a name="NumberOfArguments">Number of Arguments</a></h3>
|
<h3><a name="NumberOfArguments">Number of Arguments</a></h3>
|
||||||
<p>This implementation supports function objects with up to nine arguments. This is
|
<p>This implementation supports function objects with up to nine arguments. This is
|
||||||
an implementation detail, not an inherent limitation of the design.</p>
|
an implementation detail, not an inherent limitation of the design.</p>
|
||||||
<h3><a name="stdcall">"__stdcall", "__fastcall", and "pascal" Support</a></h3>
|
<h3><a name="stdcall">"__stdcall", "__cdecl", "__fastcall", and "pascal" Support</a></h3>
|
||||||
<p>Some platforms allow several types of (member) functions that differ by their <b>calling
|
<p>Some platforms allow several types of (member) functions that differ by their <b>calling
|
||||||
convention</b> (the rules by which the function is invoked: how are
|
convention</b> (the rules by which the function is invoked: how are
|
||||||
arguments passed, how is the return value handled, and who cleans up the stack
|
arguments passed, how is the return value handled, and who cleans up the stack
|
||||||
@@ -813,6 +814,12 @@ namespace
|
|||||||
the macro <B>BOOST_MEM_FN_ENABLE_FASTCALL</B> before including <B><boost/bind.hpp></B>.</P>
|
the macro <B>BOOST_MEM_FN_ENABLE_FASTCALL</B> before including <B><boost/bind.hpp></B>.</P>
|
||||||
<P>To use <b>bind</b> with <b>pascal</b> functions, <b>#define</b> the macro <b>BOOST_BIND_ENABLE_PASCAL</b>
|
<P>To use <b>bind</b> with <b>pascal</b> functions, <b>#define</b> the macro <b>BOOST_BIND_ENABLE_PASCAL</b>
|
||||||
before including <b><boost/bind.hpp></b>.</P>
|
before including <b><boost/bind.hpp></b>.</P>
|
||||||
|
<P>To use <B>bind</B> with <B>__cdecl</B> <B>member</B> functions, <B>#define</B> the
|
||||||
|
macro <B>BOOST_MEM_FN_ENABLE_CDECL</B> before including <B><boost/bind.hpp></B>.</P>
|
||||||
|
<P><STRONG>It is best to define these macros in the project options, via -D on the
|
||||||
|
command line, or as the first line in the translation unit (.cpp file) where
|
||||||
|
bind is used.</STRONG> Not following this rule can lead to obscure errors
|
||||||
|
when a header includes bind.hpp before the macro has been defined.</P>
|
||||||
<p>[Note: this is a non-portable extension. It is not part of the interface.]</p>
|
<p>[Note: this is a non-portable extension. It is not part of the interface.]</p>
|
||||||
<p>[Note: Some compilers provide only minimal support for the <b>__stdcall</b> keyword.]</p>
|
<p>[Note: Some compilers provide only minimal support for the <b>__stdcall</b> keyword.]</p>
|
||||||
<h3><a name="visit_each"><b>visit_each</b> support</a></h3>
|
<h3><a name="visit_each"><b>visit_each</b> support</a></h3>
|
||||||
@@ -857,10 +864,10 @@ namespace
|
|||||||
<p><br>
|
<p><br>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<small>Copyright <20> 2001, 2002 by Peter Dimov and Multi Media Ltd. Permission to
|
<small>Copyright <20> 2001, 2002 by Peter Dimov and Multi Media Ltd. Copyright
|
||||||
copy, use, modify, sell and distribute this document is granted provided this
|
2003-2005 Peter Dimov. Permission to copy, use, modify, sell and distribute
|
||||||
copyright notice appears in all copies. This document is provided "as is"
|
this document is granted provided this copyright notice appears in all copies.
|
||||||
without express or implied warranty, and with no claim as to its suitability
|
This document is provided "as is" without express or implied warranty, and with
|
||||||
for any purpose.</small></p>
|
no claim as to its suitability for any purpose.</small></p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -1422,6 +1422,18 @@ template<class F, class A1, class A2, class A3, class A4, class A5, class A6, cl
|
|||||||
#undef BOOST_BIND_MF_NAME
|
#undef BOOST_BIND_MF_NAME
|
||||||
#undef BOOST_BIND_MF_CC
|
#undef BOOST_BIND_MF_CC
|
||||||
|
|
||||||
|
#ifdef BOOST_MEM_FN_ENABLE_CDECL
|
||||||
|
|
||||||
|
#define BOOST_BIND_MF_NAME(X) X##_cdecl
|
||||||
|
#define BOOST_BIND_MF_CC __cdecl
|
||||||
|
|
||||||
|
#include <boost/bind/bind_mf_cc.hpp>
|
||||||
|
|
||||||
|
#undef BOOST_BIND_MF_NAME
|
||||||
|
#undef BOOST_BIND_MF_CC
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
||||||
|
|
||||||
#define BOOST_BIND_MF_NAME(X) X##_stdcall
|
#define BOOST_BIND_MF_NAME(X) X##_stdcall
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
//
|
//
|
||||||
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
|
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
|
||||||
// Copyright (c) 2001 David Abrahams
|
// Copyright (c) 2001 David Abrahams
|
||||||
|
// Copyright (c) 2003-2005 Peter Dimov
|
||||||
//
|
//
|
||||||
// Distributed under the Boost Software License, Version 1.0. (See
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
// accompanying file LICENSE_1_0.txt or copy at
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
@@ -48,6 +49,18 @@ template<class V> struct mf
|
|||||||
#undef BOOST_MEM_FN_CC
|
#undef BOOST_MEM_FN_CC
|
||||||
#undef BOOST_MEM_FN_NAME
|
#undef BOOST_MEM_FN_NAME
|
||||||
|
|
||||||
|
#ifdef BOOST_MEM_FN_ENABLE_CDECL
|
||||||
|
|
||||||
|
#define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl
|
||||||
|
#define BOOST_MEM_FN_CC __cdecl
|
||||||
|
|
||||||
|
#include <boost/bind/mem_fn_template.hpp>
|
||||||
|
|
||||||
|
#undef BOOST_MEM_FN_CC
|
||||||
|
#undef BOOST_MEM_FN_NAME
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
||||||
|
|
||||||
#define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
|
#define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
|
||||||
@@ -89,6 +102,18 @@ template<> struct mf<void>
|
|||||||
#undef BOOST_MEM_FN_CC
|
#undef BOOST_MEM_FN_CC
|
||||||
#undef BOOST_MEM_FN_NAME
|
#undef BOOST_MEM_FN_NAME
|
||||||
|
|
||||||
|
#ifdef BOOST_MEM_FN_ENABLE_CDECL
|
||||||
|
|
||||||
|
#define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl
|
||||||
|
#define BOOST_MEM_FN_CC __cdecl
|
||||||
|
|
||||||
|
#include <boost/bind/mem_fn_template.hpp>
|
||||||
|
|
||||||
|
#undef BOOST_MEM_FN_CC
|
||||||
|
#undef BOOST_MEM_FN_NAME
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
||||||
|
|
||||||
#define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
|
#define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
|
||||||
@@ -130,6 +155,20 @@ template<> struct mf<void>
|
|||||||
#undef BOOST_MEM_FN_NAME2
|
#undef BOOST_MEM_FN_NAME2
|
||||||
#undef BOOST_MEM_FN_CC
|
#undef BOOST_MEM_FN_CC
|
||||||
|
|
||||||
|
#ifdef BOOST_MEM_FN_ENABLE_CDECL
|
||||||
|
|
||||||
|
#define BOOST_MEM_FN_NAME(X) X##_cdecl
|
||||||
|
#define BOOST_MEM_FN_NAME2(X) inner_##X##_cdecl
|
||||||
|
#define BOOST_MEM_FN_CC __cdecl
|
||||||
|
|
||||||
|
#include <boost/bind/mem_fn_vw.hpp>
|
||||||
|
|
||||||
|
#undef BOOST_MEM_FN_NAME
|
||||||
|
#undef BOOST_MEM_FN_NAME2
|
||||||
|
#undef BOOST_MEM_FN_CC
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
||||||
|
|
||||||
#define BOOST_MEM_FN_NAME(X) X##_stdcall
|
#define BOOST_MEM_FN_NAME(X) X##_stdcall
|
||||||
@@ -178,6 +217,18 @@ namespace _mfi
|
|||||||
#undef BOOST_MEM_FN_CC
|
#undef BOOST_MEM_FN_CC
|
||||||
#undef BOOST_MEM_FN_NAME
|
#undef BOOST_MEM_FN_NAME
|
||||||
|
|
||||||
|
#ifdef BOOST_MEM_FN_ENABLE_CDECL
|
||||||
|
|
||||||
|
#define BOOST_MEM_FN_NAME(X) X##_cdecl
|
||||||
|
#define BOOST_MEM_FN_CC __cdecl
|
||||||
|
|
||||||
|
#include <boost/bind/mem_fn_template.hpp>
|
||||||
|
|
||||||
|
#undef BOOST_MEM_FN_CC
|
||||||
|
#undef BOOST_MEM_FN_NAME
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
||||||
|
|
||||||
#define BOOST_MEM_FN_NAME(X) X##_stdcall
|
#define BOOST_MEM_FN_NAME(X) X##_stdcall
|
||||||
@@ -219,6 +270,18 @@ namespace _mfi
|
|||||||
#undef BOOST_MEM_FN_NAME
|
#undef BOOST_MEM_FN_NAME
|
||||||
#undef BOOST_MEM_FN_CC
|
#undef BOOST_MEM_FN_CC
|
||||||
|
|
||||||
|
#ifdef BOOST_MEM_FN_ENABLE_CDECL
|
||||||
|
|
||||||
|
#define BOOST_MEM_FN_NAME(X) X##_cdecl
|
||||||
|
#define BOOST_MEM_FN_CC __cdecl
|
||||||
|
|
||||||
|
#include <boost/bind/mem_fn_cc.hpp>
|
||||||
|
|
||||||
|
#undef BOOST_MEM_FN_NAME
|
||||||
|
#undef BOOST_MEM_FN_CC
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
|
||||||
|
|
||||||
#define BOOST_MEM_FN_NAME(X) X##_stdcall
|
#define BOOST_MEM_FN_NAME(X) X##_stdcall
|
||||||
|
35
mem_fn.html
35
mem_fn.html
@@ -37,8 +37,8 @@
|
|||||||
<h4 style="MARGIN-LEFT: 40pt"><a href="#Files">Files</a></h4>
|
<h4 style="MARGIN-LEFT: 40pt"><a href="#Files">Files</a></h4>
|
||||||
<h4 style="MARGIN-LEFT: 40pt"><a href="#Dependencies">Dependencies</a></h4>
|
<h4 style="MARGIN-LEFT: 40pt"><a href="#Dependencies">Dependencies</a></h4>
|
||||||
<h4 style="MARGIN-LEFT: 40pt"><a href="#NumberOfArguments">Number of Arguments</a></h4>
|
<h4 style="MARGIN-LEFT: 40pt"><a href="#NumberOfArguments">Number of Arguments</a></h4>
|
||||||
<h4 style="MARGIN-LEFT: 40pt"><a href="#stdcall">"__stdcall" and
|
<h4 style="MARGIN-LEFT: 40pt"><a href="#stdcall">"__stdcall", "__cdecl" and
|
||||||
"__fastcall" Support</a></h4>
|
"__fastcall" Support</a></h4>
|
||||||
<h3 style="MARGIN-LEFT: 20pt"><a href="#Acknowledgements">Acknowledgements</a></h3>
|
<h3 style="MARGIN-LEFT: 20pt"><a href="#Acknowledgements">Acknowledgements</a></h3>
|
||||||
<h2><a name="Purpose">Purpose</a></h2>
|
<h2><a name="Purpose">Purpose</a></h2>
|
||||||
<p>
|
<p>
|
||||||
@@ -168,10 +168,13 @@ void k(std::vector<boost::shared_ptr<X> > const & v)
|
|||||||
</p>
|
</p>
|
||||||
<h3><a name="Q4">Why isn't BOOST_MEM_FN_ENABLE_STDCALL defined automatically?</a></h3>
|
<h3><a name="Q4">Why isn't BOOST_MEM_FN_ENABLE_STDCALL defined automatically?</a></h3>
|
||||||
<p>
|
<p>
|
||||||
Non-portable extensions, in general, should default to off to prevent vendor
|
Non-portable extensions, in general, should default to
|
||||||
lock-in. Had BOOST_MEM_FN_ENABLE_STDCALL been defined automatically, you could
|
off to prevent vendor lock-in. Had BOOST_MEM_FN_ENABLE_STDCALL been defined
|
||||||
have accidentally taken advantage of it without realizing that your code is,
|
automatically, you could have accidentally taken advantage of
|
||||||
perhaps, no longer portable.
|
it without realizing that your code is, perhaps, no longer portable.
|
||||||
|
In addition, it is possible for the default
|
||||||
|
calling convention to be __stdcall, in which case enabling __stdcall support will
|
||||||
|
result in duplicate definitions.
|
||||||
</p>
|
</p>
|
||||||
<h2><a name="Interface">Interface</a></h2>
|
<h2><a name="Interface">Interface</a></h2>
|
||||||
<h3><a name="Synopsis">Synopsis</a></h3>
|
<h3><a name="Synopsis">Synopsis</a></h3>
|
||||||
@@ -346,7 +349,7 @@ template<class R, class T, class A1, class A2> <i>unspecified-6</i> <a hre
|
|||||||
This implementation supports member functions with up to eight arguments. This
|
This implementation supports member functions with up to eight arguments. This
|
||||||
is not an inherent limitation of the design, but an implementation detail.
|
is not an inherent limitation of the design, but an implementation detail.
|
||||||
</p>
|
</p>
|
||||||
<h3><a name="stdcall">"__stdcall" and "__fastcall" Support</a></h3>
|
<h3><a name="stdcall">"__stdcall", "__cdecl" and "__fastcall" Support</a></h3>
|
||||||
<p>
|
<p>
|
||||||
Some platforms allow several types of member functions that differ by their <b>calling
|
Some platforms allow several types of member functions that differ by their <b>calling
|
||||||
convention</b> (the rules by which the function is invoked: how are
|
convention</b> (the rules by which the function is invoked: how are
|
||||||
@@ -355,7 +358,8 @@ template<class R, class T, class A1, class A2> <i>unspecified-6</i> <a hre
|
|||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
For example, Windows API functions and COM interface member functions use a
|
For example, Windows API functions and COM interface member functions use a
|
||||||
calling convention known as <b>__stdcall</b>. Borland VCL components use <STRONG>__fastcall</STRONG>.
|
calling convention known as <b>__stdcall</b>. Borland VCL components use <STRONG>__fastcall</STRONG>. UDK, the component model of
|
||||||
|
OpenOffice.org, uses <STRONG>__cdecl</STRONG>.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
To use <b>mem_fn</b> with <b>__stdcall</b> member functions, <b>#define</b> the
|
To use <b>mem_fn</b> with <b>__stdcall</b> member functions, <b>#define</b> the
|
||||||
@@ -363,9 +367,16 @@ template<class R, class T, class A1, class A2> <i>unspecified-6</i> <a hre
|
|||||||
indirectly, <b><boost/mem_fn.hpp></b>.
|
indirectly, <b><boost/mem_fn.hpp></b>.
|
||||||
</p>
|
</p>
|
||||||
<P>To use <B>mem_fn</B> with <B>__fastcall</B> member functions, <B>#define</B> the
|
<P>To use <B>mem_fn</B> with <B>__fastcall</B> member functions, <B>#define</B> the
|
||||||
macro <B>BOOST_MEM_FN_ENABLE_FASTCALL</B> before including, directly or
|
macro <B>BOOST_MEM_FN_ENABLE_FASTCALL</B> before
|
||||||
indirectly, <B><boost/mem_fn.hpp></B>.
|
including <B><boost/mem_fn.hpp></B>.
|
||||||
</P>
|
</P>
|
||||||
|
<P>To use <B>mem_fn</B> with <B>__cdecl</B> member functions, <B>#define</B> the
|
||||||
|
macro <B>BOOST_MEM_FN_ENABLE_CDECL</B> before including
|
||||||
|
<B><boost/mem_fn.hpp></B>. </P>
|
||||||
|
<P><STRONG>It is best to define these macros in the project options, via -D
|
||||||
|
on the command line, or as the first line in the translation unit (.cpp file)
|
||||||
|
where mem_fn is used.</STRONG> Not following this rule can lead to obscure
|
||||||
|
errors when a header includes mem_fn.hpp before the macro has been defined.</P>
|
||||||
<P>[Note: this is a non-portable extension. It is not part of the interface.]
|
<P>[Note: this is a non-portable extension. It is not part of the interface.]
|
||||||
</P>
|
</P>
|
||||||
<p>
|
<p>
|
||||||
@@ -387,10 +398,10 @@ template<class R, class T, class A1, class A2> <i>unspecified-6</i> <a hre
|
|||||||
Dave Abrahams modified <b>bind</b> and <b>mem_fn</b> to support void returns on
|
Dave Abrahams modified <b>bind</b> and <b>mem_fn</b> to support void returns on
|
||||||
deficient compilers.
|
deficient compilers.
|
||||||
</p>
|
</p>
|
||||||
<p><br>
|
<p>Daniel Boelzle pointed out that UDK uses <STRONG>__cdecl</STRONG>.<br>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<small>Copyright <20> 2001, 2002 by Peter Dimov and Multi Media Ltd. Permission
|
<small>Copyright <20> 2001, 2002 by Peter Dimov and Multi Media Ltd. Copyright 2003-2005 Peter Dimov. Permission
|
||||||
to copy, use, modify, sell and distribute this document is granted provided
|
to copy, use, modify, sell and distribute this document is granted provided
|
||||||
this copyright notice appears in all copies. This document is provided "as is"
|
this copyright notice appears in all copies. This document is provided "as is"
|
||||||
without express or implied warranty, and with no claim as to its suitability
|
without express or implied warranty, and with no claim as to its suitability
|
||||||
|
164
test/bind_cdecl_mf_test.cpp
Normal file
164
test/bind_cdecl_mf_test.cpp
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC)
|
||||||
|
#pragma warning(disable: 4786) // identifier truncated in debug info
|
||||||
|
#pragma warning(disable: 4710) // function not inlined
|
||||||
|
#pragma warning(disable: 4711) // function selected for automatic inline expansion
|
||||||
|
#pragma warning(disable: 4514) // unreferenced inline removed
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// bind_cdecl_mf_test.cpp - test for bind.hpp + __cdecl (member functions)
|
||||||
|
//
|
||||||
|
// Copyright (c) 2005 Peter Dimov
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
|
||||||
|
#define BOOST_MEM_FN_ENABLE_CDECL
|
||||||
|
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||||
|
#pragma warning(push, 3)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
struct X
|
||||||
|
{
|
||||||
|
mutable unsigned int hash;
|
||||||
|
|
||||||
|
X(): hash(0) {}
|
||||||
|
|
||||||
|
int __cdecl f0() { f1(17); return 0; }
|
||||||
|
int __cdecl g0() const { g1(17); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
|
||||||
|
int __cdecl g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
|
||||||
|
|
||||||
|
int __cdecl f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
|
||||||
|
int __cdecl g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
|
||||||
|
int __cdecl g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
|
||||||
|
int __cdecl g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
|
||||||
|
int __cdecl g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
|
||||||
|
int __cdecl g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
|
||||||
|
int __cdecl g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
|
||||||
|
int __cdecl g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
|
void member_function_test()
|
||||||
|
{
|
||||||
|
using namespace boost;
|
||||||
|
|
||||||
|
X x;
|
||||||
|
|
||||||
|
// 0
|
||||||
|
|
||||||
|
bind(&X::f0, &x)();
|
||||||
|
bind(&X::f0, ref(x))();
|
||||||
|
|
||||||
|
bind(&X::g0, &x)();
|
||||||
|
bind(&X::g0, x)();
|
||||||
|
bind(&X::g0, ref(x))();
|
||||||
|
|
||||||
|
// 1
|
||||||
|
|
||||||
|
bind(&X::f1, &x, 1)();
|
||||||
|
bind(&X::f1, ref(x), 1)();
|
||||||
|
|
||||||
|
bind(&X::g1, &x, 1)();
|
||||||
|
bind(&X::g1, x, 1)();
|
||||||
|
bind(&X::g1, ref(x), 1)();
|
||||||
|
|
||||||
|
// 2
|
||||||
|
|
||||||
|
bind(&X::f2, &x, 1, 2)();
|
||||||
|
bind(&X::f2, ref(x), 1, 2)();
|
||||||
|
|
||||||
|
bind(&X::g2, &x, 1, 2)();
|
||||||
|
bind(&X::g2, x, 1, 2)();
|
||||||
|
bind(&X::g2, ref(x), 1, 2)();
|
||||||
|
|
||||||
|
// 3
|
||||||
|
|
||||||
|
bind(&X::f3, &x, 1, 2, 3)();
|
||||||
|
bind(&X::f3, ref(x), 1, 2, 3)();
|
||||||
|
|
||||||
|
bind(&X::g3, &x, 1, 2, 3)();
|
||||||
|
bind(&X::g3, x, 1, 2, 3)();
|
||||||
|
bind(&X::g3, ref(x), 1, 2, 3)();
|
||||||
|
|
||||||
|
// 4
|
||||||
|
|
||||||
|
bind(&X::f4, &x, 1, 2, 3, 4)();
|
||||||
|
bind(&X::f4, ref(x), 1, 2, 3, 4)();
|
||||||
|
|
||||||
|
bind(&X::g4, &x, 1, 2, 3, 4)();
|
||||||
|
bind(&X::g4, x, 1, 2, 3, 4)();
|
||||||
|
bind(&X::g4, ref(x), 1, 2, 3, 4)();
|
||||||
|
|
||||||
|
// 5
|
||||||
|
|
||||||
|
bind(&X::f5, &x, 1, 2, 3, 4, 5)();
|
||||||
|
bind(&X::f5, ref(x), 1, 2, 3, 4, 5)();
|
||||||
|
|
||||||
|
bind(&X::g5, &x, 1, 2, 3, 4, 5)();
|
||||||
|
bind(&X::g5, x, 1, 2, 3, 4, 5)();
|
||||||
|
bind(&X::g5, ref(x), 1, 2, 3, 4, 5)();
|
||||||
|
|
||||||
|
// 6
|
||||||
|
|
||||||
|
bind(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
|
||||||
|
bind(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)();
|
||||||
|
|
||||||
|
bind(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
|
||||||
|
bind(&X::g6, x, 1, 2, 3, 4, 5, 6)();
|
||||||
|
bind(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)();
|
||||||
|
|
||||||
|
// 7
|
||||||
|
|
||||||
|
bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
|
||||||
|
bind(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
|
||||||
|
|
||||||
|
bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
|
||||||
|
bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
|
||||||
|
bind(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
|
||||||
|
|
||||||
|
// 8
|
||||||
|
|
||||||
|
bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
|
||||||
|
bind(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
|
||||||
|
|
||||||
|
bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
|
||||||
|
bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
|
||||||
|
bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
|
||||||
|
|
||||||
|
BOOST_TEST( x.hash == 23558 );
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
member_function_test();
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
186
test/mem_fn_cdecl_test.cpp
Normal file
186
test/mem_fn_cdecl_test.cpp
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC)
|
||||||
|
#pragma warning(disable: 4786) // identifier truncated in debug info
|
||||||
|
#pragma warning(disable: 4710) // function not inlined
|
||||||
|
#pragma warning(disable: 4711) // function selected for automatic inline expansion
|
||||||
|
#pragma warning(disable: 4514) // unreferenced inline removed
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// mem_fn_cdecl_test.cpp - a test for mem_fn.hpp + __cdecl
|
||||||
|
//
|
||||||
|
// Copyright (c) 2005 Peter Dimov
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
|
||||||
|
#define BOOST_MEM_FN_ENABLE_CDECL
|
||||||
|
|
||||||
|
#include <boost/mem_fn.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||||
|
#pragma warning(push, 3)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
struct X
|
||||||
|
{
|
||||||
|
mutable unsigned int hash;
|
||||||
|
|
||||||
|
X(): hash(0) {}
|
||||||
|
|
||||||
|
int __cdecl f0() { f1(17); return 0; }
|
||||||
|
int __cdecl g0() const { g1(17); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
|
||||||
|
int __cdecl g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
|
||||||
|
|
||||||
|
int __cdecl f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
|
||||||
|
int __cdecl g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
|
||||||
|
int __cdecl g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
|
||||||
|
int __cdecl g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
|
||||||
|
int __cdecl g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
|
||||||
|
int __cdecl g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
|
||||||
|
int __cdecl g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
|
||||||
|
|
||||||
|
int __cdecl f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
|
||||||
|
int __cdecl g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
|
int detect_errors(bool x)
|
||||||
|
{
|
||||||
|
if(x)
|
||||||
|
{
|
||||||
|
std::cerr << "no errors detected.\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "test failed.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using boost::mem_fn;
|
||||||
|
|
||||||
|
X x;
|
||||||
|
|
||||||
|
X const & rcx = x;
|
||||||
|
X const * pcx = &x;
|
||||||
|
|
||||||
|
boost::shared_ptr<X> sp(new X);
|
||||||
|
|
||||||
|
mem_fn(&X::f0)(x);
|
||||||
|
mem_fn(&X::f0)(&x);
|
||||||
|
mem_fn(&X::f0)(sp);
|
||||||
|
|
||||||
|
mem_fn(&X::g0)(x);
|
||||||
|
mem_fn(&X::g0)(rcx);
|
||||||
|
mem_fn(&X::g0)(&x);
|
||||||
|
mem_fn(&X::g0)(pcx);
|
||||||
|
mem_fn(&X::g0)(sp);
|
||||||
|
|
||||||
|
mem_fn(&X::f1)(x, 1);
|
||||||
|
mem_fn(&X::f1)(&x, 1);
|
||||||
|
mem_fn(&X::f1)(sp, 1);
|
||||||
|
|
||||||
|
mem_fn(&X::g1)(x, 1);
|
||||||
|
mem_fn(&X::g1)(rcx, 1);
|
||||||
|
mem_fn(&X::g1)(&x, 1);
|
||||||
|
mem_fn(&X::g1)(pcx, 1);
|
||||||
|
mem_fn(&X::g1)(sp, 1);
|
||||||
|
|
||||||
|
mem_fn(&X::f2)(x, 1, 2);
|
||||||
|
mem_fn(&X::f2)(&x, 1, 2);
|
||||||
|
mem_fn(&X::f2)(sp, 1, 2);
|
||||||
|
|
||||||
|
mem_fn(&X::g2)(x, 1, 2);
|
||||||
|
mem_fn(&X::g2)(rcx, 1, 2);
|
||||||
|
mem_fn(&X::g2)(&x, 1, 2);
|
||||||
|
mem_fn(&X::g2)(pcx, 1, 2);
|
||||||
|
mem_fn(&X::g2)(sp, 1, 2);
|
||||||
|
|
||||||
|
mem_fn(&X::f3)(x, 1, 2, 3);
|
||||||
|
mem_fn(&X::f3)(&x, 1, 2, 3);
|
||||||
|
mem_fn(&X::f3)(sp, 1, 2, 3);
|
||||||
|
|
||||||
|
mem_fn(&X::g3)(x, 1, 2, 3);
|
||||||
|
mem_fn(&X::g3)(rcx, 1, 2, 3);
|
||||||
|
mem_fn(&X::g3)(&x, 1, 2, 3);
|
||||||
|
mem_fn(&X::g3)(pcx, 1, 2, 3);
|
||||||
|
mem_fn(&X::g3)(sp, 1, 2, 3);
|
||||||
|
|
||||||
|
mem_fn(&X::f4)(x, 1, 2, 3, 4);
|
||||||
|
mem_fn(&X::f4)(&x, 1, 2, 3, 4);
|
||||||
|
mem_fn(&X::f4)(sp, 1, 2, 3, 4);
|
||||||
|
|
||||||
|
mem_fn(&X::g4)(x, 1, 2, 3, 4);
|
||||||
|
mem_fn(&X::g4)(rcx, 1, 2, 3, 4);
|
||||||
|
mem_fn(&X::g4)(&x, 1, 2, 3, 4);
|
||||||
|
mem_fn(&X::g4)(pcx, 1, 2, 3, 4);
|
||||||
|
mem_fn(&X::g4)(sp, 1, 2, 3, 4);
|
||||||
|
|
||||||
|
mem_fn(&X::f5)(x, 1, 2, 3, 4, 5);
|
||||||
|
mem_fn(&X::f5)(&x, 1, 2, 3, 4, 5);
|
||||||
|
mem_fn(&X::f5)(sp, 1, 2, 3, 4, 5);
|
||||||
|
|
||||||
|
mem_fn(&X::g5)(x, 1, 2, 3, 4, 5);
|
||||||
|
mem_fn(&X::g5)(rcx, 1, 2, 3, 4, 5);
|
||||||
|
mem_fn(&X::g5)(&x, 1, 2, 3, 4, 5);
|
||||||
|
mem_fn(&X::g5)(pcx, 1, 2, 3, 4, 5);
|
||||||
|
mem_fn(&X::g5)(sp, 1, 2, 3, 4, 5);
|
||||||
|
|
||||||
|
mem_fn(&X::f6)(x, 1, 2, 3, 4, 5, 6);
|
||||||
|
mem_fn(&X::f6)(&x, 1, 2, 3, 4, 5, 6);
|
||||||
|
mem_fn(&X::f6)(sp, 1, 2, 3, 4, 5, 6);
|
||||||
|
|
||||||
|
mem_fn(&X::g6)(x, 1, 2, 3, 4, 5, 6);
|
||||||
|
mem_fn(&X::g6)(rcx, 1, 2, 3, 4, 5, 6);
|
||||||
|
mem_fn(&X::g6)(&x, 1, 2, 3, 4, 5, 6);
|
||||||
|
mem_fn(&X::g6)(pcx, 1, 2, 3, 4, 5, 6);
|
||||||
|
mem_fn(&X::g6)(sp, 1, 2, 3, 4, 5, 6);
|
||||||
|
|
||||||
|
mem_fn(&X::f7)(x, 1, 2, 3, 4, 5, 6, 7);
|
||||||
|
mem_fn(&X::f7)(&x, 1, 2, 3, 4, 5, 6, 7);
|
||||||
|
mem_fn(&X::f7)(sp, 1, 2, 3, 4, 5, 6, 7);
|
||||||
|
|
||||||
|
mem_fn(&X::g7)(x, 1, 2, 3, 4, 5, 6, 7);
|
||||||
|
mem_fn(&X::g7)(rcx, 1, 2, 3, 4, 5, 6, 7);
|
||||||
|
mem_fn(&X::g7)(&x, 1, 2, 3, 4, 5, 6, 7);
|
||||||
|
mem_fn(&X::g7)(pcx, 1, 2, 3, 4, 5, 6, 7);
|
||||||
|
mem_fn(&X::g7)(sp, 1, 2, 3, 4, 5, 6, 7);
|
||||||
|
|
||||||
|
mem_fn(&X::f8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||||
|
mem_fn(&X::f8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||||
|
mem_fn(&X::f8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||||
|
|
||||||
|
mem_fn(&X::g8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||||
|
mem_fn(&X::g8)(rcx, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||||
|
mem_fn(&X::g8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||||
|
mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||||
|
mem_fn(&X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||||
|
|
||||||
|
return detect_errors(x.hash == 17610 && sp->hash == 2155);
|
||||||
|
}
|
Reference in New Issue
Block a user