From 35ee2f3a521e381f9ea90b27822c992aaa92c0a5 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 15 Jul 2002 14:07:03 +0000 Subject: [PATCH] __fastcall support added. [SVN r14465] --- bind.html | 60 +++++++------ bind_fastcall_mf_test.cpp | 165 ++++++++++++++++++++++++++++++++++ bind_fastcall_test.cpp | 110 +++++++++++++++++++++++ include/boost/bind.hpp | 24 +++++ include/boost/mem_fn.hpp | 62 +++++++++++++ mem_fn.html | 16 ++-- mem_fn_fastcall_test.cpp | 185 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 590 insertions(+), 32 deletions(-) create mode 100644 bind_fastcall_mf_test.cpp create mode 100644 bind_fastcall_test.cpp create mode 100644 mem_fn_fastcall_test.cpp diff --git a/bind.html b/bind.html index 411462a..1038f48 100644 --- a/bind.html +++ b/bind.html @@ -46,7 +46,7 @@

Does bind work with Mac toolbox functions?

Does bind work with extern - "C" functions?

+ "C" functions?

Why doesn't bind automatically recognize nonstandard functions?

Troubleshooting

@@ -77,7 +77,8 @@

Files

Dependencies

Number of Arguments

-

"__stdcall" and "pascal" Support

+

"__stdcall", "__fastcall", and + "pascal" Support

Using the BOOST_BIND macro

visit_each support

Acknowledgements

@@ -455,13 +456,13 @@ template<class T> void f(T const & t); alternative is to treat the function as a generic function object and use the bind<R>(f, ...) syntax.

-

Does bind work with extern "C" functions?

+

Does bind work with extern "C" functions?

- Sometimes. On some platforms, pointers to extern "C" functions are - equivalent to "ordinary" function pointers, so they work fine. Other - platforms treat them as different types. A platform-specific implementation of bind - is expected to handle the problem transparently; this implementation does not. - As usual, the workaround is to treat the function as a + Sometimes. On some platforms, pointers to extern "C" functions are equivalent + to "ordinary" function pointers, so they work fine. Other platforms treat them + as different types. A platform-specific implementation of bind is + expected to handle the problem transparently; this implementation does not. As + usual, the workaround is to treat the function as a generic function object and use the bind<R>(f, ...) syntax.

Why doesn't bind automatically recognize @@ -471,8 +472,9 @@ template<class T> void f(T const & t); lock-in. Had the appropriate macros been defined automatically, you could have accidentally taken advantage of them without realizing that your code is, perhaps, no longer portable. In addition, some - compilers have the option to make __stdcall their default calling - convention, in which case no separate support would be necessary. + compilers have the option to make __stdcall (__fastcall) + their default calling convention, in which case no separate support would be + necessary.

Troubleshooting

Incorrect number of arguments

@@ -589,7 +591,7 @@ int main() a2, ..., aN) form works with nonstandard functions.

- On some platforms, extern "C" functions, like std::strcmp, are not + On some platforms, extern "C" functions, like std::strcmp, are not recognized by the short form of bind.

@@ -753,8 +755,8 @@ namespace Effects: Equivalent to bind<typename F::result_type, F>(f);

- Notes: Implementations are allowed to infer the return type of f - via other means as an extension, without relying on the result_type member. + Notes: Implementations are allowed to infer the return type of f via + other means as an extension, without relying on the result_type member.

template<class R> unspecified-2 bind(R (*f) ())

@@ -789,8 +791,8 @@ namespace a1);

- Notes: Implementations are allowed to infer the return type of f - via other means as an extension, without relying on the result_type member. + Notes: Implementations are allowed to infer the return type of f via + other means as an extension, without relying on the result_type member.

template<class R, class B1, class A1> unspecified-4 bind(R @@ -822,8 +824,8 @@ namespace a1);

-

template<class R, class T, class A1> unspecified-6-1 bind(R - T::*f, A1 a1)

+

template<class R, class T, class A1> unspecified-6-1 + bind(R T::*f, A1 a1)

Effects: Equivalent to bind<R const &>(boost::mem_fn(f), @@ -852,8 +854,8 @@ namespace a1, a2);

- Notes: Implementations are allowed to infer the return type of f - via other means as an extension, without relying on the result_type member. + Notes: Implementations are allowed to infer the return type of f via + other means as an extension, without relying on the result_type member.

template<class R, class B1, class B2, class A1, class A2> unspecified-8 @@ -888,8 +890,8 @@ namespace

Additional overloads

- Implementations are allowed to provide additional bind overloads in order to - support more arguments or different function pointer variations. + Implementations are allowed to provide additional bind overloads in + order to support more arguments or different function pointer variations.

Implementation

Files

@@ -951,7 +953,7 @@ namespace This implementation supports function objects with up to nine arguments. This is an implementation detail, not an inherent limitation of the design.

-

"__stdcall" and "pascal" Support

+

"__stdcall", "__fastcall", and "pascal" Support

Some platforms allow several types of (member) functions that differ by their calling convention (the rules by which the function is invoked: how are @@ -960,8 +962,8 @@ namespace

For example, Windows API functions and COM interface member functions use a - calling convention known as __stdcall. Mac toolbox functions use a pascal - calling convention. + calling convention known as __stdcall.Borland VCL components use __fastcall. + Mac toolbox functions use a pascal calling convention.

To use bind with __stdcall functions, #define the macro BOOST_BIND_ENABLE_STDCALL @@ -971,10 +973,16 @@ namespace To use bind with __stdcall member functions, #define the macro BOOST_MEM_FN_ENABLE_STDCALL before including <boost/bind.hpp>.

-

+

To use bind with __fastcall functions, #define the macro BOOST_BIND_ENABLE_FASTCALL + before including <boost/bind.hpp>. +

+

To use bind with __fastcall member functions, #define + the macro BOOST_MEM_FN_ENABLE_FASTCALL before including <boost/bind.hpp>. +

+

To use bind with pascal functions, #define the macro BOOST_BIND_ENABLE_PASCAL before including <boost/bind.hpp>. -

+

[Note: this is a non-portable extension. It is not part of the interface.]

diff --git a/bind_fastcall_mf_test.cpp b/bind_fastcall_mf_test.cpp new file mode 100644 index 0000000..dcf642b --- /dev/null +++ b/bind_fastcall_mf_test.cpp @@ -0,0 +1,165 @@ +#if defined(_MSC_VER) && !defined(__ICL) +#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_stdcall_mf_test.cpp - test for bind.hpp + __stdcall (member functions) +// +// Copyright (c) 2001 Peter Dimov and Multi Media Ltd. +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// + +#define BOOST_MEM_FN_ENABLE_FASTCALL + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(push, 3) +#endif + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(pop) +#endif + + +#define BOOST_INCLUDE_MAIN +#include + +struct X +{ + mutable unsigned int hash; + + X(): hash(0) {} + + void __fastcall f0() { f1(17); } + void __fastcall g0() const { g1(17); } + + void __fastcall f1(int a1) { hash = (hash * 17041 + a1) % 32768; } + void __fastcall g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; } + + void __fastcall f2(int a1, int a2) { f1(a1); f1(a2); } + void __fastcall g2(int a1, int a2) const { g1(a1); g1(a2); } + + void __fastcall f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); } + void __fastcall g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); } + + void __fastcall f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); } + void __fastcall g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); } + + void __fastcall f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); } + void __fastcall g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); } + + void __fastcall f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); } + void __fastcall g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); } + + void __fastcall f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); } + void __fastcall 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); } + + void __fastcall 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); } + void __fastcall 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); } +}; + +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 test_main(int, char * []) +{ + member_function_test(); + return 0; +} diff --git a/bind_fastcall_test.cpp b/bind_fastcall_test.cpp new file mode 100644 index 0000000..1da820d --- /dev/null +++ b/bind_fastcall_test.cpp @@ -0,0 +1,110 @@ +#if defined(_MSC_VER) && !defined(__ICL) +#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_fastcall_test.cpp - test for bind.hpp + __fastcall (free functions) +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// + +#define BOOST_BIND_ENABLE_FASTCALL + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(push, 3) +#endif + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(pop) +#endif + +#define BOOST_INCLUDE_MAIN +#include + +// + +long __fastcall f_0() +{ + return 17041L; +} + +long __fastcall f_1(long a) +{ + return a; +} + +long __fastcall f_2(long a, long b) +{ + return a + 10 * b; +} + +long __fastcall f_3(long a, long b, long c) +{ + return a + 10 * b + 100 * c; +} + +long __fastcall f_4(long a, long b, long c, long d) +{ + return a + 10 * b + 100 * c + 1000 * d; +} + +long __fastcall f_5(long a, long b, long c, long d, long e) +{ + return a + 10 * b + 100 * c + 1000 * d + 10000 * e; +} + +long __fastcall f_6(long a, long b, long c, long d, long e, long f) +{ + return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f; +} + +long __fastcall f_7(long a, long b, long c, long d, long e, long f, long g) +{ + return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g; +} + +long __fastcall f_8(long a, long b, long c, long d, long e, long f, long g, long h) +{ + return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h; +} + +long __fastcall f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i) +{ + return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i; +} + +void function_test() +{ + using namespace boost; + + int const i = 1; + + BOOST_TEST( bind(f_0)(i) == 17041L ); + BOOST_TEST( bind(f_1, _1)(i) == 1L ); + BOOST_TEST( bind(f_2, _1, 2)(i) == 21L ); + BOOST_TEST( bind(f_3, _1, 2, 3)(i) == 321L ); + BOOST_TEST( bind(f_4, _1, 2, 3, 4)(i) == 4321L ); + BOOST_TEST( bind(f_5, _1, 2, 3, 4, 5)(i) == 54321L ); + BOOST_TEST( bind(f_6, _1, 2, 3, 4, 5, 6)(i) == 654321L ); + BOOST_TEST( bind(f_7, _1, 2, 3, 4, 5, 6, 7)(i) == 7654321L ); + BOOST_TEST( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i) == 87654321L ); + BOOST_TEST( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i) == 987654321L ); +} + +int test_main(int, char * []) +{ + function_test(); + return 0; +} diff --git a/include/boost/bind.hpp b/include/boost/bind.hpp index 5a3ffbf..5480d1f 100644 --- a/include/boost/bind.hpp +++ b/include/boost/bind.hpp @@ -1343,6 +1343,18 @@ template + +#undef BOOST_BIND_CC +#undef BOOST_BIND_ST + +#endif + #ifdef BOOST_BIND_ENABLE_PASCAL #define BOOST_BIND_ST pascal @@ -1377,6 +1389,18 @@ template + +#undef BOOST_BIND_MF_NAME +#undef BOOST_BIND_MF_CC + +#endif + // data member pointers template diff --git a/include/boost/mem_fn.hpp b/include/boost/mem_fn.hpp index f59fff4..af93168 100644 --- a/include/boost/mem_fn.hpp +++ b/include/boost/mem_fn.hpp @@ -66,6 +66,18 @@ template struct mf #endif +#ifdef BOOST_MEM_FN_ENABLE_FASTCALL + +#define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall +#define BOOST_MEM_FN_CC __fastcall + +#include + +#undef BOOST_MEM_FN_CC +#undef BOOST_MEM_FN_NAME + +#endif + #undef BOOST_MEM_FN_RETURN }; // struct mf @@ -95,6 +107,18 @@ template<> struct mf #endif +#ifdef BOOST_MEM_FN_ENABLE_FASTCALL + +#define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall +#define BOOST_MEM_FN_CC __fastcall + +#include + +#undef BOOST_MEM_FN_CC +#undef BOOST_MEM_FN_NAME + +#endif + #undef BOOST_MEM_FN_RETURN }; // struct mf @@ -126,6 +150,20 @@ template<> struct mf #endif +#ifdef BOOST_MEM_FN_ENABLE_FASTCALL + +#define BOOST_MEM_FN_NAME(X) X##_fastcall +#define BOOST_MEM_FN_NAME2(X) inner_##X##_fastcall +#define BOOST_MEM_FN_CC __fastcall + +#include + +#undef BOOST_MEM_FN_NAME +#undef BOOST_MEM_FN_NAME2 +#undef BOOST_MEM_FN_CC + +#endif + } // namespace _mfi #else // #ifdef BOOST_NO_VOID_RETURNS @@ -158,6 +196,18 @@ namespace _mfi #endif +#ifdef BOOST_MEM_FN_ENABLE_FASTCALL + +#define BOOST_MEM_FN_NAME(X) X##_fastcall +#define BOOST_MEM_FN_CC __fastcall + +#include + +#undef BOOST_MEM_FN_CC +#undef BOOST_MEM_FN_NAME + +#endif + #undef BOOST_MEM_FN_RETURN } // namespace _mfi @@ -187,6 +237,18 @@ namespace _mfi #endif +#ifdef BOOST_MEM_FN_ENABLE_FASTCALL + +#define BOOST_MEM_FN_NAME(X) X##_fastcall +#define BOOST_MEM_FN_CC __fastcall + +#include + +#undef BOOST_MEM_FN_NAME +#undef BOOST_MEM_FN_CC + +#endif + // data member support namespace _mfi diff --git a/mem_fn.html b/mem_fn.html index b9efcad..cdd780a 100644 --- a/mem_fn.html +++ b/mem_fn.html @@ -37,7 +37,8 @@

Files

Dependencies

Number of Arguments

-

"__stdcall" Support

+

"__stdcall" and + "__fastcall" Support

Acknowledgements

Purpose

@@ -321,7 +322,7 @@ template<class R, class T, class A1, class A2> implementation-defined-6 This implementation supports member functions with up to eight arguments. This is not an inherent limitation of the design, but an implementation detail.

-

"__stdcall" Support

+

"__stdcall" and "__fastcall" Support

Some platforms allow several types of member functions that differ by their calling convention (the rules by which the function is invoked: how are @@ -330,16 +331,19 @@ template<class R, class T, class A1, class A2> implementation-defined-6

For example, Windows API functions and COM interface member functions use a - calling convention known as __stdcall. + calling convention known as __stdcall. Borland VCL components use __fastcall.

To use mem_fn with __stdcall member functions, #define the macro BOOST_MEM_FN_ENABLE_STDCALL before including, directly or indirectly, <boost/mem_fn.hpp>.

-

- [Note: this is a non-portable extension. It is not part of the interface.] -

+

To use mem_fn with __fastcall member functions, #define the + macro BOOST_MEM_FN_ENABLE_FASTCALL before including, directly or + indirectly, <boost/mem_fn.hpp>. +

+

[Note: this is a non-portable extension. It is not part of the interface.] +

[Note: Some compilers provide only minimal support for the __stdcall keyword.]

diff --git a/mem_fn_fastcall_test.cpp b/mem_fn_fastcall_test.cpp new file mode 100644 index 0000000..ca26273 --- /dev/null +++ b/mem_fn_fastcall_test.cpp @@ -0,0 +1,185 @@ +#if defined(_MSC_VER) && !defined(__ICL) +#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_fastcall_test.cpp - a test for mem_fn.hpp + __fastcall +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// + +#define BOOST_MEM_FN_ENABLE_FASTCALL + +#include +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(push, 3) +#endif + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(pop) +#endif + + +struct X +{ + mutable unsigned int hash; + + X(): hash(0) {} + + void __fastcall f0() { f1(17); } + void __fastcall g0() const { g1(17); } + + void __fastcall f1(int a1) { hash = (hash * 17041 + a1) % 32768; } + void __fastcall g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; } + + void __fastcall f2(int a1, int a2) { f1(a1); f1(a2); } + void __fastcall g2(int a1, int a2) const { g1(a1); g1(a2); } + + void __fastcall f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); } + void __fastcall g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); } + + void __fastcall f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); } + void __fastcall g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); } + + void __fastcall f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); } + void __fastcall g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); } + + void __fastcall f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); } + void __fastcall g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); } + + void __fastcall f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); } + void __fastcall 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); } + + void __fastcall 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); } + void __fastcall 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); } +}; + +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 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); +}