2
0
mirror of https://github.com/boostorg/bind.git synced 2026-02-22 14:32:10 +00:00

Merge of new boost.thread code along with required changes from boost.bind

[SVN r46474]
This commit is contained in:
Anthony Williams
2008-06-18 13:01:08 +00:00
parent 224e9f5eec
commit e22e641bbf
10 changed files with 916 additions and 22 deletions

View File

@@ -27,10 +27,15 @@ test-suite "bind"
[ run bind_visit_test.cpp ]
[ run bind_placeholder_test.cpp ]
[ run bind_rvalue_test.cpp ]
[ run bind_and_or_test.cpp ]
[ run mem_fn_test.cpp ]
[ run mem_fn_void_test.cpp ]
[ run mem_fn_derived_test.cpp ]
[ run mem_fn_eq_test.cpp ]
[ run mem_fn_dm_test.cpp ]
[ run mem_fn_rv_test.cpp ]
[ run ref_fn_test.cpp ]
[ run bind_fnobj2_test.cpp ]
[ run bind_fn2_test.cpp ]
[ run bind_mf2_test.cpp ]
;

84
test/bind_and_or_test.cpp Normal file
View File

@@ -0,0 +1,84 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#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_and_or_test.cpp - &&, || operators
//
// Copyright (c) 2008 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#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>
bool f( bool x )
{
return x;
}
bool g( bool x )
{
return !x;
}
bool h()
{
BOOST_ERROR( "Short-circuit evaluation failure" );
return false;
}
template< class F, class A1, class A2, class R > void test( F f, A1 a1, A2 a2, R r )
{
BOOST_TEST( f( a1, a2 ) == r );
}
int main()
{
// &&
test( boost::bind( f, true ) && boost::bind( g, true ), false, false, f( true ) && g( true ) );
test( boost::bind( f, true ) && boost::bind( g, false ), false, false, f( true ) && g( false ) );
test( boost::bind( f, false ) && boost::bind( h ), false, false, f( false ) && h() );
test( boost::bind( f, _1 ) && boost::bind( g, _2 ), true, true, f( true ) && g( true ) );
test( boost::bind( f, _1 ) && boost::bind( g, _2 ), true, false, f( true ) && g( false ) );
test( boost::bind( f, _1 ) && boost::bind( h ), false, false, f( false ) && h() );
// ||
test( boost::bind( f, false ) || boost::bind( g, true ), false, false, f( false ) || g( true ) );
test( boost::bind( f, false ) || boost::bind( g, false ), false, false, f( false ) || g( false ) );
test( boost::bind( f, true ) || boost::bind( h ), false, false, f( true ) || h() );
test( boost::bind( f, _1 ) || boost::bind( g, _2 ), false, true, f( false ) || g( true ) );
test( boost::bind( f, _1 ) || boost::bind( g, _2 ), false, false, f( false ) || g( false ) );
test( boost::bind( f, _1 ) || boost::bind( h ), true, false, f( true ) || h() );
//
return boost::report_errors();
}

171
test/bind_fn2_test.cpp Normal file
View File

@@ -0,0 +1,171 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#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_fn2_test.cpp - test for functions w/ the type<> syntax
//
// Copyright (c) 2005, 2008 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#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 global_result;
// long
long f_0()
{
return global_result = 17041L;
}
long f_1(long a)
{
return global_result = a;
}
long f_2(long a, long b)
{
return global_result = a + 10 * b;
}
long f_3(long a, long b, long c)
{
return global_result = a + 10 * b + 100 * c;
}
long f_4(long a, long b, long c, long d)
{
return global_result = a + 10 * b + 100 * c + 1000 * d;
}
long f_5(long a, long b, long c, long d, long e)
{
return global_result = 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 global_result = 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 global_result = 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 global_result = 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 global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
// void
void fv_0()
{
global_result = 17041L;
}
void fv_1(long a)
{
global_result = a;
}
void fv_2(long a, long b)
{
global_result = a + 10 * b;
}
void fv_3(long a, long b, long c)
{
global_result = a + 10 * b + 100 * c;
}
void fv_4(long a, long b, long c, long d)
{
global_result = a + 10 * b + 100 * c + 1000 * d;
}
void fv_5(long a, long b, long c, long d, long e)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
void fv_6(long a, long b, long c, long d, long e, long f)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
void fv_7(long a, long b, long c, long d, long e, long f, long g)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
void fv_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
void fv_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
void function_test()
{
using namespace boost;
bind( type<void>(), f_0 )(); BOOST_TEST( global_result == 17041L );
bind( type<void>(), f_1, 1 )(); BOOST_TEST( global_result == 1L );
bind( type<void>(), f_2, 1, 2 )(); BOOST_TEST( global_result == 21L );
bind( type<void>(), f_3, 1, 2, 3 )(); BOOST_TEST( global_result == 321L );
bind( type<void>(), f_4, 1, 2, 3, 4 )(); BOOST_TEST( global_result == 4321L );
bind( type<void>(), f_5, 1, 2, 3, 4, 5 )(); BOOST_TEST( global_result == 54321L );
bind( type<void>(), f_6, 1, 2, 3, 4, 5, 6 )(); BOOST_TEST( global_result == 654321L );
bind( type<void>(), f_7, 1, 2, 3, 4, 5, 6, 7 )(); BOOST_TEST( global_result == 7654321L );
bind( type<void>(), f_8, 1, 2, 3, 4, 5, 6, 7, 8 )(); BOOST_TEST( global_result == 87654321L );
bind( type<void>(), f_9, 1, 2, 3, 4, 5, 6, 7, 8, 9 )(); BOOST_TEST( global_result == 987654321L );
bind( type<void>(), fv_0 )(); BOOST_TEST( global_result == 17041L );
bind( type<void>(), fv_1, 1 )(); BOOST_TEST( global_result == 1L );
bind( type<void>(), fv_2, 1, 2 )(); BOOST_TEST( global_result == 21L );
bind( type<void>(), fv_3, 1, 2, 3 )(); BOOST_TEST( global_result == 321L );
bind( type<void>(), fv_4, 1, 2, 3, 4 )(); BOOST_TEST( global_result == 4321L );
bind( type<void>(), fv_5, 1, 2, 3, 4, 5 )(); BOOST_TEST( global_result == 54321L );
bind( type<void>(), fv_6, 1, 2, 3, 4, 5, 6 )(); BOOST_TEST( global_result == 654321L );
bind( type<void>(), fv_7, 1, 2, 3, 4, 5, 6, 7 )(); BOOST_TEST( global_result == 7654321L );
bind( type<void>(), fv_8, 1, 2, 3, 4, 5, 6, 7, 8 )(); BOOST_TEST( global_result == 87654321L );
bind( type<void>(), fv_9, 1, 2, 3, 4, 5, 6, 7, 8, 9 )(); BOOST_TEST( global_result == 987654321L );
}
int main()
{
function_test();
return boost::report_errors();
}

76
test/bind_fnobj2_test.cpp Normal file
View File

@@ -0,0 +1,76 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#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_fnobj2_test.cpp - test for function objects w/ the type<> syntax
//
// Copyright (c) 2005, 2008 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#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) {}
int operator()() const { operator()(17); return 0; }
int operator()(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int operator()(int a1, int a2) const { operator()(a1); operator()(a2); return 0; }
int operator()(int a1, int a2, int a3) const { operator()(a1, a2); operator()(a3); return 0; }
int operator()(int a1, int a2, int a3, int a4) const { operator()(a1, a2, a3); operator()(a4); return 0; }
int operator()(int a1, int a2, int a3, int a4, int a5) const { operator()(a1, a2, a3, a4); operator()(a5); return 0; }
int operator()(int a1, int a2, int a3, int a4, int a5, int a6) const { operator()(a1, a2, a3, a4, a5); operator()(a6); return 0; }
int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { operator()(a1, a2, a3, a4, a5, a6); operator()(a7); return 0; }
int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { operator()(a1, a2, a3, a4, a5, a6, a7); operator()(a8); return 0; }
int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9) const { operator()(a1, a2, a3, a4, a5, a6, a7, a8); operator()(a9); return 0; }
};
void function_object_test()
{
using namespace boost;
X x;
bind( type<void>(), ref(x) )();
bind( type<void>(), ref(x), 1 )();
bind( type<void>(), ref(x), 1, 2 )();
bind( type<void>(), ref(x), 1, 2, 3 )();
bind( type<void>(), ref(x), 1, 2, 3, 4 )();
bind( type<void>(), ref(x), 1, 2, 3, 4, 5 )();
bind( type<void>(), ref(x), 1, 2, 3, 4, 5, 6 )();
bind( type<void>(), ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind( type<void>(), ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
bind( type<void>(), ref(x), 1, 2, 3, 4, 5, 6, 7, 8, 9 )();
BOOST_TEST( x.hash == 9932 );
}
int main()
{
function_object_test();
return boost::report_errors();
}

View File

@@ -1,7 +1,7 @@
//
// bind_lookup_problem_test.cpp
//
// Copyright (C) Markus Schöpflin 2005.
// Copyright (C) Markus Schoepflin 2005.
//
// Use, modification, and distribution are subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

162
test/bind_mf2_test.cpp Normal file
View File

@@ -0,0 +1,162 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#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_mf2_test.cpp - test for member functions w/ the type<> syntax
//
// Copyright (c) 2005, 2008 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#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) {}
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; }
};
void member_function_test()
{
using namespace boost;
X x;
// 0
bind( type<void>(), &X::f0, &x )();
bind( type<void>(), &X::f0, ref(x) )();
bind( type<void>(), &X::g0, &x )();
bind( type<void>(), &X::g0, x )();
bind( type<void>(), &X::g0, ref(x) )();
// 1
bind( type<void>(), &X::f1, &x, 1 )();
bind( type<void>(), &X::f1, ref(x), 1 )();
bind( type<void>(), &X::g1, &x, 1 )();
bind( type<void>(), &X::g1, x, 1 )();
bind( type<void>(), &X::g1, ref(x), 1 )();
// 2
bind( type<void>(), &X::f2, &x, 1, 2 )();
bind( type<void>(), &X::f2, ref(x), 1, 2 )();
bind( type<void>(), &X::g2, &x, 1, 2 )();
bind( type<void>(), &X::g2, x, 1, 2 )();
bind( type<void>(), &X::g2, ref(x), 1, 2 )();
// 3
bind( type<void>(), &X::f3, &x, 1, 2, 3 )();
bind( type<void>(), &X::f3, ref(x), 1, 2, 3 )();
bind( type<void>(), &X::g3, &x, 1, 2, 3 )();
bind( type<void>(), &X::g3, x, 1, 2, 3 )();
bind( type<void>(), &X::g3, ref(x), 1, 2, 3 )();
// 4
bind( type<void>(), &X::f4, &x, 1, 2, 3, 4 )();
bind( type<void>(), &X::f4, ref(x), 1, 2, 3, 4 )();
bind( type<void>(), &X::g4, &x, 1, 2, 3, 4 )();
bind( type<void>(), &X::g4, x, 1, 2, 3, 4 )();
bind( type<void>(), &X::g4, ref(x), 1, 2, 3, 4 )();
// 5
bind( type<void>(), &X::f5, &x, 1, 2, 3, 4, 5 )();
bind( type<void>(), &X::f5, ref(x), 1, 2, 3, 4, 5 )();
bind( type<void>(), &X::g5, &x, 1, 2, 3, 4, 5 )();
bind( type<void>(), &X::g5, x, 1, 2, 3, 4, 5 )();
bind( type<void>(), &X::g5, ref(x), 1, 2, 3, 4, 5 )();
// 6
bind( type<void>(), &X::f6, &x, 1, 2, 3, 4, 5, 6 )();
bind( type<void>(), &X::f6, ref(x), 1, 2, 3, 4, 5, 6 )();
bind( type<void>(), &X::g6, &x, 1, 2, 3, 4, 5, 6 )();
bind( type<void>(), &X::g6, x, 1, 2, 3, 4, 5, 6 )();
bind( type<void>(), &X::g6, ref(x), 1, 2, 3, 4, 5, 6 )();
// 7
bind( type<void>(), &X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind( type<void>(), &X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind( type<void>(), &X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind( type<void>(), &X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
bind( type<void>(), &X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
bind( type<void>(), &X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8 )();
bind( type<void>(), &X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
bind( type<void>(), &X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8 )();
bind( type<void>(), &X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8 )();
bind( type<void>(), &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();
}

81
test/ref_fn_test.cpp Normal file
View File

@@ -0,0 +1,81 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#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
// ref_fn_test.cpp: ref( f )
//
// Copyright (c) 2008 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/ref.hpp>
#include <boost/detail/lightweight_test.hpp>
void f0()
{
}
void f1(int)
{
}
void f2(int, int)
{
}
void f3(int, int, int)
{
}
void f4(int, int, int, int)
{
}
void f5(int, int, int, int, int)
{
}
void f6(int, int, int, int, int, int)
{
}
void f7(int, int, int, int, int, int, int)
{
}
void f8(int, int, int, int, int, int, int, int)
{
}
void f9(int, int, int, int, int, int, int, int, int)
{
}
#define BOOST_TEST_REF( f ) BOOST_TEST( &boost::ref( f ).get() == &f )
int main()
{
int v = 0;
BOOST_TEST_REF( v );
BOOST_TEST_REF( f0 );
BOOST_TEST_REF( f1 );
BOOST_TEST_REF( f2 );
BOOST_TEST_REF( f3 );
BOOST_TEST_REF( f4 );
BOOST_TEST_REF( f5 );
BOOST_TEST_REF( f6 );
BOOST_TEST_REF( f7 );
BOOST_TEST_REF( f8 );
BOOST_TEST_REF( f9 );
return boost::report_errors();
}