From e3bd44aa773277098d553dda22edd37b57390826 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 15 Nov 2001 14:50:04 +0000 Subject: [PATCH] Minor void return fixes (MSVC 6 on -W4, g++ 2.95.3) [SVN r11706] --- bind.html | 34 +------ bind_stdcall_mf_test.cpp | 10 ++ bind_stdcall_test.cpp | 9 ++ bind_test.cpp | 203 +++++++++++++++++++++++++++++---------- include/boost/bind.hpp | 11 +++ include/boost/mem_fn.hpp | 15 ++- mem_fn.html | 8 +- mem_fn_stdcall_test.cpp | 10 ++ mem_fn_test.cpp | 12 ++- mem_fn_void_test.cpp | 10 ++ 10 files changed, 235 insertions(+), 87 deletions(-) diff --git a/bind.html b/bind.html index e50b42c..ae0064a 100644 --- a/bind.html +++ b/bind.html @@ -600,35 +600,6 @@ This is an implementation detail, not an inherent limitation of the design.

-

Void returns

- -

-The following C++ code: -

- -
-void f();
-
-void g()
-{
-    return f();
-}
-
- -

-is legal; in fact it was deliberately made legal in order to support -forwarding functions that return void. -

- -

-Unfortunately, some compilers have not caught up with the C++ Standard yet -and do not allow void returns. This implementation of bind will not -work for function pointers, member function pointers or function objects that -return void if the compiler does not support the feature. A possible -workaround is to change the return type of the function object in question -from void to int and return a dummy value of 0. -

-

__stdcall support

@@ -768,6 +739,11 @@ Dave Abrahams fixed a MSVC-specific conflict between bind and the iterator adaptors library.

+

+Dave Abrahams modified bind and mem_fn to support void returns +on deficient compilers. +

+




Copyright © 2001 by Peter Dimov and Multi Media Ltd. Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document diff --git a/bind_stdcall_mf_test.cpp b/bind_stdcall_mf_test.cpp index c9fe416..8645a51 100644 --- a/bind_stdcall_mf_test.cpp +++ b/bind_stdcall_mf_test.cpp @@ -19,8 +19,18 @@ #define BOOST_MEM_FN_ENABLE_STDCALL #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 diff --git a/bind_stdcall_test.cpp b/bind_stdcall_test.cpp index 75e1c00..20f3a69 100644 --- a/bind_stdcall_test.cpp +++ b/bind_stdcall_test.cpp @@ -19,8 +19,17 @@ #define BOOST_BIND_ENABLE_STDCALL #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 diff --git a/bind_test.cpp b/bind_test.cpp index facca6c..d079902 100644 --- a/bind_test.cpp +++ b/bind_test.cpp @@ -8,8 +8,6 @@ // // bind_test.cpp - monolithic test for bind.hpp // -// Version 1.00.0002 (2001-09-02) -// // Copyright (c) 2001 Peter Dimov and Multi Media Ltd. // Copyright (c) 2001 David Abrahams // @@ -21,8 +19,18 @@ #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 + + #define BOOST_INCLUDE_MAIN #include @@ -273,95 +281,186 @@ struct V void 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); } }; -template -void member_function_test(T x) +void member_function_test() { using namespace boost; + X x; + // 0 - bind(&T::f0, &x)(); - bind(&T::f0, ref(x))(); + bind(&X::f0, &x)(); + bind(&X::f0, ref(x))(); - bind(&T::g0, &x)(); - bind(&T::g0, x)(); - bind(&T::g0, ref(x))(); + bind(&X::g0, &x)(); + bind(&X::g0, x)(); + bind(&X::g0, ref(x))(); // 1 - bind(&T::f1, &x, 1)(); - bind(&T::f1, ref(x), 1)(); + bind(&X::f1, &x, 1)(); + bind(&X::f1, ref(x), 1)(); - bind(&T::g1, &x, 1)(); - bind(&T::g1, x, 1)(); - bind(&T::g1, ref(x), 1)(); + bind(&X::g1, &x, 1)(); + bind(&X::g1, x, 1)(); + bind(&X::g1, ref(x), 1)(); // 2 - bind(&T::f2, &x, 1, 2)(); - bind(&T::f2, ref(x), 1, 2)(); + bind(&X::f2, &x, 1, 2)(); + bind(&X::f2, ref(x), 1, 2)(); - bind(&T::g2, &x, 1, 2)(); - bind(&T::g2, x, 1, 2)(); - bind(&T::g2, 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(&T::f3, &x, 1, 2, 3)(); - bind(&T::f3, ref(x), 1, 2, 3)(); + bind(&X::f3, &x, 1, 2, 3)(); + bind(&X::f3, ref(x), 1, 2, 3)(); - bind(&T::g3, &x, 1, 2, 3)(); - bind(&T::g3, x, 1, 2, 3)(); - bind(&T::g3, 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(&T::f4, &x, 1, 2, 3, 4)(); - bind(&T::f4, ref(x), 1, 2, 3, 4)(); + bind(&X::f4, &x, 1, 2, 3, 4)(); + bind(&X::f4, ref(x), 1, 2, 3, 4)(); - bind(&T::g4, &x, 1, 2, 3, 4)(); - bind(&T::g4, x, 1, 2, 3, 4)(); - bind(&T::g4, 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(&T::f5, &x, 1, 2, 3, 4, 5)(); - bind(&T::f5, 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(&T::g5, &x, 1, 2, 3, 4, 5)(); - bind(&T::g5, x, 1, 2, 3, 4, 5)(); - bind(&T::g5, 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(&T::f6, &x, 1, 2, 3, 4, 5, 6)(); - bind(&T::f6, 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(&T::g6, &x, 1, 2, 3, 4, 5, 6)(); - bind(&T::g6, x, 1, 2, 3, 4, 5, 6)(); - bind(&T::g6, 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(&T::f7, &x, 1, 2, 3, 4, 5, 6, 7)(); - bind(&T::f7, 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(&T::g7, &x, 1, 2, 3, 4, 5, 6, 7)(); - bind(&T::g7, x, 1, 2, 3, 4, 5, 6, 7)(); - bind(&T::g7, 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(&T::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)(); - bind(&T::f8, 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(&T::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)(); - bind(&T::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)(); - bind(&T::g8, 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 ); } +void member_function_void_test() +{ + using namespace boost; + + V v; + + // 0 + + bind(&V::f0, &v)(); + bind(&V::f0, ref(v))(); + + bind(&V::g0, &v)(); + bind(&V::g0, v)(); + bind(&V::g0, ref(v))(); + + // 1 + + bind(&V::f1, &v, 1)(); + bind(&V::f1, ref(v), 1)(); + + bind(&V::g1, &v, 1)(); + bind(&V::g1, v, 1)(); + bind(&V::g1, ref(v), 1)(); + + // 2 + + bind(&V::f2, &v, 1, 2)(); + bind(&V::f2, ref(v), 1, 2)(); + + bind(&V::g2, &v, 1, 2)(); + bind(&V::g2, v, 1, 2)(); + bind(&V::g2, ref(v), 1, 2)(); + + // 3 + + bind(&V::f3, &v, 1, 2, 3)(); + bind(&V::f3, ref(v), 1, 2, 3)(); + + bind(&V::g3, &v, 1, 2, 3)(); + bind(&V::g3, v, 1, 2, 3)(); + bind(&V::g3, ref(v), 1, 2, 3)(); + + // 4 + + bind(&V::f4, &v, 1, 2, 3, 4)(); + bind(&V::f4, ref(v), 1, 2, 3, 4)(); + + bind(&V::g4, &v, 1, 2, 3, 4)(); + bind(&V::g4, v, 1, 2, 3, 4)(); + bind(&V::g4, ref(v), 1, 2, 3, 4)(); + + // 5 + + bind(&V::f5, &v, 1, 2, 3, 4, 5)(); + bind(&V::f5, ref(v), 1, 2, 3, 4, 5)(); + + bind(&V::g5, &v, 1, 2, 3, 4, 5)(); + bind(&V::g5, v, 1, 2, 3, 4, 5)(); + bind(&V::g5, ref(v), 1, 2, 3, 4, 5)(); + + // 6 + + bind(&V::f6, &v, 1, 2, 3, 4, 5, 6)(); + bind(&V::f6, ref(v), 1, 2, 3, 4, 5, 6)(); + + bind(&V::g6, &v, 1, 2, 3, 4, 5, 6)(); + bind(&V::g6, v, 1, 2, 3, 4, 5, 6)(); + bind(&V::g6, ref(v), 1, 2, 3, 4, 5, 6)(); + + // 7 + + bind(&V::f7, &v, 1, 2, 3, 4, 5, 6, 7)(); + bind(&V::f7, ref(v), 1, 2, 3, 4, 5, 6, 7)(); + + bind(&V::g7, &v, 1, 2, 3, 4, 5, 6, 7)(); + bind(&V::g7, v, 1, 2, 3, 4, 5, 6, 7)(); + bind(&V::g7, ref(v), 1, 2, 3, 4, 5, 6, 7)(); + + // 8 + + bind(&V::f8, &v, 1, 2, 3, 4, 5, 6, 7, 8)(); + bind(&V::f8, ref(v), 1, 2, 3, 4, 5, 6, 7, 8)(); + + bind(&V::g8, &v, 1, 2, 3, 4, 5, 6, 7, 8)(); + bind(&V::g8, v, 1, 2, 3, 4, 5, 6, 7, 8)(); + bind(&V::g8, ref(v), 1, 2, 3, 4, 5, 6, 7, 8)(); + + BOOST_TEST( v.hash == 23558 ); +} + void nested_bind_test() { using namespace boost; @@ -386,11 +485,13 @@ int test_main(int, char * []) { function_test(); function_object_test(); + #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) adaptable_function_object_test(); #endif - member_function_test(X()); - member_function_test(V()); + + member_function_test(); + member_function_void_test(); nested_bind_test(); return 0; diff --git a/include/boost/bind.hpp b/include/boost/bind.hpp index 003c41f..8df7731 100644 --- a/include/boost/bind.hpp +++ b/include/boost/bind.hpp @@ -1088,14 +1088,25 @@ private: }; }; +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(push) +#pragma warning(disable: 4097) // typedef name 'base' used as a synonym for class +#endif + template class bind_t : public bind_t_generator::template implementation { typedef typename bind_t_generator::template implementation base; public: bind_t(F f, L const & l): base(f, l) {} + private: + bind_t & operator= (bind_t const &); }; +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(pop) +#endif + // add_value #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION diff --git a/include/boost/mem_fn.hpp b/include/boost/mem_fn.hpp index ead4579..0adae6b 100644 --- a/include/boost/mem_fn.hpp +++ b/include/boost/mem_fn.hpp @@ -1141,6 +1141,11 @@ struct mf }; }; +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(push) +#pragma warning(disable: 4097) // typedef name 'mf0_' used as a synonym for class +#endif + template class mf0: public mf::template mf0_ { @@ -1285,15 +1290,17 @@ class cmf8: public mf::template cmf8_ explicit cmf8(F f): cmf8_(f) {} }; +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(pop) +#endif + } // namespace _mfi // mem_fn -#if (defined(_WIN32) || defined(__WIN32__)) && defined(__MWERKS__) -# define BOOST_MEM_FN_ENABLE_STDCALL -#endif +// MSVC 7.0 and Metrowerks 7.1 can't handle the "main line" -#if defined(BOOST_MEM_FN_ENABLE_STDCALL) || (defined(BOOST_MSVC) && BOOST_MSVC <= 1300) +#if defined(BOOST_MEM_FN_ENABLE_STDCALL) || (defined(BOOST_MSVC) && BOOST_MSVC <= 1300) || (defined(__MWERKS__) && (__MWERKS__ <= 0x2406)) #if defined(BOOST_MEM_FN_ENABLE_STDCALL) #define BOOST_MEM_FN_CC __stdcall diff --git a/mem_fn.html b/mem_fn.html index a7abab3..d921f1c 100644 --- a/mem_fn.html +++ b/mem_fn.html @@ -27,7 +27,8 @@

Purpose

@@ -287,6 +288,11 @@ was Darin Adler. Steve Anichini pointed out that COM interfaces use __stdcall.

+

+Dave Abrahams modified bind and mem_fn to support void returns +on deficient compilers. +

+




Copyright © 2001 by Peter Dimov and Multi Media Ltd. Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document diff --git a/mem_fn_stdcall_test.cpp b/mem_fn_stdcall_test.cpp index af0620f..0f0ab45 100644 --- a/mem_fn_stdcall_test.cpp +++ b/mem_fn_stdcall_test.cpp @@ -20,8 +20,18 @@ #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; diff --git a/mem_fn_test.cpp b/mem_fn_test.cpp index 6dcf13f..7706e22 100644 --- a/mem_fn_test.cpp +++ b/mem_fn_test.cpp @@ -8,8 +8,6 @@ // // mem_fn_test.cpp - a test for mem_fn.hpp // -// 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,8 +18,18 @@ #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; diff --git a/mem_fn_void_test.cpp b/mem_fn_void_test.cpp index 793cf0b..4b669e4 100644 --- a/mem_fn_void_test.cpp +++ b/mem_fn_void_test.cpp @@ -18,8 +18,18 @@ #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;