diff --git a/bind_stdcall_mf_test.cpp b/bind_stdcall_mf_test.cpp new file mode 100644 index 0000000..c9fe416 --- /dev/null +++ b/bind_stdcall_mf_test.cpp @@ -0,0 +1,155 @@ +#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_STDCALL + +#include +#include + +#define BOOST_INCLUDE_MAIN +#include + +struct X +{ + mutable unsigned int hash; + + X(): hash(0) {} + + int __stdcall f0() { f1(17); return 0; } + int __stdcall g0() const { g1(17); return 0; } + + int __stdcall f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; } + int __stdcall g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; } + + int __stdcall f2(int a1, int a2) { f1(a1); f1(a2); return 0; } + int __stdcall g2(int a1, int a2) const { g1(a1); g1(a2); return 0; } + + int __stdcall f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; } + int __stdcall g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; } + + int __stdcall f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; } + int __stdcall g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; } + + int __stdcall f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; } + int __stdcall g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; } + + int __stdcall f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; } + int __stdcall 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 __stdcall 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 __stdcall 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 __stdcall 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 __stdcall 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 test_main(int, char * []) +{ + member_function_test(); + return 0; +} diff --git a/bind_stdcall_test.cpp b/bind_stdcall_test.cpp new file mode 100644 index 0000000..75e1c00 --- /dev/null +++ b/bind_stdcall_test.cpp @@ -0,0 +1,101 @@ +#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_test.cpp - test for bind.hpp + __stdcall (free 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_BIND_ENABLE_STDCALL + +#include +#include + +#define BOOST_INCLUDE_MAIN +#include + +// + +long __stdcall f_0() +{ + return 17041L; +} + +long __stdcall f_1(long a) +{ + return a; +} + +long __stdcall f_2(long a, long b) +{ + return a + 10 * b; +} + +long __stdcall f_3(long a, long b, long c) +{ + return a + 10 * b + 100 * c; +} + +long __stdcall f_4(long a, long b, long c, long d) +{ + return a + 10 * b + 100 * c + 1000 * d; +} + +long __stdcall f_5(long a, long b, long c, long d, long e) +{ + return a + 10 * b + 100 * c + 1000 * d + 10000 * e; +} + +long __stdcall 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 __stdcall 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 __stdcall 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 __stdcall 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 0ac926c..ec2ac5b 100644 --- a/include/boost/bind.hpp +++ b/include/boost/bind.hpp @@ -1,15 +1,13 @@ #ifndef BOOST_BIND_HPP_INCLUDED #define BOOST_BIND_HPP_INCLUDED -#if _MSC_VER >= 1020 +#if _MSC_VER+0 >= 1020 #pragma once #endif // // bind.hpp - binds function objects to arguments // -// Version 1.02.0001 (2001-10-18) -// // Copyright (c) 2001 Peter Dimov and Multi Media Ltd. // // Permission to copy, use, modify, sell and distribute this software @@ -1025,116 +1023,36 @@ template(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9)); } -#endif +#endif // !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) // function pointers -template - _bi::bind_t - BOOST_BIND(R (*f) ()) -{ - typedef R (*F) (); - typedef _bi::list0 list_type; - return _bi::bind_t (f, list_type()); -} +#if defined(BOOST_BIND_ENABLE_STDCALL) +#define BOOST_BIND_CC __stdcall +#include +#undef BOOST_BIND_CC +#endif -template - _bi::bind_t::type> - BOOST_BIND(R (*f) (B1), A1 a1) -{ - typedef R (*F) (B1); - typedef typename _bi::list_av_1::type list_type; - return _bi::bind_t (f, list_type(a1)); -} - -template - _bi::bind_t::type> - BOOST_BIND(R (*f) (B1, B2), A1 a1, A2 a2) -{ - typedef R (*F) (B1, B2); - typedef typename _bi::list_av_2::type list_type; - return _bi::bind_t (f, list_type(a1, a2)); -} - -template - _bi::bind_t::type> - BOOST_BIND(R (*f) (B1, B2, B3), A1 a1, A2 a2, A3 a3) -{ - typedef R (*F) (B1, B2, B3); - typedef typename _bi::list_av_3::type list_type; - return _bi::bind_t(f, list_type(a1, a2, a3)); -} - -template - _bi::bind_t::type> - BOOST_BIND(R (*f) (B1, B2, B3, B4), A1 a1, A2 a2, A3 a3, A4 a4) -{ - typedef R (*F) (B1, B2, B3, B4); - typedef typename _bi::list_av_4::type list_type; - return _bi::bind_t(f, list_type(a1, a2, a3, a4)); -} - -template - _bi::bind_t::type> - BOOST_BIND(R (*f) (B1, B2, B3, B4, B5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) -{ - typedef R (*F) (B1, B2, B3, B4, B5); - typedef typename _bi::list_av_5::type list_type; - return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5)); -} - -template - _bi::bind_t::type> - BOOST_BIND(R (*f) (B1, B2, B3, B4, B5, B6), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) -{ - typedef R (*F) (B1, B2, B3, B4, B5, B6); - typedef typename _bi::list_av_6::type list_type; - return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6)); -} - -template - _bi::bind_t::type> - BOOST_BIND(R (*f) (B1, B2, B3, B4, B5, B6, B7), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) -{ - typedef R (*F) (B1, B2, B3, B4, B5, B6, B7); - typedef typename _bi::list_av_7::type list_type; - return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6, a7)); -} - -template - _bi::bind_t::type> - BOOST_BIND(R (*f) (B1, B2, B3, B4, B5, B6, B7, B8), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) -{ - typedef R (*F) (B1, B2, B3, B4, B5, B6, B7, B8); - typedef typename _bi::list_av_8::type list_type; - return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8)); -} - -template - _bi::bind_t::type> - BOOST_BIND(R (*f) (B1, B2, B3, B4, B5, B6, B7, B8, B9), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) -{ - typedef R (*F) (B1, B2, B3, B4, B5, B6, B7, B8, B9); - typedef typename _bi::list_av_9::type list_type; - return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9)); -} +#define BOOST_BIND_CC +#include +#undef BOOST_BIND_CC // member function pointers +#if defined(BOOST_MEM_FN_ENABLE_STDCALL) || (defined(BOOST_MSVC) && BOOST_MSVC <= 1300) + +#if defined(BOOST_MEM_FN_ENABLE_STDCALL) +#define BOOST_BIND_MF_CC __stdcall +#include +#undef BOOST_BIND_MF_CC +#endif + +#define BOOST_BIND_MF_CC +#include +#undef BOOST_BIND_MF_CC + +#else + // 0 template(F(f), list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9)); } +#endif // !defined(BOOST_MEM_FN_ENABLE_STDCALL) + } // namespace boost namespace diff --git a/include/boost/bind/bind_cc.hpp b/include/boost/bind/bind_cc.hpp new file mode 100644 index 0000000..f97dbaf --- /dev/null +++ b/include/boost/bind/bind_cc.hpp @@ -0,0 +1,122 @@ +#ifndef BOOST_BIND_CC +#error Do not include directly. +#endif + +// +// bind/bind_cc.hpp - support for different calling conventions +// +// Do not include this header directly. +// +// 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. +// +// See http://www.boost.org/libs/bind/bind.html for documentation. +// + +template + _bi::bind_t + BOOST_BIND(R (BOOST_BIND_CC *f) ()) +{ + typedef R (BOOST_BIND_CC *F) (); + typedef _bi::list0 list_type; + return _bi::bind_t (f, list_type()); +} + +template + _bi::bind_t::type> + BOOST_BIND(R (BOOST_BIND_CC *f) (B1), A1 a1) +{ + typedef R (BOOST_BIND_CC *F) (B1); + typedef typename _bi::list_av_1::type list_type; + return _bi::bind_t (f, list_type(a1)); +} + +template + _bi::bind_t::type> + BOOST_BIND(R (BOOST_BIND_CC *f) (B1, B2), A1 a1, A2 a2) +{ + typedef R (BOOST_BIND_CC *F) (B1, B2); + typedef typename _bi::list_av_2::type list_type; + return _bi::bind_t (f, list_type(a1, a2)); +} + +template + _bi::bind_t::type> + BOOST_BIND(R (BOOST_BIND_CC *f) (B1, B2, B3), A1 a1, A2 a2, A3 a3) +{ + typedef R (BOOST_BIND_CC *F) (B1, B2, B3); + typedef typename _bi::list_av_3::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3)); +} + +template + _bi::bind_t::type> + BOOST_BIND(R (BOOST_BIND_CC *f) (B1, B2, B3, B4), A1 a1, A2 a2, A3 a3, A4 a4) +{ + typedef R (BOOST_BIND_CC *F) (B1, B2, B3, B4); + typedef typename _bi::list_av_4::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4)); +} + +template + _bi::bind_t::type> + BOOST_BIND(R (BOOST_BIND_CC *f) (B1, B2, B3, B4, B5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) +{ + typedef R (BOOST_BIND_CC *F) (B1, B2, B3, B4, B5); + typedef typename _bi::list_av_5::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5)); +} + +template + _bi::bind_t::type> + BOOST_BIND(R (BOOST_BIND_CC *f) (B1, B2, B3, B4, B5, B6), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) +{ + typedef R (BOOST_BIND_CC *F) (B1, B2, B3, B4, B5, B6); + typedef typename _bi::list_av_6::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6)); +} + +template + _bi::bind_t::type> + BOOST_BIND(R (BOOST_BIND_CC *f) (B1, B2, B3, B4, B5, B6, B7), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) +{ + typedef R (BOOST_BIND_CC *F) (B1, B2, B3, B4, B5, B6, B7); + typedef typename _bi::list_av_7::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6, a7)); +} + +template + _bi::bind_t::type> + BOOST_BIND(R (BOOST_BIND_CC *f) (B1, B2, B3, B4, B5, B6, B7, B8), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) +{ + typedef R (BOOST_BIND_CC *F) (B1, B2, B3, B4, B5, B6, B7, B8); + typedef typename _bi::list_av_8::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8)); +} + +template + _bi::bind_t::type> + BOOST_BIND(R (BOOST_BIND_CC *f) (B1, B2, B3, B4, B5, B6, B7, B8, B9), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) +{ + typedef R (BOOST_BIND_CC *F) (B1, B2, B3, B4, B5, B6, B7, B8, B9); + typedef typename _bi::list_av_9::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9)); +} diff --git a/include/boost/bind/bind_mf_cc.hpp b/include/boost/bind/bind_mf_cc.hpp new file mode 100644 index 0000000..5d6a343 --- /dev/null +++ b/include/boost/bind/bind_mf_cc.hpp @@ -0,0 +1,232 @@ +#ifndef BOOST_BIND_MF_CC +#error Do not include directly. +#endif + +// +// bind/bind_mf_cc.hpp - support for different calling conventions +// +// Do not include this header directly. +// +// 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. +// +// See http://www.boost.org/libs/bind/bind.html for documentation. +// + +// 0 + +template + _bi::bind_t, typename _bi::list_av_1::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (), A1 a1) +{ + typedef _mfi::mf0 F; + typedef typename _bi::list_av_1::type list_type; + return _bi::bind_t(F(f), list_type(a1)); +} + +template + _bi::bind_t, typename _bi::list_av_1::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) () const, A1 a1) +{ + typedef _mfi::cmf0 F; + typedef typename _bi::list_av_1::type list_type; + return _bi::bind_t(F(f), list_type(a1)); +} + +// 1 + +template + _bi::bind_t, typename _bi::list_av_2::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1), A1 a1, A2 a2) +{ + typedef _mfi::mf1 F; + typedef typename _bi::list_av_2::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2)); +} + +template + _bi::bind_t, typename _bi::list_av_2::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1) const, A1 a1, A2 a2) +{ + typedef _mfi::cmf1 F; + typedef typename _bi::list_av_2::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2)); +} + +// 2 + +template + _bi::bind_t, typename _bi::list_av_3::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2), A1 a1, A2 a2, A3 a3) +{ + typedef _mfi::mf2 F; + typedef typename _bi::list_av_3::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3)); +} + +template + _bi::bind_t, typename _bi::list_av_3::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2) const, A1 a1, A2 a2, A3 a3) +{ + typedef _mfi::cmf2 F; + typedef typename _bi::list_av_3::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3)); +} + +// 3 + +template + _bi::bind_t, typename _bi::list_av_4::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3), A1 a1, A2 a2, A3 a3, A4 a4) +{ + typedef _mfi::mf3 F; + typedef typename _bi::list_av_4::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4)); +} + +template + _bi::bind_t, typename _bi::list_av_4::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3) const, A1 a1, A2 a2, A3 a3, A4 a4) +{ + typedef _mfi::cmf3 F; + typedef typename _bi::list_av_4::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4)); +} + +// 4 + +template + _bi::bind_t, typename _bi::list_av_5::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) +{ + typedef _mfi::mf4 F; + typedef typename _bi::list_av_5::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4, a5)); +} + +template + _bi::bind_t, typename _bi::list_av_5::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4) const, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) +{ + typedef _mfi::cmf4 F; + typedef typename _bi::list_av_5::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4, a5)); +} + +// 5 + +template + _bi::bind_t, typename _bi::list_av_6::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) +{ + typedef _mfi::mf5 F; + typedef typename _bi::list_av_6::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4, a5, a6)); +} + +template + _bi::bind_t, typename _bi::list_av_6::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5) const, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) +{ + typedef _mfi::cmf5 F; + typedef typename _bi::list_av_6::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4, a5, a6)); +} + +// 6 + +template + _bi::bind_t, typename _bi::list_av_7::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) +{ + typedef _mfi::mf6 F; + typedef typename _bi::list_av_7::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4, a5, a6, a7)); +} + +template + _bi::bind_t, typename _bi::list_av_7::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6) const, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) +{ + typedef _mfi::cmf6 F; + typedef typename _bi::list_av_7::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4, a5, a6, a7)); +} + +// 7 + +template + _bi::bind_t, typename _bi::list_av_8::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) +{ + typedef _mfi::mf7 F; + typedef typename _bi::list_av_8::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4, a5, a6, a7, a8)); +} + +template + _bi::bind_t, typename _bi::list_av_8::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7) const, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) +{ + typedef _mfi::cmf7 F; + typedef typename _bi::list_av_8::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4, a5, a6, a7, a8)); +} + +// 8 + +template + _bi::bind_t, typename _bi::list_av_9::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7, B8), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) +{ + typedef _mfi::mf8 F; + typedef typename _bi::list_av_9::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9)); +} + +template + _bi::bind_t, typename _bi::list_av_9::type> + BOOST_BIND(R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7, B8) const, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) +{ + typedef _mfi::cmf8 F; + typedef typename _bi::list_av_9::type list_type; + return _bi::bind_t(F(f), list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9)); +} diff --git a/include/boost/bind/mem_fn_cc.hpp b/include/boost/bind/mem_fn_cc.hpp new file mode 100644 index 0000000..91459f0 --- /dev/null +++ b/include/boost/bind/mem_fn_cc.hpp @@ -0,0 +1,108 @@ +#ifndef BOOST_MEM_FN_CC +#error Do not include directly. +#endif + +// +// bind/mem_fn_cc.hpp - support for different calling conventions +// +// Do not include this header directly. +// +// 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. +// +// See http://www.boost.org/libs/bind/mem_fn.html for documentation. +// + +template _mfi::mf0 mem_fn(R (BOOST_MEM_FN_CC T::*f) ()) +{ + return _mfi::mf0(f); +} + +template _mfi::cmf0 mem_fn(R (BOOST_MEM_FN_CC T::*f) () const) +{ + return _mfi::cmf0(f); +} + +template _mfi::mf1 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1)) +{ + return _mfi::mf1(f); +} + +template _mfi::cmf1 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1) const) +{ + return _mfi::cmf1(f); +} + +template _mfi::mf2 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2)) +{ + return _mfi::mf2(f); +} + +template _mfi::cmf2 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2) const) +{ + return _mfi::cmf2(f); +} + +template _mfi::mf3 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3)) +{ + return _mfi::mf3(f); +} + +template _mfi::cmf3 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3) const) +{ + return _mfi::cmf3(f); +} + +template _mfi::mf4 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3, A4)) +{ + return _mfi::mf4(f); +} + +template _mfi::cmf4 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3, A4) const) +{ + return _mfi::cmf4(f); +} + +template _mfi::mf5 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3, A4, A5)) +{ + return _mfi::mf5(f); +} + +template _mfi::cmf5 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3, A4, A5) const) +{ + return _mfi::cmf5(f); +} + +template _mfi::mf6 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3, A4, A5, A6)) +{ + return _mfi::mf6(f); +} + +template _mfi::cmf6 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3, A4, A5, A6) const) +{ + return _mfi::cmf6(f); +} + +template _mfi::mf7 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3, A4, A5, A6, A7)) +{ + return _mfi::mf7(f); +} + +template _mfi::cmf7 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3, A4, A5, A6, A7) const) +{ + return _mfi::cmf7(f); +} + +template _mfi::mf8 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3, A4, A5, A6, A7, A8)) +{ + return _mfi::mf8(f); +} + +template _mfi::cmf8 mem_fn(R (BOOST_MEM_FN_CC T::*f) (A1, A2, A3, A4, A5, A6, A7, A8) const) +{ + return _mfi::cmf8(f); +} diff --git a/include/boost/mem_fn.hpp b/include/boost/mem_fn.hpp index f6709ed..4ead981 100644 --- a/include/boost/mem_fn.hpp +++ b/include/boost/mem_fn.hpp @@ -1,15 +1,13 @@ #ifndef BOOST_MEM_FN_HPP_INCLUDED #define BOOST_MEM_FN_HPP_INCLUDED -#if _MSC_VER >= 1020 +#if _MSC_VER+0 >= 1020 #pragma once #endif // // mem_fn.hpp - a generalization of std::mem_fun[_ref] // -// Version 1.02.0001 (2001-08-30) -// // Copyright (c) 2001 Peter Dimov and Multi Media Ltd. // // Permission to copy, use, modify, sell and distribute this software @@ -20,6 +18,8 @@ // See http://www.boost.org/libs/bind/mem_fn.html for documentation. // +#include + namespace boost { @@ -47,7 +47,7 @@ namespace _mfi // mem_fun_impl // mf0 -template class mf0 +template class mf0 { public: @@ -56,7 +56,6 @@ public: private: - typedef R (T::*F) (); F f_; public: @@ -81,7 +80,7 @@ public: // cmf0 -template class cmf0 +template class cmf0 { public: @@ -90,7 +89,6 @@ public: private: - typedef R (T::*F) () const; F f_; public: @@ -110,7 +108,7 @@ public: // mf1 -template class mf1 +template class mf1 { public: @@ -120,7 +118,6 @@ public: private: - typedef R (T::*F) (A1); F f_; public: @@ -145,7 +142,7 @@ public: // cmf1 -template class cmf1 +template class cmf1 { public: @@ -155,7 +152,6 @@ public: private: - typedef R (T::*F) (A1) const; F f_; public: @@ -175,7 +171,7 @@ public: // mf2 -template class mf2 +template class mf2 { public: @@ -183,7 +179,6 @@ public: private: - typedef R (T::*F) (A1, A2); F f_; public: @@ -208,7 +203,7 @@ public: // cmf2 -template class cmf2 +template class cmf2 { public: @@ -216,7 +211,6 @@ public: private: - typedef R (T::*F) (A1, A2) const; F f_; public: @@ -236,7 +230,7 @@ public: // mf3 -template class mf3 +template class mf3 { public: @@ -244,7 +238,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3); F f_; public: @@ -269,7 +262,7 @@ public: // cmf3 -template class cmf3 +template class cmf3 { public: @@ -277,7 +270,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3) const; F f_; public: @@ -297,7 +289,7 @@ public: // mf4 -template class mf4 +template class mf4 { public: @@ -305,7 +297,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3, A4); F f_; public: @@ -330,7 +321,7 @@ public: // cmf4 -template class cmf4 +template class cmf4 { public: @@ -338,7 +329,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3, A4) const; F f_; public: @@ -358,7 +348,7 @@ public: // mf5 -template class mf5 +template class mf5 { public: @@ -366,7 +356,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3, A4, A5); F f_; public: @@ -391,7 +380,7 @@ public: // cmf5 -template class cmf5 +template class cmf5 { public: @@ -399,7 +388,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3, A4, A5) const; F f_; public: @@ -419,7 +407,7 @@ public: // mf6 -template class mf6 +template class mf6 { public: @@ -427,7 +415,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3, A4, A5, A6); F f_; public: @@ -452,7 +439,7 @@ public: // cmf6 -template class cmf6 +template class cmf6 { public: @@ -460,7 +447,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3, A4, A5, A6) const; F f_; public: @@ -480,7 +466,7 @@ public: // mf7 -template class mf7 +template class mf7 { public: @@ -488,7 +474,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3, A4, A5, A6, A7); F f_; public: @@ -513,7 +498,7 @@ public: // cmf7 -template class cmf7 +template class cmf7 { public: @@ -521,7 +506,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3, A4, A5, A6, A7) const; F f_; public: @@ -541,7 +525,7 @@ public: // mf8 -template class mf8 +template class mf8 { public: @@ -549,7 +533,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3, A4, A5, A6, A7, A8); F f_; public: @@ -574,7 +557,7 @@ public: // cmf8 -template class cmf8 +template class cmf8 { public: @@ -582,7 +565,6 @@ public: private: - typedef R (T::*F) (A1, A2, A3, A4, A5, A6, A7, A8) const; F f_; public: @@ -609,6 +591,20 @@ public: // mem_fn +#if defined(BOOST_MEM_FN_ENABLE_STDCALL) || (defined(BOOST_MSVC) && BOOST_MSVC <= 1300) + +#if defined(BOOST_MEM_FN_ENABLE_STDCALL) +#define BOOST_MEM_FN_CC __stdcall +#include +#undef BOOST_MEM_FN_CC +#endif + +#define BOOST_MEM_FN_CC +#include +#undef BOOST_MEM_FN_CC + +#else + template _mfi::mf0 mem_fn(R (T::*f) ()) { return _mfi::mf0(f); @@ -699,6 +695,8 @@ template(f); } +#endif // !defined(BOOST_MEM_FN_ENABLE_STDCALL) + } // namespace boost #endif // #ifndef BOOST_MEM_FN_HPP_INCLUDED diff --git a/mem_fn_stdcall_test.cpp b/mem_fn_stdcall_test.cpp new file mode 100644 index 0000000..af0620f --- /dev/null +++ b/mem_fn_stdcall_test.cpp @@ -0,0 +1,175 @@ +#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_stdcall_test.cpp - a test for mem_fn.hpp + __stdcall +// +// 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_STDCALL + +#include +#include +#include + +struct X +{ + mutable unsigned int hash; + + X(): hash(0) {} + + int __stdcall f0() { f1(17); return 0; } + int __stdcall g0() const { g1(17); return 0; } + + int __stdcall f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; } + int __stdcall g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; } + + int __stdcall f2(int a1, int a2) { f1(a1); f1(a2); return 0; } + int __stdcall g2(int a1, int a2) const { g1(a1); g1(a2); return 0; } + + int __stdcall f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; } + int __stdcall g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; } + + int __stdcall f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; } + int __stdcall g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; } + + int __stdcall f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; } + int __stdcall g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; } + + int __stdcall f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; } + int __stdcall 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 __stdcall 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 __stdcall 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 __stdcall 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 __stdcall 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 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); +}