1
0
forked from boostorg/bind

Minor void return fixes (MSVC 6 on -W4, g++ 2.95.3)

[SVN r11706]
This commit is contained in:
Peter Dimov
2001-11-15 14:50:04 +00:00
parent 03dba9a279
commit e3bd44aa77
10 changed files with 235 additions and 87 deletions

View File

@@ -600,35 +600,6 @@ This is an implementation detail, not an inherent limitation of the
design.
</p>
<h3>Void returns</h3>
<p>
The following C++ code:
</p>
<pre>
void f();
void g()
{
return f();
}
</pre>
<p>
is legal; in fact it was deliberately made legal in order to support
forwarding functions that return <b>void</b>.
</p>
<p>
Unfortunately, some compilers have not caught up with the C++ Standard yet
and do not allow void returns. This implementation of <b>bind</b> will not
work for function pointers, member function pointers or function objects that
return <b>void</b> if the compiler does not support the feature. A possible
workaround is to change the return type of the function object in question
from <b>void</b> to <b>int</b> and return a dummy value of 0.
</p>
<h3>__stdcall support</h3>
<p>
@@ -768,6 +739,11 @@ Dave Abrahams fixed a MSVC-specific conflict between <b>bind</b> and the
<a href="../utility\iterator_adaptors.htm">iterator adaptors library</a>.
</p>
<p>
Dave Abrahams modified <b>bind</b> and <b>mem_fn</b> to support void returns
on deficient compilers.
</p>
<p><br><br><br><small>Copyright &copy; 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

View File

@@ -19,8 +19,18 @@
#define BOOST_MEM_FN_ENABLE_STDCALL
#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
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>

View File

@@ -19,8 +19,17 @@
#define BOOST_BIND_ENABLE_STDCALL
#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
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>

View File

@@ -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 <boost/bind.hpp>
#include <boost/ref.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
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
@@ -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 <class T>
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;

View File

@@ -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 R, class F, class L> class bind_t
: public bind_t_generator<R>::template implementation<F, L>
{
typedef typename bind_t_generator<R>::template implementation<F, L> 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

View File

@@ -1141,6 +1141,11 @@ struct mf<void>
};
};
#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 R, class T, class F = R (T::*) ()>
class mf0: public mf<R>::template mf0_<T, F>
{
@@ -1285,15 +1290,17 @@ class cmf8: public mf<R>::template cmf8_<T, A1, A2, A3, A4, A5, A6, A7, A8, F>
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

View File

@@ -27,7 +27,8 @@
<ul>
<li><a href="../../boost/mem_fn.hpp">mem_fn.hpp</a> (implementation)
<li><a href="mem_fn_test.cpp">mem_fn_test.cpp</a> (test)
<li><a href="mem_fn_stdcall_test.cpp">mem_fn_stdcall_test.cpp</a> (test with __stdcall member functions)
<li><a href="mem_fn_stdcall_test.cpp">mem_fn_stdcall_test.cpp</a> (test for __stdcall)
<li><a href="mem_fn_void_test.cpp">mem_fn_void_test.cpp</a> (test for void returns)
</ul>
<h2>Purpose</h2>
@@ -287,6 +288,11 @@ was Darin Adler.
Steve Anichini pointed out that COM interfaces use <b>__stdcall</b>.
</p>
<p>
Dave Abrahams modified <b>bind</b> and <b>mem_fn</b> to support void returns
on deficient compilers.
</p>
<p><br><br><br><small>Copyright &copy; 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

View File

@@ -20,8 +20,18 @@
#include <boost/mem_fn.hpp>
#include <boost/smart_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;

View File

@@ -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 <boost/mem_fn.hpp>
#include <boost/smart_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;

View File

@@ -18,8 +18,18 @@
#include <boost/mem_fn.hpp>
#include <boost/smart_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;