forked from boostorg/bind
Removed bind_test_?.cpp
[SVN r11400]
This commit is contained in:
@@ -29,12 +29,9 @@
|
|||||||
<h2>Files</h2>
|
<h2>Files</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="../../boost/bind.hpp">bind.hpp</a> (implementation)</li>
|
<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.cpp">bind_test.cpp</a> (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_as_compose.cpp">bind_as_compose.cpp</a> (function composition example)</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>
|
</ul>
|
||||||
|
|
||||||
<h2>Purpose</h2>
|
<h2>Purpose</h2>
|
||||||
@@ -658,7 +655,7 @@ that applies <b>v</b>, as a function object, to its internal state. Using
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<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>
|
</p>
|
||||||
|
|
||||||
<h2>Acknowledgements</h2>
|
<h2>Acknowledgements</h2>
|
||||||
|
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
|
#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.
|
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
|
||||||
//
|
//
|
Reference in New Issue
Block a user