Compare commits

...

26 Commits

Author SHA1 Message Date
Rene Rivera
082266a9a5 Cleanup release tags.
[SVN r44252]
2008-04-12 03:40:20 +00:00
nobody
eca90dd715 This commit was manufactured by cvs2svn to create tag
'Version_1_30_1'.

[SVN r19444]
2003-08-04 17:55:29 +00:00
Douglas Gregor
b32ebea99c Make this a forwarding header to the BoostBook-generated documentation
[SVN r17738]
2003-03-05 16:26:01 +00:00
nobody
5454a5aac6 This commit was manufactured by cvs2svn to create branch 'RC_1_30_0'.
[SVN r17693]
2003-03-01 19:43:06 +00:00
Peter Dimov
c9db3c51ea Fixed some links.
[SVN r17670]
2003-02-27 11:58:50 +00:00
Peter Dimov
8c09072ead Added copyright to Jamfiles.
[SVN r17363]
2003-02-13 15:41:26 +00:00
Peter Dimov
4876b82a73 Moved bind tests to a subinclude.
[SVN r17030]
2003-01-24 16:05:26 +00:00
Peter Dimov
7b7784d470 Metrowerks precompiled header fix (Bertolt Mildner)
[SVN r16731]
2003-01-02 11:55:47 +00:00
Dave Abrahams
eca328b27c Factor out get_pointer, supply an overload for std::auto_ptr.
[SVN r16672]
2002-12-20 18:15:01 +00:00
Peter Dimov
ad46d513d7 Documented new bind(type<R>(), f, ...) syntax.
[SVN r15932]
2002-10-15 12:45:49 +00:00
Peter Dimov
cc3ebc18b8 Fix for Compaq C++ (Ralf W. Grosse-Kunstleve)
[SVN r15929]
2002-10-15 10:57:08 +00:00
Peter Dimov
5a10daef4d bind(type<R>(), f, ...) alternative syntax support.
[SVN r15928]
2002-10-15 10:51:34 +00:00
Peter Dimov
51e4031aaf Fixed g++ 2.95 problem with bind<void>(...) (reported by Alkis Evlogimenos)
[SVN r15923]
2002-10-14 16:35:26 +00:00
Peter Dimov
55dbef0000 Fix for data member support, result_type was R instead of R const &
[SVN r15409]
2002-09-17 12:41:05 +00:00
Peter Dimov
b63a6a5d99 HTML error fixed.
[SVN r15253]
2002-09-10 16:12:51 +00:00
Peter Dimov
52cc55329b Fixed broken links.
[SVN r15123]
2002-08-31 13:04:52 +00:00
Dave Abrahams
5db80e9a33 Added explicit qualification for intel linux C++
[SVN r15025]
2002-08-21 12:27:03 +00:00
Peter Dimov
3cbc321fa5 Fixed the links in the Files section (reported by Albrecht Fritzsche)
[SVN r14955]
2002-08-19 16:51:06 +00:00
Peter Dimov
2f97add842 Switched to <boost/detail/lightweight_test.hpp> for testing.
[SVN r14932]
2002-08-16 16:41:16 +00:00
Peter Dimov
5345f14829 Redirecting index.html files added.
[SVN r14897]
2002-08-15 18:19:42 +00:00
Peter Dimov
0053801ad2 Data member support added.
[SVN r14640]
2002-07-30 13:01:47 +00:00
Peter Dimov
ad043d1fff implementation-defined changed to unspecified.
[SVN r14629]
2002-07-27 16:05:01 +00:00
Peter Dimov
35ee2f3a52 __fastcall support added.
[SVN r14465]
2002-07-15 14:07:03 +00:00
Dave Abrahams
5b1528f3f4 Fix unversioned VC++ checks
[SVN r14436]
2002-07-13 12:26:19 +00:00
Peter Dimov
2277238db7 Support for ref() as a first argument, allowing noncopyable function objects.
[SVN r14115]
2002-06-08 18:06:32 +00:00
Peter Dimov
bdde6cd8b2 extern C FAQ entry, support for data member pointers documented, etc.
[SVN r14081]
2002-06-04 15:15:04 +00:00
18 changed files with 1286 additions and 1269 deletions

965
bind.html

File diff suppressed because it is too large Load Diff

View File

@@ -22,6 +22,7 @@
#include <boost/config.hpp>
#include <boost/ref.hpp>
#include <boost/mem_fn.hpp>
#include <boost/type.hpp>
#include <boost/bind/arg.hpp>
// Borland-specific bug, visit_each() silently fails to produce code
@@ -59,6 +60,11 @@ template<class F> struct result_traits<unspecified, F>
typedef typename F::result_type type;
};
template<class F> struct result_traits< unspecified, reference_wrapper<F> >
{
typedef typename F::result_type type;
};
#endif
// bind_t forward declaration for listN
@@ -85,6 +91,23 @@ private:
template<class T> class type {};
// unwrap
template<class F> inline F & unwrap(F & f, long)
{
return f;
}
template<class F> inline F & unwrap(reference_wrapper<F> & f, int)
{
return f;
}
template<class F> inline F & unwrap(reference_wrapper<F> const & f, int)
{
return f;
}
// listN
#ifdef BOOST_NO_VOID_RETURNS
@@ -120,7 +143,7 @@ public:
template<class R, class F, class A> R operator()(type<R>, F f, A &) const
{
return f();
return unwrap(f, 0)();
}
template<class V> void accept(V &) const
@@ -144,9 +167,9 @@ public:
explicit list1(A1 a1): a1_(a1) {}
A1 operator[] (arg<1>) const { return a1_; }
A1 operator[] (boost::arg<1>) const { return a1_; }
A1 operator[] (arg<1> (*) ()) const { return a1_; }
A1 operator[] (boost::arg<1> (*) ()) const { return a1_; }
template<class T> T & operator[] (value<T> & v) const { return v.get(); }
@@ -160,7 +183,7 @@ public:
template<class R, class F, class A> R operator()(type<R>, F f, A & a) const
{
return f(a[a1_]);
return unwrap(f, 0)(a[a1_]);
}
template<class V> void accept(V & v) const
@@ -190,11 +213,11 @@ public:
list2(A1 a1, A2 a2): a1_(a1), a2_(a2) {}
A1 operator[] (arg<1>) const { return a1_; }
A2 operator[] (arg<2>) const { return a2_; }
A1 operator[] (boost::arg<1>) const { return a1_; }
A2 operator[] (boost::arg<2>) const { return a2_; }
A1 operator[] (arg<1> (*) ()) const { return a1_; }
A2 operator[] (arg<2> (*) ()) const { return a2_; }
A1 operator[] (boost::arg<1> (*) ()) const { return a1_; }
A2 operator[] (boost::arg<2> (*) ()) const { return a2_; }
template<class T> T & operator[] (value<T> & v) const { return v.get(); }
@@ -208,7 +231,7 @@ public:
template<class R, class F, class A> R operator()(type<R>, F f, A & a) const
{
return f(a[a1_], a[a2_]);
return unwrap(f, 0)(a[a1_], a[a2_]);
}
template<class V> void accept(V & v) const
@@ -240,13 +263,13 @@ public:
list3(A1 a1, A2 a2, A3 a3): a1_(a1), a2_(a2), a3_(a3) {}
A1 operator[] (arg<1>) const { return a1_; }
A2 operator[] (arg<2>) const { return a2_; }
A3 operator[] (arg<3>) const { return a3_; }
A1 operator[] (boost::arg<1>) const { return a1_; }
A2 operator[] (boost::arg<2>) const { return a2_; }
A3 operator[] (boost::arg<3>) const { return a3_; }
A1 operator[] (arg<1> (*) ()) const { return a1_; }
A2 operator[] (arg<2> (*) ()) const { return a2_; }
A3 operator[] (arg<3> (*) ()) const { return a3_; }
A1 operator[] (boost::arg<1> (*) ()) const { return a1_; }
A2 operator[] (boost::arg<2> (*) ()) const { return a2_; }
A3 operator[] (boost::arg<3> (*) ()) const { return a3_; }
template<class T> T & operator[] (value<T> & v) const { return v.get(); }
@@ -260,7 +283,7 @@ public:
template<class R, class F, class A> R operator()(type<R>, F f, A & a) const
{
return f(a[a1_], a[a2_], a[a3_]);
return unwrap(f, 0)(a[a1_], a[a2_], a[a3_]);
}
template<class V> void accept(V & v) const
@@ -294,15 +317,15 @@ public:
list4(A1 a1, A2 a2, A3 a3, A4 a4): a1_(a1), a2_(a2), a3_(a3), a4_(a4) {}
A1 operator[] (arg<1>) const { return a1_; }
A2 operator[] (arg<2>) const { return a2_; }
A3 operator[] (arg<3>) const { return a3_; }
A4 operator[] (arg<4>) const { return a4_; }
A1 operator[] (boost::arg<1>) const { return a1_; }
A2 operator[] (boost::arg<2>) const { return a2_; }
A3 operator[] (boost::arg<3>) const { return a3_; }
A4 operator[] (boost::arg<4>) const { return a4_; }
A1 operator[] (arg<1> (*) ()) const { return a1_; }
A2 operator[] (arg<2> (*) ()) const { return a2_; }
A3 operator[] (arg<3> (*) ()) const { return a3_; }
A4 operator[] (arg<4> (*) ()) const { return a4_; }
A1 operator[] (boost::arg<1> (*) ()) const { return a1_; }
A2 operator[] (boost::arg<2> (*) ()) const { return a2_; }
A3 operator[] (boost::arg<3> (*) ()) const { return a3_; }
A4 operator[] (boost::arg<4> (*) ()) const { return a4_; }
template<class T> T & operator[] (value<T> & v) const { return v.get(); }
@@ -316,7 +339,7 @@ public:
template<class R, class F, class A> R operator()(type<R>, F f, A & a) const
{
return f(a[a1_], a[a2_], a[a3_], a[a4_]);
return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_]);
}
template<class V> void accept(V & v) const
@@ -352,17 +375,17 @@ public:
list5(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5): a1_(a1), a2_(a2), a3_(a3), a4_(a4), a5_(a5) {}
A1 operator[] (arg<1>) const { return a1_; }
A2 operator[] (arg<2>) const { return a2_; }
A3 operator[] (arg<3>) const { return a3_; }
A4 operator[] (arg<4>) const { return a4_; }
A5 operator[] (arg<5>) const { return a5_; }
A1 operator[] (boost::arg<1>) const { return a1_; }
A2 operator[] (boost::arg<2>) const { return a2_; }
A3 operator[] (boost::arg<3>) const { return a3_; }
A4 operator[] (boost::arg<4>) const { return a4_; }
A5 operator[] (boost::arg<5>) const { return a5_; }
A1 operator[] (arg<1> (*) ()) const { return a1_; }
A2 operator[] (arg<2> (*) ()) const { return a2_; }
A3 operator[] (arg<3> (*) ()) const { return a3_; }
A4 operator[] (arg<4> (*) ()) const { return a4_; }
A5 operator[] (arg<5> (*) ()) const { return a5_; }
A1 operator[] (boost::arg<1> (*) ()) const { return a1_; }
A2 operator[] (boost::arg<2> (*) ()) const { return a2_; }
A3 operator[] (boost::arg<3> (*) ()) const { return a3_; }
A4 operator[] (boost::arg<4> (*) ()) const { return a4_; }
A5 operator[] (boost::arg<5> (*) ()) const { return a5_; }
template<class T> T & operator[] (value<T> & v) const { return v.get(); }
@@ -376,7 +399,7 @@ public:
template<class R, class F, class A> R operator()(type<R>, F f, A & a) const
{
return f(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_]);
return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_]);
}
template<class V> void accept(V & v) const
@@ -414,19 +437,19 @@ public:
list6(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6): a1_(a1), a2_(a2), a3_(a3), a4_(a4), a5_(a5), a6_(a6) {}
A1 operator[] (arg<1>) const { return a1_; }
A2 operator[] (arg<2>) const { return a2_; }
A3 operator[] (arg<3>) const { return a3_; }
A4 operator[] (arg<4>) const { return a4_; }
A5 operator[] (arg<5>) const { return a5_; }
A6 operator[] (arg<6>) const { return a6_; }
A1 operator[] (boost::arg<1>) const { return a1_; }
A2 operator[] (boost::arg<2>) const { return a2_; }
A3 operator[] (boost::arg<3>) const { return a3_; }
A4 operator[] (boost::arg<4>) const { return a4_; }
A5 operator[] (boost::arg<5>) const { return a5_; }
A6 operator[] (boost::arg<6>) const { return a6_; }
A1 operator[] (arg<1> (*) ()) const { return a1_; }
A2 operator[] (arg<2> (*) ()) const { return a2_; }
A3 operator[] (arg<3> (*) ()) const { return a3_; }
A4 operator[] (arg<4> (*) ()) const { return a4_; }
A5 operator[] (arg<5> (*) ()) const { return a5_; }
A6 operator[] (arg<6> (*) ()) const { return a6_; }
A1 operator[] (boost::arg<1> (*) ()) const { return a1_; }
A2 operator[] (boost::arg<2> (*) ()) const { return a2_; }
A3 operator[] (boost::arg<3> (*) ()) const { return a3_; }
A4 operator[] (boost::arg<4> (*) ()) const { return a4_; }
A5 operator[] (boost::arg<5> (*) ()) const { return a5_; }
A6 operator[] (boost::arg<6> (*) ()) const { return a6_; }
template<class T> T & operator[] (value<T> & v) const { return v.get(); }
@@ -440,7 +463,7 @@ public:
template<class R, class F, class A> R operator()(type<R>, F f, A & a) const
{
return f(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_]);
return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_]);
}
template<class V> void accept(V & v) const
@@ -480,21 +503,21 @@ public:
list7(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7): a1_(a1), a2_(a2), a3_(a3), a4_(a4), a5_(a5), a6_(a6), a7_(a7) {}
A1 operator[] (arg<1>) const { return a1_; }
A2 operator[] (arg<2>) const { return a2_; }
A3 operator[] (arg<3>) const { return a3_; }
A4 operator[] (arg<4>) const { return a4_; }
A5 operator[] (arg<5>) const { return a5_; }
A6 operator[] (arg<6>) const { return a6_; }
A7 operator[] (arg<7>) const { return a7_; }
A1 operator[] (boost::arg<1>) const { return a1_; }
A2 operator[] (boost::arg<2>) const { return a2_; }
A3 operator[] (boost::arg<3>) const { return a3_; }
A4 operator[] (boost::arg<4>) const { return a4_; }
A5 operator[] (boost::arg<5>) const { return a5_; }
A6 operator[] (boost::arg<6>) const { return a6_; }
A7 operator[] (boost::arg<7>) const { return a7_; }
A1 operator[] (arg<1> (*) ()) const { return a1_; }
A2 operator[] (arg<2> (*) ()) const { return a2_; }
A3 operator[] (arg<3> (*) ()) const { return a3_; }
A4 operator[] (arg<4> (*) ()) const { return a4_; }
A5 operator[] (arg<5> (*) ()) const { return a5_; }
A6 operator[] (arg<6> (*) ()) const { return a6_; }
A7 operator[] (arg<7> (*) ()) const { return a7_; }
A1 operator[] (boost::arg<1> (*) ()) const { return a1_; }
A2 operator[] (boost::arg<2> (*) ()) const { return a2_; }
A3 operator[] (boost::arg<3> (*) ()) const { return a3_; }
A4 operator[] (boost::arg<4> (*) ()) const { return a4_; }
A5 operator[] (boost::arg<5> (*) ()) const { return a5_; }
A6 operator[] (boost::arg<6> (*) ()) const { return a6_; }
A7 operator[] (boost::arg<7> (*) ()) const { return a7_; }
template<class T> T & operator[] (value<T> & v) const { return v.get(); }
@@ -508,7 +531,7 @@ public:
template<class R, class F, class A> R operator()(type<R>, F f, A & a) const
{
return f(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_]);
return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_]);
}
template<class V> void accept(V & v) const
@@ -550,23 +573,23 @@ public:
list8(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8): a1_(a1), a2_(a2), a3_(a3), a4_(a4), a5_(a5), a6_(a6), a7_(a7), a8_(a8) {}
A1 operator[] (arg<1>) const { return a1_; }
A2 operator[] (arg<2>) const { return a2_; }
A3 operator[] (arg<3>) const { return a3_; }
A4 operator[] (arg<4>) const { return a4_; }
A5 operator[] (arg<5>) const { return a5_; }
A6 operator[] (arg<6>) const { return a6_; }
A7 operator[] (arg<7>) const { return a7_; }
A8 operator[] (arg<8>) const { return a8_; }
A1 operator[] (boost::arg<1>) const { return a1_; }
A2 operator[] (boost::arg<2>) const { return a2_; }
A3 operator[] (boost::arg<3>) const { return a3_; }
A4 operator[] (boost::arg<4>) const { return a4_; }
A5 operator[] (boost::arg<5>) const { return a5_; }
A6 operator[] (boost::arg<6>) const { return a6_; }
A7 operator[] (boost::arg<7>) const { return a7_; }
A8 operator[] (boost::arg<8>) const { return a8_; }
A1 operator[] (arg<1> (*) ()) const { return a1_; }
A2 operator[] (arg<2> (*) ()) const { return a2_; }
A3 operator[] (arg<3> (*) ()) const { return a3_; }
A4 operator[] (arg<4> (*) ()) const { return a4_; }
A5 operator[] (arg<5> (*) ()) const { return a5_; }
A6 operator[] (arg<6> (*) ()) const { return a6_; }
A7 operator[] (arg<7> (*) ()) const { return a7_; }
A8 operator[] (arg<8> (*) ()) const { return a8_; }
A1 operator[] (boost::arg<1> (*) ()) const { return a1_; }
A2 operator[] (boost::arg<2> (*) ()) const { return a2_; }
A3 operator[] (boost::arg<3> (*) ()) const { return a3_; }
A4 operator[] (boost::arg<4> (*) ()) const { return a4_; }
A5 operator[] (boost::arg<5> (*) ()) const { return a5_; }
A6 operator[] (boost::arg<6> (*) ()) const { return a6_; }
A7 operator[] (boost::arg<7> (*) ()) const { return a7_; }
A8 operator[] (boost::arg<8> (*) ()) const { return a8_; }
template<class T> T & operator[] (value<T> & v) const { return v.get(); }
@@ -580,7 +603,7 @@ public:
template<class R, class F, class A> R operator()(type<R>, F f, A & a) const
{
return f(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_]);
return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_]);
}
template<class V> void accept(V & v) const
@@ -624,25 +647,25 @@ public:
list9(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9): a1_(a1), a2_(a2), a3_(a3), a4_(a4), a5_(a5), a6_(a6), a7_(a7), a8_(a8), a9_(a9) {}
A1 operator[] (arg<1>) const { return a1_; }
A2 operator[] (arg<2>) const { return a2_; }
A3 operator[] (arg<3>) const { return a3_; }
A4 operator[] (arg<4>) const { return a4_; }
A5 operator[] (arg<5>) const { return a5_; }
A6 operator[] (arg<6>) const { return a6_; }
A7 operator[] (arg<7>) const { return a7_; }
A8 operator[] (arg<8>) const { return a8_; }
A9 operator[] (arg<9>) const { return a9_; }
A1 operator[] (boost::arg<1>) const { return a1_; }
A2 operator[] (boost::arg<2>) const { return a2_; }
A3 operator[] (boost::arg<3>) const { return a3_; }
A4 operator[] (boost::arg<4>) const { return a4_; }
A5 operator[] (boost::arg<5>) const { return a5_; }
A6 operator[] (boost::arg<6>) const { return a6_; }
A7 operator[] (boost::arg<7>) const { return a7_; }
A8 operator[] (boost::arg<8>) const { return a8_; }
A9 operator[] (boost::arg<9>) const { return a9_; }
A1 operator[] (arg<1> (*) ()) const { return a1_; }
A2 operator[] (arg<2> (*) ()) const { return a2_; }
A3 operator[] (arg<3> (*) ()) const { return a3_; }
A4 operator[] (arg<4> (*) ()) const { return a4_; }
A5 operator[] (arg<5> (*) ()) const { return a5_; }
A6 operator[] (arg<6> (*) ()) const { return a6_; }
A7 operator[] (arg<7> (*) ()) const { return a7_; }
A8 operator[] (arg<8> (*) ()) const { return a8_; }
A9 operator[] (arg<9> (*) ()) const { return a9_; }
A1 operator[] (boost::arg<1> (*) ()) const { return a1_; }
A2 operator[] (boost::arg<2> (*) ()) const { return a2_; }
A3 operator[] (boost::arg<3> (*) ()) const { return a3_; }
A4 operator[] (boost::arg<4> (*) ()) const { return a4_; }
A5 operator[] (boost::arg<5> (*) ()) const { return a5_; }
A6 operator[] (boost::arg<6> (*) ()) const { return a6_; }
A7 operator[] (boost::arg<7> (*) ()) const { return a7_; }
A8 operator[] (boost::arg<8> (*) ()) const { return a8_; }
A9 operator[] (boost::arg<9> (*) ()) const { return a9_; }
template<class T> T & operator[] (value<T> & v) const { return v.get(); }
@@ -656,7 +679,7 @@ public:
template<class R, class F, class A> R operator()(type<R>, F f, A & a) const
{
return f(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_], a[a9_]);
return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_], a[a9_]);
}
template<class V> void accept(V & v) const
@@ -703,7 +726,7 @@ template <class R> struct evaluator0
template<class L, class F, class A>
static R eval(L const&, F f, A &)
{
return f();
return unwrap(f, 0)();
}
};
@@ -712,7 +735,7 @@ template <> struct evaluator0<void>
template<class L, class F, class A>
static void eval(L const&, F f, A &)
{
f();
unwrap(f, 0)();
}
};
@@ -721,7 +744,7 @@ template <class R> struct evaluator1
template<class L, class F, class A>
static R eval(L const& l, F f, A & a)
{
return f(a[l.a1_]);
return unwrap(f, 0)(a[l.a1_]);
}
};
@@ -730,7 +753,7 @@ template <> struct evaluator1<void>
template<class L, class F, class A>
static void eval(L const& l, F f, A & a)
{
f(a[l.a1_]);
unwrap(f, 0)(a[l.a1_]);
}
};
@@ -739,7 +762,7 @@ template <class R> struct evaluator2
template<class L, class F, class A>
static R eval(L const& l, F f, A & a)
{
return f(a[l.a1_], a[l.a2_]);
return unwrap(f, 0)(a[l.a1_], a[l.a2_]);
}
};
@@ -748,7 +771,7 @@ template <> struct evaluator2<void>
template<class L, class F, class A>
static void eval(L const& l, F f, A & a)
{
f(a[l.a1_], a[l.a2_]);
unwrap(f, 0)(a[l.a1_], a[l.a2_]);
}
};
@@ -757,7 +780,7 @@ template <class R> struct evaluator3
template<class L, class F, class A>
static R eval(L const& l, F f, A & a)
{
return f(a[l.a1_], a[l.a2_], a[l.a3_]);
return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_]);
}
};
@@ -766,7 +789,7 @@ template <> struct evaluator3<void>
template<class L, class F, class A>
static void eval(L const& l, F f, A & a)
{
f(a[l.a1_], a[l.a2_], a[l.a3_]);
unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_]);
}
};
@@ -775,7 +798,7 @@ template <class R> struct evaluator4
template<class L, class F, class A>
static R eval(L const& l, F f, A & a)
{
return f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_]);
return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_]);
}
};
@@ -784,7 +807,7 @@ template <> struct evaluator4<void>
template<class L, class F, class A>
static void eval(L const& l, F f, A & a)
{
f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_]);
unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_]);
}
};
@@ -793,7 +816,7 @@ template <class R> struct evaluator5
template<class L, class F, class A>
static R eval(L const& l, F f, A & a)
{
return f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_]);
return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_]);
}
};
@@ -802,7 +825,7 @@ template <> struct evaluator5<void>
template<class L, class F, class A>
static void eval(L const& l, F f, A & a)
{
f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_]);
unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_]);
}
};
@@ -811,7 +834,7 @@ template <class R> struct evaluator6
template<class L, class F, class A>
static R eval(L const& l, F f, A & a)
{
return f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_]);
return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_]);
}
};
@@ -820,7 +843,7 @@ template <> struct evaluator6<void>
template<class L, class F, class A>
static void eval(L const& l, F f, A & a)
{
f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_]);
unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_]);
}
};
@@ -829,7 +852,7 @@ template <class R> struct evaluator7
template<class L, class F, class A>
static R eval(L const& l, F f, A & a)
{
return f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_]);
return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_]);
}
};
@@ -838,7 +861,7 @@ template <> struct evaluator7<void>
template<class L, class F, class A>
static void eval(L const& l, F f, A & a)
{
f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_]);
unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_]);
}
};
@@ -847,7 +870,7 @@ template <class R> struct evaluator8
template<class L, class F, class A>
static R eval(L const& l, F f, A & a)
{
return f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_]);
return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_]);
}
};
@@ -856,7 +879,7 @@ template <> struct evaluator8<void>
template<class L, class F, class A>
static void eval(L const& l, F f, A & a)
{
f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_]);
unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_]);
}
};
@@ -865,7 +888,7 @@ template <class R> struct evaluator9
template<class L, class F, class A>
static R eval(L const& l, F f, A & a)
{
return f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_], a[l.a9_]);
return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_], a[l.a9_]);
}
};
@@ -874,7 +897,7 @@ template <> struct evaluator9<void>
template<class L, class F, class A>
static void eval(L const& l, F f, A & a)
{
f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_], a[l.a9_]);
unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_], a[l.a9_]);
}
};
@@ -967,12 +990,12 @@ template<class T> struct add_value< reference_wrapper<T> >
template<int I> struct add_value< arg<I> >
{
typedef arg<I> type;
typedef boost::arg<I> type;
};
template<int I> struct add_value< arg<I> (*) () >
{
typedef arg<I> (*type) ();
typedef boost::arg<I> (*type) ();
};
template<class R, class F, class L> struct add_value< bind_t<R, F, L> >
@@ -1111,6 +1134,18 @@ template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, c
typedef list9<B1, B2, B3, B4, B5, B6, B7, B8, B9> type;
};
// g++ 2.95 specific helper; used by the data member overload
template<class T> struct add_cref
{
typedef T const & type;
};
template<> struct add_cref<void>
{
typedef void type;
};
} // namespace _bi
// visit_each
@@ -1213,6 +1248,88 @@ template<class R, class F, class A1, class A2, class A3, class A4, class A5, cla
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9));
}
// generic function objects, alternative syntax
template<class R, class F>
_bi::bind_t<R, F, _bi::list0>
BOOST_BIND(boost::type<R>, F f)
{
typedef _bi::list0 list_type;
return _bi::bind_t<R, F, list_type> (f, list_type());
}
template<class R, class F, class A1>
_bi::bind_t<R, F, typename _bi::list_av_1<A1>::type>
BOOST_BIND(boost::type<R>, F f, A1 a1)
{
typedef typename _bi::list_av_1<A1>::type list_type;
return _bi::bind_t<R, F, list_type> (f, list_type(a1));
}
template<class R, class F, class A1, class A2>
_bi::bind_t<R, F, typename _bi::list_av_2<A1, A2>::type>
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2)
{
typedef typename _bi::list_av_2<A1, A2>::type list_type;
return _bi::bind_t<R, F, list_type> (f, list_type(a1, a2));
}
template<class R, class F, class A1, class A2, class A3>
_bi::bind_t<R, F, typename _bi::list_av_3<A1, A2, A3>::type>
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3)
{
typedef typename _bi::list_av_3<A1, A2, A3>::type list_type;
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3));
}
template<class R, class F, class A1, class A2, class A3, class A4>
_bi::bind_t<R, F, typename _bi::list_av_4<A1, A2, A3, A4>::type>
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4)
{
typedef typename _bi::list_av_4<A1, A2, A3, A4>::type list_type;
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4));
}
template<class R, class F, class A1, class A2, class A3, class A4, class A5>
_bi::bind_t<R, F, typename _bi::list_av_5<A1, A2, A3, A4, A5>::type>
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
{
typedef typename _bi::list_av_5<A1, A2, A3, A4, A5>::type list_type;
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5));
}
template<class R, class F, class A1, class A2, class A3, class A4, class A5, class A6>
_bi::bind_t<R, F, typename _bi::list_av_6<A1, A2, A3, A4, A5, A6>::type>
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
{
typedef typename _bi::list_av_6<A1, A2, A3, A4, A5, A6>::type list_type;
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6));
}
template<class R, class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
_bi::bind_t<R, F, typename _bi::list_av_7<A1, A2, A3, A4, A5, A6, A7>::type>
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
{
typedef typename _bi::list_av_7<A1, A2, A3, A4, A5, A6, A7>::type list_type;
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6, a7));
}
template<class R, class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
_bi::bind_t<R, F, typename _bi::list_av_8<A1, A2, A3, A4, A5, A6, A7, A8>::type>
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
{
typedef typename _bi::list_av_8<A1, A2, A3, A4, A5, A6, A7, A8>::type list_type;
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8));
}
template<class R, class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
_bi::bind_t<R, F, typename _bi::list_av_9<A1, A2, A3, A4, A5, A6, A7, A8, A9>::type>
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
{
typedef typename _bi::list_av_9<A1, A2, A3, A4, A5, A6, A7, A8, A9>::type list_type;
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9));
}
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
// adaptable function objects
@@ -1321,6 +1438,18 @@ template<class F, class A1, class A2, class A3, class A4, class A5, class A6, cl
#endif
#ifdef BOOST_BIND_ENABLE_FASTCALL
#define BOOST_BIND_CC __fastcall
#define BOOST_BIND_ST
#include <boost/bind/bind_cc.hpp>
#undef BOOST_BIND_CC
#undef BOOST_BIND_ST
#endif
#ifdef BOOST_BIND_ENABLE_PASCAL
#define BOOST_BIND_ST pascal
@@ -1355,17 +1484,44 @@ template<class F, class A1, class A2, class A3, class A4, class A5, class A6, cl
#endif
#ifdef BOOST_MEM_FN_ENABLE_FASTCALL
#define BOOST_BIND_MF_NAME(X) X##_fastcall
#define BOOST_BIND_MF_CC __fastcall
#include <boost/bind/bind_mf_cc.hpp>
#undef BOOST_BIND_MF_NAME
#undef BOOST_BIND_MF_CC
#endif
// data member pointers
#if defined(__GNUC__) && (__GNUC__ == 2)
template<class R, class T, class A1>
_bi::bind_t< R, _mfi::dm<R, T>, typename _bi::list_av_1<A1>::type >
_bi::bind_t< typename _bi::add_cref<R>::type, _mfi::dm<R, T>, typename _bi::list_av_1<A1>::type >
BOOST_BIND(R T::*f, A1 a1)
{
typedef _mfi::dm<R, T> F;
typedef typename _bi::list_av_1<A1>::type list_type;
return _bi::bind_t<R, F, list_type>(F(f), list_type(a1));
return _bi::bind_t<typename _bi::add_cref<R>::type, F, list_type>(F(f), list_type(a1));
}
#else
template<class R, class T, class A1>
_bi::bind_t< R const &, _mfi::dm<R, T>, typename _bi::list_av_1<A1>::type >
BOOST_BIND(R T::*f, A1 a1)
{
typedef _mfi::dm<R, T> F;
typedef typename _bi::list_av_1<A1>::type list_type;
return _bi::bind_t<R const &, F, list_type>(F(f), list_type(a1));
}
#endif
} // namespace boost
#ifndef BOOST_BIND_NO_PLACEHOLDERS

View File

@@ -36,7 +36,7 @@ static inline boost::arg<7> _7() { return boost::arg<7>(); }
static inline boost::arg<8> _8() { return boost::arg<8>(); }
static inline boost::arg<9> _9() { return boost::arg<9>(); }
#elif defined(BOOST_MSVC)
#elif (defined(BOOST_MSVC) && BOOST_MSVC <= 1300) || (defined(__DECCXX_VER) && __DECCXX_VER <= 60590031) || defined(__MWERKS__)
static boost::arg<1> _1;
static boost::arg<2> _2;

View File

@@ -20,19 +20,11 @@
//
#include <boost/config.hpp>
#include <boost/get_pointer.hpp>
namespace boost
{
// get_pointer(p) extracts a ->* capable pointer from p
template<class T> T * get_pointer(T * p)
{
return p;
}
// get_pointer(shared_ptr<T> const & p) has been moved to shared_ptr.hpp
#if defined(BOOST_NO_VOID_RETURNS)
#define BOOST_MEM_FN_CLASS_F , class F
@@ -66,6 +58,18 @@ template<class V> 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 <boost/bind/mem_fn_template.hpp>
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#endif
#undef BOOST_MEM_FN_RETURN
}; // struct mf<V>
@@ -95,6 +99,18 @@ template<> struct mf<void>
#endif
#ifdef BOOST_MEM_FN_ENABLE_FASTCALL
#define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
#define BOOST_MEM_FN_CC __fastcall
#include <boost/bind/mem_fn_template.hpp>
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#endif
#undef BOOST_MEM_FN_RETURN
}; // struct mf<void>
@@ -126,6 +142,20 @@ template<> struct mf<void>
#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 <boost/bind/mem_fn_vw.hpp>
#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 +188,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 <boost/bind/mem_fn_template.hpp>
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#endif
#undef BOOST_MEM_FN_RETURN
} // namespace _mfi
@@ -187,6 +229,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 <boost/bind/mem_fn_cc.hpp>
#undef BOOST_MEM_FN_NAME
#undef BOOST_MEM_FN_CC
#endif
// data member support
namespace _mfi

10
index.html Normal file
View File

@@ -0,0 +1,10 @@
<html>
<head>
<meta http-equiv="refresh" content="0; URL=bind.html">
</head>
<body>
Automatic redirection failed, please go to
<a href="bind.html">bind.html</a> or
<a href="mem_fn.html">mem_fn.html</a>.
</body>
</html>

View File

@@ -1,371 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Boost: mem_fn.hpp documentation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="white" style="MARGIN-LEFT: 5%; MARGIN-RIGHT: 5%">
<table border="0" width="100%">
<tr>
<td width="277">
<img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86">
</td>
<td align="middle">
<h1>mem_fn.hpp</h1>
</td>
</tr>
<tr>
<td colspan="2" height="64">&nbsp;</td>
</tr>
</table>
<h2>Contents</h2>
<h3 style="MARGIN-LEFT: 20pt"><a href="#Purpose">Purpose</a></h3>
<h3 style="MARGIN-LEFT: 20pt"><a href="#FAQ">Frequently Asked Questions</a></h3>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Q1">Can <b>mem_fn</b> be used instead of the
standard <b>std::mem_fun[_ref]</b> adaptors?</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Q2">Should I replace every occurence of <b>std::mem_fun[_ref]</b>
with <b>mem_fn</b> in my existing code?</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Q3">Does <b>mem_fn</b> work with COM methods?</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Q4">Why isn't BOOST_MEM_FN_ENABLE_STDCALL
defined automatically?</a></h4>
<h3 style="MARGIN-LEFT: 20pt"><a href="#Interface">Interface</a></h3>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Synopsis">Synopsis</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#CommonRequirements">Common requirements</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#get_pointer">get_pointer</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#mem_fn">mem_fn</a></h4>
<h3 style="MARGIN-LEFT: 20pt"><a href="#Implementation">Implementation</a></h3>
<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="#NumberOfArguments">Number of Arguments</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#stdcall">"__stdcall" Support</a></h4>
<h3 style="MARGIN-LEFT: 20pt"><a href="#Acknowledgements">Acknowledgements</a></h3>
<h2><a name="Purpose">Purpose</a></h2>
<p>
<b>boost::mem_fn</b> is a generalization of the standard functions <b>std::mem_fun</b>
and <b>std::mem_fun_ref</b>. It supports member function pointers with more
than one argument, and the returned function object can take a pointer, a
reference, or a smart pointer to an object instance as its first argument.
</p>
<p>
The purpose of <b>mem_fn</b> is twofold. First, it allows users to invoke a
member function on a container with the familiar
</p>
<pre>
std::for_each(v.begin(), v.end(), boost::mem_fn(&amp;Shape::draw));
</pre>
<p>
syntax, even when the container stores smart pointers.
</p>
<p>
Second, it can be used as a building block by library developers that want to
treat a pointer to member function as a function object. A library might define
an enhanced <b>for_each</b> algorithm with an overload of the form:
</p>
<pre>
template&lt;class It, class R, class T&gt; void for_each(It first, It last, R (T::*pmf) ())
{
std::for_each(first, last, boost::mem_fn(pmf));
}
</pre>
<p>
that will allow the convenient syntax:
</p>
<pre>
for_each(v.begin(), v.end(), &amp;Shape::draw);
</pre>
<p>
When documenting the feature, the library author will simply state:
</p>
<h4 style="MARGIN-LEFT: 20pt">template&lt;class It, class R, class T&gt; void
for_each(It first, It last, R (T::*pmf) ());</h4>
<p style="MARGIN-LEFT: 20pt">
<b>Effects:</b> equivalent to std::for_each(first, last, boost::mem_fn(pmf));
</p>
<p>
where <b>boost::mem_fn</b> can be a link to this page. See <a href="bind.html">the
documentation of <b>bind</b></a> for an example.
</p>
<p>
<b>mem_fn</b> takes one argument, a pointer to a member function, and returns a
function object suitable for use with standard or user-defined algorithms:
</p>
<pre>
struct X
{
void f();
};
void g(std::vector&lt;X&gt; &amp; v)
{
std::for_each(v.begin(), v.end(), boost::mem_fn(&amp;X::f));
};
void h(std::vector&lt;X *&gt; const &amp; v)
{
std::for_each(v.begin(), v.end(), boost::mem_fn(&amp;X::f));
};
void k(std::vector&lt;boost::shared_ptr&lt;X&gt; &gt; const &amp; v)
{
std::for_each(v.begin(), v.end(), boost::mem_fn(&amp;X::f));
};
</pre>
<p>
The returned function object takes the same arguments as the input member
function plus a "flexible" first argument that represents the object instance.
</p>
<p>
When the function object is invoked with a first argument <b>x</b> that is
neither a pointer nor a reference to the appropriate class (<b>X</b> in the
example above), it uses <tt>get_pointer(x)</tt> to obtain a pointer from <b>x</b>.
Library authors can "register" their smart pointer classes by supplying an
appropriate <b>get_pointer</b> overload, allowing <b>mem_fn</b> to recognize
and support them.
</p>
<p>
[Note: <b>get_pointer</b> is not restricted to return a pointer. Any object
that can be used in a member function call expression <tt>(x-&gt;*pmf)(...)</tt>
will work.]
</p>
<p>
[Note: the library uses an unqualified call to <b>get_pointer</b>. Therefore,
it will find, through argument-dependent lookup, <b>get_pointer</b> overloads
that are defined in the same namespace as the corresponding smart pointer
class, in addition to any <b>boost::get_pointer</b> overloads.]
</p>
<p>
All function objects returned by <b>mem_fn</b> expose a <b>result_type</b> typedef
that represents the return type of the member function.
</p>
<h2><a name="FAQ">Frequently Asked Questions</a></h2>
<h3><a name="Q1">Can <b>mem_fn</b> be used instead of the standard <b>std::mem_fun[_ref]</b>
adaptors?</a></h3>
<p>
Yes. For simple uses, <b>mem_fn</b> provides additional functionality that the
standard adaptors do not. Complicated expressions that use <b>std::bind1st</b>, <b>std::bind2nd</b>
or <a href="../compose/index.htm"><b>Boost.Compose</b></a> along with the
standard adaptors can be rewritten using <a href="bind.html"><b>boost::bind</b></a>
that automatically takes advantage of <b>mem_fn</b>.
</p>
<h3><a name="Q2">Should I replace every occurence of <b>std::mem_fun[_ref]</b> with <b>mem_fn</b>
in my existing code?</a></h3>
<p>
No, unless you have good reasons to do so. <b>mem_fn</b> is not 100% compatible
with the standard adaptors, although it comes pretty close. In particular, <b>mem_fn</b>
does not return objects of type <b>std::[const_]mem_fun[1][_ref]_t</b>, as the
standard adaptors do, and it is not possible to fully describe the type of the
first argument using the standard <b>argument_type</b> and <b>first_argument_type</b>
nested typedefs. Libraries that need adaptable function objects in order to
function might not like <b>mem_fn</b>.
</p>
<h3><a name="Q3">Does <b>mem_fn</b> work with COM methods?</a></h3>
<p>
Yes, if you <a href="#stdcall">#define BOOST_MEM_FN_ENABLE_STDCALL</a>.
</p>
<h3><a name="Q4">Why isn't BOOST_MEM_FN_ENABLE_STDCALL defined automatically?</a></h3>
<p>
Non-portable extensions, in general, should default to off to prevent vendor
lock-in. Had BOOST_MEM_FN_ENABLE_STDCALL been defined automatically, you could
have accidentally taken advantage of it without realizing that your code is,
perhaps, no longer portable.
</p>
<h2><a name="Interface">Interface</a></h2>
<h3><a name="Synopsis">Synopsis</a></h3>
<pre>
namespace boost
{
template&lt;class T&gt; T * <a href="#get_pointer_1">get_pointer</a> (T * p);
template&lt;class R, class T&gt; <i>implementation-defined-1</i> <a href="#mem_fn_1">mem_fn</a>(R (T::*pmf) ());
template&lt;class R, class T&gt; <i>implementation-defined-2</i> <a href="#mem_fn_2">mem_fn</a>(R (T::*pmf) () const);
template&lt;class R, class T, class A1&gt; <i>implementation-defined-3</i> <a href="#mem_fn_3">mem_fn</a>(R (T::*pmf) (A1));
template&lt;class R, class T, class A1&gt; <i>implementation-defined-4</i> <a href="#mem_fn_4">mem_fn</a>(R (T::*pmf) (A1) const);
template&lt;class R, class T, class A1, class A2&gt; <i>implementation-defined-5</i> <a href="#mem_fn_5">mem_fn</a>(R (T::*pmf) (A1, A2));
template&lt;class R, class T, class A1, class A2&gt; <i>implementation-defined-6</i> <a href="#mem_fn_6">mem_fn</a>(R (T::*pmf) (A1, A2) const);
// implementation defined number of additional overloads for more arguments
}
</pre>
<h3><a name="CommonRequirements">Common requirements</a></h3>
<p>
All <tt><i>implementation-defined-N</i></tt> types mentioned in the Synopsis
are <b>CopyConstructible</b> and <b>Assignable</b>. Their copy constructors and
assignment operators do not throw exceptions. <tt><i>implementation-defined-N</i>::result_type</tt>
is defined as the return type of the member function pointer passed as an
argument to <b>mem_fn</b> (<b>R</b> in the Synopsis.)
</p>
<h3><a name="get_pointer">get_pointer</a></h3>
<h4><a name="get_pointer_1">template&lt;class T&gt; T * get_pointer(T * p)</a></h4>
<blockquote>
<p>
<b>Returns:</b> <tt>p</tt>.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h3><a name="mem_fn">mem_fn</a></h3>
<h4><a name="mem_fn_1">template&lt;class R, class T&gt; <i>implementation-defined-1</i>
mem_fn(R (T::*pmf) ())</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t)</i></tt>
is equivalent to <tt>(t.*pmf)()</tt> when <i>t</i> is an l-value of type <STRONG>T </STRONG>
or derived, <tt>(get_pointer(t)-&gt;*pmf)()</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="mem_fn_2">template&lt;class R, class T&gt; <i>implementation-defined-2</i>
mem_fn(R (T::*pmf) () const)</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t)</i></tt>
is equivalent to <tt>(t.*pmf)()</tt> when <i>t</i> is of type <STRONG>T</STRONG>
<EM>[const]<STRONG> </STRONG></EM>or derived, <tt>(get_pointer(t)-&gt;*pmf)()</tt>
otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="mem_fn_3">template&lt;class R, class T, class A1&gt; <i>implementation-defined-3</i>
mem_fn(R (T::*pmf) (A1))</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t, a1)</i></tt>
is equivalent to <tt>(t.*pmf)(a1)</tt> when <i>t</i> is an l-value of type <STRONG>T
</STRONG>or derived, <tt>(get_pointer(t)-&gt;*pmf)(a1)</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="mem_fn_4">template&lt;class R, class T, class A1&gt; <i>implementation-defined-4</i>
mem_fn(R (T::*pmf) (A1) const)</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t, a1)</i></tt>
is equivalent to <tt>(t.*pmf)(a1)</tt> when <i>t</i> is of type <STRONG>T</STRONG>
<EM>[const]<STRONG> </STRONG></EM>or derived, <tt>(get_pointer(t)-&gt;*pmf)(a1)</tt>
otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="mem_fn_5">template&lt;class R, class T, class A1, class A2&gt; <i>implementation-defined-5</i>
mem_fn(R (T::*pmf) (A1, A2))</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t, a1, a2)</i></tt>
is equivalent to <tt>(t.*pmf)(a1, a2)</tt> when <i>t</i> is an l-value of type <STRONG>
T</STRONG> or derived, <tt>(get_pointer(t)-&gt;*pmf)(a1, a2)</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="mem_fn_6">template&lt;class R, class T, class A1, class A2&gt; <i>implementation-defined-6</i>
mem_fn(R (T::*pmf) (A1, A2) const)</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t, a1, a2)</i></tt>
is equivalent to <tt>(t.*pmf)(a1, a2)</tt> when <i>t</i> is of type <STRONG>T</STRONG>
<EM>[const]</EM> or derived, <tt>(get_pointer(t)-&gt;*pmf)(a1, a2)</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h2><a name="Implementation">Implementation</a></h2>
<h3><a name="Files">Files</a></h3>
<ul>
<li>
<a href="../../boost/mem_fn.hpp">boost/mem_fn.hpp</a>
(main header)
<li>
<a href="../../boost/bind/mem_fn_cc.hpp">boost/bind/mem_fn_cc.hpp</a>
(used by mem_fn.hpp, do not include directly)
<li>
<a href="../../boost/bind/mem_fn_vw.hpp">boost/bind/mem_fn_vw.hpp</a>
(used by mem_fn.hpp, do not include directly)
<li>
<a href="../../boost/bind/mem_fn_template.hpp">boost/bind/mem_fn_template.hpp</a>
(used by mem_fn.hpp, do not include directly)
<li>
<a href="mem_fn_test.cpp">libs/bind/mem_fn_test.cpp</a>
(test)
<li>
<a href="mem_fn_stdcall_test.cpp">libs/bind/mem_fn_stdcall_test.cpp</a>
(test for __stdcall)
<li>
<a href="mem_fn_void_test.cpp">libs/bind/mem_fn_void_test.cpp</a> (test for
void returns)</li>
</ul>
<h3><a name="Dependencies">Dependencies</a></h3>
<ul>
<li>
<a href="../config/config.htm">Boost.Config</a></li>
</ul>
<h3><a name="NumberOfArguments">Number of Arguments</a></h3>
<p>
This implementation supports member functions with up to eight arguments. This
is not an inherent limitation of the design, but an implementation detail.
</p>
<h3><a name="stdcall">"__stdcall" Support</a></h3>
<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
arguments passed, how is the return value handled, and who cleans up the stack
- if any.)
</p>
<p>
For example, Windows API functions and COM interface member functions use a
calling convention known as <b>__stdcall</b>.
</p>
<p>
To use <b>mem_fn</b> with <b>__stdcall</b> member functions, <b>#define</b> the
macro <b>BOOST_MEM_FN_ENABLE_STDCALL</b> before including, directly or
indirectly, <b>&lt;boost/mem_fn.hpp&gt;</b>.
</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>
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
<p>
Rene Jager's initial suggestion of using traits classes to make <b>mem_fn</b> adapt
to user-defined smart pointers inspired the <b>get_pointer</b>-based design.
</p>
<p>
Numerous improvements were suggested during the formal review period by Richard
Crossley, Jens Maurer, Ed Brey, and others. Review manager was Darin Adler.
</p>
<p>
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 © 2001, 2002&nbsp;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 is provided "as is"
without express or implied warranty, and with no claim as to its suitability
for any purpose.</small></p>
</body>
<head>
<meta http-equiv="refresh" content="0; URL=../bind/mem_fn.html">
</head>
<body>
Automatic redirection failed, please go to
<a href="../bind/mem_fn.html">../bind/mem_fn.html</a>.
</body>
</html>

200
ref.html
View File

@@ -1,195 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Boost: ref.hpp documentation</title>
</head>
<body bgcolor="White">
<table border="0" width="100%">
<tr>
<td width="277">
<img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86">
</td>
<td align="center">
<table border="0">
<tr>
<td nowrap><h1>ref.hpp</h1>
</td>
</tr>
<tr>
<td align="right" nowrap><small>&nbsp;1.00.0004 (2002-01-27)</small></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" height="64">&nbsp;</td>
</tr>
</table>
<h2>Files</h2>
<ul>
<li>
<a href="../../boost/ref.hpp">ref.hpp</a>
</ul>
<h2>Purpose</h2>
<p>
The header <a href="../../boost/ref.hpp">boost/ref.hpp</a> defines the class
template <b>boost::reference_wrapper&lt;T&gt;</b>, the two functions <b>boost::ref</b>
and <b>boost::cref</b> that return instances of <b>boost::reference_wrapper&lt;T&gt;</b>,
and the two traits classes <b>boost::is_reference_wrapper&lt;T&gt;</b> and <b>boost::unwrap_reference&lt;T&gt;</b>.
</p>
<p>
The purpose of <b>boost::reference_wrapper&lt;T&gt;</b> is to contain a
reference to an object of type <b>T</b>. It is primarily used to "feed"
references to function templates (algorithms) that take their parameter by
value.
</p>
<p>
To support this usage, <b>boost::reference_wrapper&lt;T&gt;</b> provides an
implicit conversion to <b>T &amp;</b>. This usually allows the function
templates to work on references unmodified.
</p>
<p>
<b>boost::reference_wrapper&lt;T&gt;</b> is both <b>CopyConstructible</b> and <b>Assignable</b>
(ordinary references are not <b>Assignable</b>).
</p>
<p>
The expression <b>boost::ref(x)</b> returns a <b>boost::reference_wrapper&lt;X&gt;(x)</b>
where <b>X</b> is the type of <b>x</b>. Similarly, <b>boost::cref(x)</b> returns
a <b>boost::reference_wrapper&lt;X const&gt;(x)</b>.
</p>
<p>
The expression <b>boost::is_reference_wrapper&lt;T&gt;::value</b> is <b>true</b>
if <b>T</b> is a <b>reference_wrapper</b>, and <b>false</b>
otherwise.
</p>
<p>
The type-expression <b>boost::unwrap_reference&lt;T&gt;::type</b> is <b>T::type</b>
if <b>T</b> is a <b>reference_wrapper</b>, <b>T</b> otherwise.
</p>
<h2>Interface</h2>
<h3>Synopsis</h3>
<pre>
namespace boost
{
template&lt;class T&gt; class <a href="#reference_wrapper">reference_wrapper</a>;
template&lt;class T&gt; reference_wrapper&lt;T&gt; <a href="#ref">ref</a>(T &amp; t);
template&lt;class T&gt; reference_wrapper&lt;T const&gt; <a href="#cref">cref</a>(T const &amp; t);
template&lt;class T&gt; class is_reference_wrapper&lt;T const&gt;;
template&lt;class T&gt; class unwrap_reference&lt;T const&gt;;
}
</pre>
<h3><a name="reference_wrapper">reference_wrapper</a></h3>
<pre>
template&lt;class T&gt; class reference_wrapper
{
public:
typedef T type;
explicit <a href="#rt_construct">reference_wrapper</a>(T &amp; t);
<a href="#rt_operator">operator T &amp;</a> () const;
T &amp; <a href="#rt_get">get</a>() const;
T* <a href="#rt_get_pointer">get_pointer</a>() const;
};
</pre>
<h4><a name="rt_construct">explicit reference_wrapper(T &amp; t)</a></h4>
<blockquote>
<p>
<b>Effects:</b> Constructs a <b>reference_wrapper</b> object that stores a
reference to <b>t</b>.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="rt_operator">operator T &amp; () const</a></h4>
<blockquote>
<p>
<b>Returns:</b> the stored reference.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="rt_get">T &amp; get() const</a></h4>
<blockquote>
<p>
<b>Returns:</b> the stored reference.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="rt_get_pointer">T* get_pointer() const</a></h4>
<blockquote>
<p>
<b>Returns:</b> a pointer to the stored object.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h3><a name="ref">ref</a></h3>
<pre>
template&lt;class T&gt; reference_wrapper&lt;T&gt; ref(T &amp; t);
</pre>
<blockquote>
<p>
<b>Returns:</b> <tt>reference_wrapper&lt;T&gt;(t)</tt>.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h3><a name="cref">cref</a></h3>
<pre>
template&lt;class T&gt; reference_wrapper&lt;T const&gt; cref(T const &amp; t);
</pre>
<blockquote>
<p>
<b>Returns:</b> <tt>reference_wrapper&lt;T const&gt;(t)</tt>.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h3><a name="is_reference_wrapper">is_reference_wrapper</a></h3>
<pre>
template&lt;class T&gt; class is_reference_wrapper&lt;T const&gt;
{
public:
static bool value = <i>unspecified</i>;
};
</pre>
Value is <b>true</b> iff <tt>T</tt> is a specialization of <tt>reference_wrapper</tt>.
<h3><a name="unwrap_reference">unwrap_reference</a></h3>
<pre>
template&lt;class T&gt; class unwrap_reference&lt;T const&gt;
{
public:
typedef <i>unspecified</i> type;
};
</pre>
<tt>type</tt> is equivalent to <tt>T::type</tt> if <tt>T</tt> is a
specialization of <tt>reference_wrapper</tt>. Otherwise <tt>type</tt> is
equivalent to <tt>T</tt>.
<h2>Acknowledgements</h2>
<p>
<b>ref</b> and <b>cref</b> were originally part of the Boost.Tuple library by <a href="../../people/jaakko_jarvi.htm">
Jaakko J&auml;rvi</a>. They were "promoted to <b>boost::</b> status" by <a href="../../people/peter_dimov.htm">
Peter Dimov</a> because they are generally useful. <a href="../../people/doug_gregor.html">
Douglas Gregor</a> and <a href="../../people/dave_abrahams.htm">Dave Abrahams</a>
contributed <tt>is_reference_wrapper</tt> and <tt>unwrap_reference</tt>.
</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 is provided &quot;as
is&quot; without express or implied warranty, and with no claim as to its
suitability for any purpose.</small></p>
</body>
<head>
<meta http-equiv="refresh" content="0; URL=../../doc/html/ref.html">
</head>
<body>
Automatic redirection failed, please go to
<a href="../../doc/html/ref.html">../../doc/html/ref.html</a>
</body>
</html>

26
test/Jamfile Normal file
View File

@@ -0,0 +1,26 @@
# Boost.Bind Library test Jamfile
#
# Copyright (c) 2003 Peter Dimov
#
# 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.
subproject libs/bind/test ;
# bring in rules for testing
SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
include testing.jam ;
# Make tests run by default.
DEPENDS all : bind ;
{
test-suite "bind"
: [ run bind_test.cpp ]
[ run mem_fn_test.cpp ]
[ run mem_fn_void_test.cpp ]
[ run mem_fn_derived_test.cpp ]
;
}

View File

@@ -0,0 +1,163 @@
#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 <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) {}
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 main()
{
member_function_test();
return boost::report_errors();
}

109
test/bind_fastcall_test.cpp Normal file
View File

@@ -0,0 +1,109 @@
#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 <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>
//
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 main()
{
function_test();
return boost::report_errors();
}

View File

@@ -30,9 +30,7 @@
#pragma warning(pop)
#endif
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
#include <boost/detail/lightweight_test.hpp>
struct X
{
@@ -158,8 +156,8 @@ void member_function_test()
BOOST_TEST( x.hash == 23558 );
}
int test_main(int, char * [])
int main()
{
member_function_test();
return 0;
return boost::report_errors();
}

View File

@@ -30,8 +30,7 @@
#pragma warning(pop)
#endif
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
#include <boost/detail/lightweight_test.hpp>
//
@@ -103,8 +102,8 @@ void function_test()
BOOST_TEST( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i) == 987654321L );
}
int test_main(int, char * [])
int main()
{
function_test();
return 0;
return boost::report_errors();
}

View File

@@ -30,9 +30,7 @@
#pragma warning(pop)
#endif
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
#include <boost/detail/lightweight_test.hpp>
//
@@ -192,12 +190,31 @@ void function_object_test()
#if !defined(__MWERKS__) || (__MWERKS__ > 0x2406) // Fails for this version of the compiler.
global_result = 0;
bind<void>(Y(), i, _1, 9, 4)(k);
BOOST_TEST( global_result == 4938 );
#endif
}
void function_object_test2()
{
using namespace boost;
short i(6);
int const k = 3;
BOOST_TEST( bind(type<short>(), Y(), ref(i))() == 7 );
BOOST_TEST( bind(type<short>(), Y(), ref(i))() == 8 );
BOOST_TEST( bind(type<int>(), Y(), i, _1)(k) == 38 );
BOOST_TEST( bind(type<long>(), Y(), i, _1, 9)(k) == 938 );
global_result = 0;
bind(type<void>(), Y(), i, _1, 9, 4)(k);
BOOST_TEST( global_result == 4938 );
}
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
@@ -485,10 +502,11 @@ void nested_bind_test()
BOOST_TEST( (bind(fv_1, bind(f_0))(), (global_result == 17041L)) );
}
int test_main(int, char * [])
int main()
{
function_test();
function_object_test();
function_object_test2();
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
adaptable_function_object_test();
@@ -498,5 +516,5 @@ int test_main(int, char * [])
member_function_void_test();
nested_bind_test();
return 0;
return boost::report_errors();
}

View File

@@ -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 <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) {}
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<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);
}