mirror of
https://github.com/boostorg/bind.git
synced 2026-04-15 14:16:08 +02:00
Compare commits
3 Commits
boost-1.25
...
boost-1.25
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7a2460e4b | ||
|
|
c61d480cb6 | ||
|
|
b9bb33048f |
71
bind.html
71
bind.html
@@ -17,7 +17,7 @@
|
||||
<td align="center">
|
||||
<table border="0">
|
||||
<tr><td nowrap><h1>bind.hpp</h1></td></tr>
|
||||
<tr><td align="right" nowrap><small> 1.01.0001 (2001-09-02)</small></td></tr>
|
||||
<tr><td align="right" nowrap><small> 1.02.0001 (2001-10-18)</small></td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -29,12 +29,9 @@
|
||||
<h2>Files</h2>
|
||||
<ul>
|
||||
<li><a href="../../boost/bind.hpp">bind.hpp</a> (implementation)</li>
|
||||
<li><a href="bind_test.cpp">bind_test.cpp</a> (monolithic test)</li>
|
||||
<li><a href="bind_test_1.cpp">bind_test_1.cpp</a> (test with function pointers)</li>
|
||||
<li><a href="bind_test_2.cpp">bind_test_2.cpp</a> (test with function objects)</li>
|
||||
<li><a href="bind_test_3.cpp">bind_test_3.cpp</a> (test with member function pointers)</li>
|
||||
<li><a href="bind_test_4.cpp">bind_test_4.cpp</a> (test with a visitor)</li>
|
||||
<li><a href="bind_test.cpp">bind_test.cpp</a> (test)</li>
|
||||
<li><a href="bind_as_compose.cpp">bind_as_compose.cpp</a> (function composition example)</li>
|
||||
<li><a href="bind_visitor.cpp">bind_visitor.cpp</a> (visitor example)</li>
|
||||
</ul>
|
||||
|
||||
<h2>Purpose</h2>
|
||||
@@ -111,6 +108,14 @@ bind(g, _3, _3, _3)(x, y, z); // g(z, z, z)
|
||||
bind(g, _1, _1, _1)(x, y, z); // g(x, x, x)
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Note that, in the last example, the function object produced by
|
||||
<tt>bind(g, _1, _1, _1)</tt> does not contain references to any arguments
|
||||
beyond the first, but it can still be used with more than one argument.
|
||||
Any extra arguments are silently ignored, just like the first and the second
|
||||
argument are ignored in the third example.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The arguments that <b>bind</b> takes are copied and held internally by
|
||||
the returned function object. For example, in the following code:
|
||||
@@ -138,10 +143,10 @@ bind(f, ref(i), _1);
|
||||
<h3>Using bind with function objects</h3>
|
||||
|
||||
<p>
|
||||
Any function object can be passed as a first argument to <b>bind</b>, but the
|
||||
syntax is a bit different. The return type of the generated function object's
|
||||
<b>bind</b> is not limited to functions; it accepts arbitrary function objects.
|
||||
In the general case, the return type of the generated function object's
|
||||
<b>operator()</b> has to be specified explicitly (without a <b>typeof</b>
|
||||
operator the return type cannot be inferred in the general case):
|
||||
operator the return type cannot be inferred):
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
@@ -159,11 +164,18 @@ bind<int>(f, _1, _1)(x); // f(x, x), i.e. zero
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
[Note: when, hopefully,
|
||||
<a href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#226">
|
||||
function template default arguments</a> become part of C++,
|
||||
<b>bind</b> will no longer require the explicit specification of the return type
|
||||
when the function object defines <b>result_type</b>.]
|
||||
When the function object exposes a nested type named <b>result_type</b>,
|
||||
the explicit return type can be omitted:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
int x = 8;
|
||||
|
||||
bind(std::less<int>, _1, 9)(x); // x < 9
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
[Note: the ability to omit the return type is not available on all compilers.]
|
||||
</p>
|
||||
|
||||
<h3>Using bind with member function pointers</h3>
|
||||
@@ -395,12 +407,16 @@ namespace boost
|
||||
|
||||
template<class R, class F> <i>implementation-defined-1</i> <a href="#bind_1">bind</a>(F f);
|
||||
|
||||
template<class F> <i>implementation-defined-1-1</i> <a href="#bind_1_1">bind</a>(F f);
|
||||
|
||||
template<class R> <i>implementation-defined-2</i> <a href="#bind_2">bind</a>(R (*f) ());
|
||||
|
||||
// one argument
|
||||
|
||||
template<class R, class F, class A1> <i>implementation-defined-3</i> <a href="#bind_3">bind</a>(F f, A1 a1);
|
||||
|
||||
template<class F, class A1> <i>implementation-defined-3-1</i> <a href="#bind_3_1">bind</a>(F f, A1 a1);
|
||||
|
||||
template<class R, class B1, class A1> <i>implementation-defined-4</i> <a href="#bind_4">bind</a>(R (*f) (B1), A1 a1);
|
||||
|
||||
template<class R, class T, class A1> <i>implementation-defined-5</i> <a href="#bind_5">bind</a>(R (T::*f) (), A1 a1);
|
||||
@@ -411,6 +427,8 @@ template<class R, class T, class A1> <i>implementation-defined-6</i> <a hr
|
||||
|
||||
template<class R, class F, class A1, class A2> <i>implementation-defined-7</i> <a href="#bind_7">bind</a>(F f, A1 a1, A2 a2);
|
||||
|
||||
template<class F, class A1, class A2> <i>implementation-defined-7-1</i> <a href="#bind_7_1">bind</a>(F f, A1 a1, A2 a2);
|
||||
|
||||
template<class R, class B1, class B2, class A1, class A2> <i>implementation-defined-8</i> <a href="#bind_8">bind</a>(R (*f) (B1, B2), A1 a1, A2 a2);
|
||||
|
||||
template<class R, class T, class B1, class A1, class A2> <i>implementation-defined-9</i> <a href="#bind_9">bind</a>(R (T::*f) (B1), A1 a1, A2 a2);
|
||||
@@ -477,6 +495,12 @@ implicitly converted to <b>R</b>.
|
||||
<b>Throws:</b> Nothing unless the copy constructor of <b>F</b> throws an exception.
|
||||
</p>
|
||||
|
||||
<h4><a name="bind_1_1">template<class F> <i>implementation-defined-1-1</i> bind(F f)</a></h4>
|
||||
|
||||
<p>
|
||||
<b>Effects:</b> equivalent to <tt>bind<typename F::result_type, F>(f);</tt>
|
||||
</p>
|
||||
|
||||
<h4><a name="bind_2">template<class R> <i>implementation-defined-2</i> bind(R (*f) ())</a></h4>
|
||||
|
||||
<p>
|
||||
@@ -499,6 +523,12 @@ implicitly converted to <b>R</b>.
|
||||
<b>Throws:</b> Nothing unless the copy constructors of <b>F</b> and <b>A1</b> throw an exception.
|
||||
</p>
|
||||
|
||||
<h4><a name="bind_3_1">template<class F, class A1> <i>implementation-defined-3-1</i> bind(F f, A1 a1)</a></h4>
|
||||
|
||||
<p>
|
||||
<b>Effects:</b> equivalent to <tt>bind<typename F::result_type, F, A1>(f, a1);</tt>
|
||||
</p>
|
||||
|
||||
<h4><a name="bind_4">template<class R, class B1, class A1> <i>implementation-defined-4</i> bind(R (*f) (B1), A1 a1)</a></h4>
|
||||
|
||||
<p>
|
||||
@@ -534,6 +564,12 @@ implicitly converted to <b>R</b>.
|
||||
<b>Throws:</b> Nothing unless the copy constructors of <b>F</b>, <b>A1</b> and <b>A2</b> throw an exception.
|
||||
</p>
|
||||
|
||||
<h4><a name="bind_7_1">template<class F, class A1, class A2> <i>implementation-defined-7-1</i> bind(F f, A1 a1, A2 a2)</a></h4>
|
||||
|
||||
<p>
|
||||
<b>Effects:</b> equivalent to <tt>bind<typename F::result_type, F, A1, A2>(f, a1, a2);</tt>
|
||||
</p>
|
||||
|
||||
<h4><a name="bind_8">template<class R, class B1, class B2, class A1, class A2> <i>implementation-defined-8</i> bind(R (*f) (B1, B2), A1 a1, A2 a2)</a></h4>
|
||||
|
||||
<p>
|
||||
@@ -658,7 +694,7 @@ that applies <b>v</b>, as a function object, to its internal state. Using
|
||||
</p>
|
||||
|
||||
<p>
|
||||
See <a href="bind_test_4.cpp">bind_test_4.cpp</a> for an example.
|
||||
See <a href="bind_visitor.cpp">bind_visitor.cpp</a> for an example.
|
||||
</p>
|
||||
|
||||
<h2>Acknowledgements</h2>
|
||||
@@ -696,6 +732,11 @@ was Darin Adler.
|
||||
The precise semantics of <b>bind</b> were refined in discussions with Jaakko Järvi.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
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><br><br><br><small>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
|
||||
|
||||
@@ -120,6 +120,23 @@ void function_object_test()
|
||||
|
||||
//
|
||||
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||
|
||||
struct Z
|
||||
{
|
||||
typedef int result_type;
|
||||
int operator()(int a, int b) const { return a + 10 * b; }
|
||||
};
|
||||
|
||||
void adaptable_function_object_test()
|
||||
{
|
||||
BOOST_TEST( boost::bind(Z(), 7, 4)() == 47 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//
|
||||
|
||||
struct X
|
||||
{
|
||||
mutable unsigned int hash;
|
||||
@@ -262,6 +279,9 @@ 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();
|
||||
nested_bind_test();
|
||||
|
||||
|
||||
104
bind_test_1.cpp
104
bind_test_1.cpp
@@ -1,104 +0,0 @@
|
||||
#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_test_1.cpp - tests bind.hpp with function pointers
|
||||
//
|
||||
// Version 1.00.0003 (2001-07-13)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <iostream>
|
||||
|
||||
long f_1(long a)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
long f_2(long a, long b)
|
||||
{
|
||||
return a + 10 * b;
|
||||
}
|
||||
|
||||
long f_3(long a, long b, long c)
|
||||
{
|
||||
return a + 10 * b + 100 * c;
|
||||
}
|
||||
|
||||
long f_4(long a, long b, long c, long d)
|
||||
{
|
||||
return a + 10 * b + 100 * c + 1000 * d;
|
||||
}
|
||||
|
||||
long f_5(long a, long b, long c, long d, long e)
|
||||
{
|
||||
return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
|
||||
}
|
||||
|
||||
long 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 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 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 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;
|
||||
}
|
||||
|
||||
unsigned long hash = 0;
|
||||
|
||||
template<class F> void test(F f)
|
||||
{
|
||||
int const i = 1;
|
||||
hash = (hash * 17041 + f(i)) % 32768;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
test(boost::bind(f_1, _1));
|
||||
test(boost::bind(f_2, _1, 2));
|
||||
test(boost::bind(f_3, _1, 2, 3));
|
||||
test(boost::bind(f_4, _1, 2, 3, 4));
|
||||
test(boost::bind(f_5, _1, 2, 3, 4, 5));
|
||||
test(boost::bind(f_6, _1, 2, 3, 4, 5, 6));
|
||||
test(boost::bind(f_7, _1, 2, 3, 4, 5, 6, 7));
|
||||
test(boost::bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8));
|
||||
test(boost::bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9));
|
||||
|
||||
return detect_errors(hash == 18797);
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#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_test_2.cpp - tests bind.hpp with function objects
|
||||
//
|
||||
// Version 1.00.0005 (2001-07-13)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <iostream>
|
||||
|
||||
struct X
|
||||
{
|
||||
short operator()(short & r) const { return ++r; }
|
||||
int operator()(int a, int b) const { return a + 10 * b; }
|
||||
long operator() (long a, long b, long c) const { return a + 10 * b + 100 * c; }
|
||||
};
|
||||
|
||||
unsigned long hash = 0;
|
||||
|
||||
template<class F> void test(F f, int const i)
|
||||
{
|
||||
hash = (hash * 17041 + f(i)) % 32768;
|
||||
}
|
||||
|
||||
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 namespace boost;
|
||||
|
||||
short i(6);
|
||||
|
||||
test(bind<short>(X(), ref(i)), 1);
|
||||
test(bind<short>(X(), ref(i)), 2);
|
||||
test(bind<int>(X(), i, _1), 3);
|
||||
test(bind<long>(X(), i, _1, 9), 4);
|
||||
|
||||
return detect_errors(hash == 24857);
|
||||
}
|
||||
161
bind_test_3.cpp
161
bind_test_3.cpp
@@ -1,161 +0,0 @@
|
||||
#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_test_3.cpp - tests bind.hpp with member function pointers
|
||||
//
|
||||
// Version 1.00.0003 (2001-07-13)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <iostream>
|
||||
|
||||
struct X
|
||||
{
|
||||
mutable unsigned int hash;
|
||||
|
||||
X(): hash(0) {}
|
||||
|
||||
int f0() { f1(17); return 0; }
|
||||
int g0() const { g1(17); return 0; }
|
||||
|
||||
int f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
|
||||
int g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
|
||||
|
||||
int f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
|
||||
int g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
|
||||
|
||||
int f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
|
||||
int g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
|
||||
|
||||
int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
|
||||
int g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
|
||||
|
||||
int f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
|
||||
int g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
|
||||
|
||||
int f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
|
||||
int g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
|
||||
|
||||
int f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
|
||||
int g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
|
||||
|
||||
int f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
|
||||
int g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
|
||||
};
|
||||
|
||||
int detect_errors(bool x)
|
||||
{
|
||||
if(x)
|
||||
{
|
||||
std::cerr << "no errors detected.\n";
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "test failed.\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using 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)();
|
||||
|
||||
return detect_errors(x.hash == 23558);
|
||||
}
|
||||
@@ -6,9 +6,9 @@
|
||||
#endif
|
||||
|
||||
//
|
||||
// bind_test_4.cpp - tests bind.hpp with a visitor
|
||||
// bind_visitor.cpp - tests bind.hpp with a visitor
|
||||
//
|
||||
// Version 1.00.0003 (2001-08-30)
|
||||
// Version 1.00.0003 (2001-10-18)
|
||||
//
|
||||
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
|
||||
//
|
||||
@@ -8,7 +8,7 @@
|
||||
//
|
||||
// bind.hpp - binds function objects to arguments
|
||||
//
|
||||
// Version 1.01.0001 (2001-08-29)
|
||||
// Version 1.02.0001 (2001-10-18)
|
||||
//
|
||||
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
|
||||
//
|
||||
@@ -512,144 +512,170 @@ private:
|
||||
list9 & operator= (list9 const &);
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||
|
||||
// unspecified
|
||||
|
||||
struct unspecified {};
|
||||
|
||||
template<class R, class F> struct result_traits
|
||||
{
|
||||
typedef R type;
|
||||
};
|
||||
|
||||
template<class F> struct result_traits<unspecified, F>
|
||||
{
|
||||
typedef typename F::result_type type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// bind_t
|
||||
|
||||
template<class R, class F, class L> class bind_t
|
||||
{
|
||||
public:
|
||||
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||
|
||||
typedef typename result_traits<R, F>::type result_type;
|
||||
|
||||
#else
|
||||
|
||||
typedef R result_type;
|
||||
|
||||
#endif
|
||||
|
||||
bind_t(F f, L const & l): f_(f), l_(l) {}
|
||||
|
||||
R operator()()
|
||||
result_type operator()()
|
||||
{
|
||||
list0 a;
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
R operator()() const
|
||||
result_type operator()() const
|
||||
{
|
||||
list0 a;
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1> R operator()(A1 & a1)
|
||||
template<class A1> result_type operator()(A1 & a1)
|
||||
{
|
||||
list1<A1 &> a(a1);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1> R operator()(A1 & a1) const
|
||||
template<class A1> result_type operator()(A1 & a1) const
|
||||
{
|
||||
list1<A1 &> a(a1);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2> R operator()(A1 & a1, A2 & a2)
|
||||
template<class A1, class A2> result_type operator()(A1 & a1, A2 & a2)
|
||||
{
|
||||
list2<A1 &, A2 &> a(a1, a2);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2> R operator()(A1 & a1, A2 & a2) const
|
||||
template<class A1, class A2> result_type operator()(A1 & a1, A2 & a2) const
|
||||
{
|
||||
list2<A1 &, A2 &> a(a1, a2);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3> R operator()(A1 & a1, A2 & a2, A3 & a3)
|
||||
template<class A1, class A2, class A3> result_type operator()(A1 & a1, A2 & a2, A3 & a3)
|
||||
{
|
||||
list3<A1 &, A2 &, A3 &> a(a1, a2, a3);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3> R operator()(A1 & a1, A2 & a2, A3 & a3) const
|
||||
template<class A1, class A2, class A3> result_type operator()(A1 & a1, A2 & a2, A3 & a3) const
|
||||
{
|
||||
list3<A1 &, A2 &, A3 &> a(a1, a2, a3);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4)
|
||||
template<class A1, class A2, class A3, class A4> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4)
|
||||
{
|
||||
list4<A1 &, A2 &, A3 &, A4 &> a(a1, a2, a3, a4);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4) const
|
||||
template<class A1, class A2, class A3, class A4> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4) const
|
||||
{
|
||||
list4<A1 &, A2 &, A3 &, A4 &> a(a1, a2, a3, a4);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4, class A5> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5)
|
||||
template<class A1, class A2, class A3, class A4, class A5> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5)
|
||||
{
|
||||
list5<A1 &, A2 &, A3 &, A4 &, A5 &> a(a1, a2, a3, a4, a5);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4, class A5> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5) const
|
||||
template<class A1, class A2, class A3, class A4, class A5> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5) const
|
||||
{
|
||||
list5<A1 &, A2 &, A3 &, A4 &, A5 &> a(a1, a2, a3, a4, a5);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6)
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6)
|
||||
{
|
||||
list6<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &> a(a1, a2, a3, a4, a5, a6);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6) const
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6) const
|
||||
{
|
||||
list6<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &> a(a1, a2, a3, a4, a5, a6);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7)
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7)
|
||||
{
|
||||
list7<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &> a(a1, a2, a3, a4, a5, a6, a7);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7) const
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7) const
|
||||
{
|
||||
list7<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &> a(a1, a2, a3, a4, a5, a6, a7);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8)
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8)
|
||||
{
|
||||
list8<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &, A8 &> a(a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8) const
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8) const
|
||||
{
|
||||
list8<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &, A8 &> a(a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8, A9 & a9)
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8, A9 & a9)
|
||||
{
|
||||
list9<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &, A8 &, A9 &> a(a1, a2, a3, a4, a5, a6, a7, a8, a9);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> R operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8, A9 & a9) const
|
||||
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8, A9 & a9) const
|
||||
{
|
||||
list9<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &, A8 &, A9 &> a(a1, a2, a3, a4, a5, a6, a7, a8, a9);
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A> R eval(A & a)
|
||||
template<class A> result_type eval(A & a)
|
||||
{
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class A> R eval(A & a) const
|
||||
template<class A> result_type eval(A & a) const
|
||||
{
|
||||
return l_(type<R>(), f_, a);
|
||||
return l_(type<result_type>(), f_, a);
|
||||
}
|
||||
|
||||
template<class V> void accept(V & v) const
|
||||
@@ -915,6 +941,92 @@ 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));
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||
|
||||
// adaptable function objects
|
||||
|
||||
template<class F>
|
||||
_bi::bind_t<_bi::unspecified, F, _bi::list0>
|
||||
BOOST_BIND(F f)
|
||||
{
|
||||
typedef _bi::list0 list_type;
|
||||
return _bi::bind_t<_bi::unspecified, F, list_type> (f, list_type());
|
||||
}
|
||||
|
||||
template<class F, class A1>
|
||||
_bi::bind_t<_bi::unspecified, F, typename _bi::list_av_1<A1>::type>
|
||||
BOOST_BIND(F f, A1 a1)
|
||||
{
|
||||
typedef typename _bi::list_av_1<A1>::type list_type;
|
||||
return _bi::bind_t<_bi::unspecified, F, list_type> (f, list_type(a1));
|
||||
}
|
||||
|
||||
template<class F, class A1, class A2>
|
||||
_bi::bind_t<_bi::unspecified, F, typename _bi::list_av_2<A1, A2>::type>
|
||||
BOOST_BIND(F f, A1 a1, A2 a2)
|
||||
{
|
||||
typedef typename _bi::list_av_2<A1, A2>::type list_type;
|
||||
return _bi::bind_t<_bi::unspecified, F, list_type> (f, list_type(a1, a2));
|
||||
}
|
||||
|
||||
template<class F, class A1, class A2, class A3>
|
||||
_bi::bind_t<_bi::unspecified, F, typename _bi::list_av_3<A1, A2, A3>::type>
|
||||
BOOST_BIND(F f, A1 a1, A2 a2, A3 a3)
|
||||
{
|
||||
typedef typename _bi::list_av_3<A1, A2, A3>::type list_type;
|
||||
return _bi::bind_t<_bi::unspecified, F, list_type>(f, list_type(a1, a2, a3));
|
||||
}
|
||||
|
||||
template<class F, class A1, class A2, class A3, class A4>
|
||||
_bi::bind_t<_bi::unspecified, F, typename _bi::list_av_4<A1, A2, A3, A4>::type>
|
||||
BOOST_BIND(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<_bi::unspecified, F, list_type>(f, list_type(a1, a2, a3, a4));
|
||||
}
|
||||
|
||||
template<class F, class A1, class A2, class A3, class A4, class A5>
|
||||
_bi::bind_t<_bi::unspecified, F, typename _bi::list_av_5<A1, A2, A3, A4, A5>::type>
|
||||
BOOST_BIND(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<_bi::unspecified, F, list_type>(f, list_type(a1, a2, a3, a4, a5));
|
||||
}
|
||||
|
||||
template<class F, class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
_bi::bind_t<_bi::unspecified, F, typename _bi::list_av_6<A1, A2, A3, A4, A5, A6>::type>
|
||||
BOOST_BIND(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<_bi::unspecified, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6));
|
||||
}
|
||||
|
||||
template<class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
|
||||
_bi::bind_t<_bi::unspecified, F, typename _bi::list_av_7<A1, A2, A3, A4, A5, A6, A7>::type>
|
||||
BOOST_BIND(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<_bi::unspecified, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6, a7));
|
||||
}
|
||||
|
||||
template<class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
|
||||
_bi::bind_t<_bi::unspecified, F, typename _bi::list_av_8<A1, A2, A3, A4, A5, A6, A7, A8>::type>
|
||||
BOOST_BIND(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<_bi::unspecified, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8));
|
||||
}
|
||||
|
||||
template<class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
|
||||
_bi::bind_t<_bi::unspecified, F, typename _bi::list_av_9<A1, A2, A3, A4, A5, A6, A7, A8, A9>::type>
|
||||
BOOST_BIND(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<_bi::unspecified, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// function pointers
|
||||
|
||||
template<class R>
|
||||
|
||||
Reference in New Issue
Block a user