early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,11 @@
# Copyright 2018, 2019 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(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
if(HAVE_BOOST_TEST)
boost_test_jamfile(FILE Jamfile.v2 LINK_LIBRARIES Boost::bind Boost::core Boost::function Boost::smart_ptr)
endif()

View File

@@ -0,0 +1,85 @@
# Boost.Bind Library test Jamfile
#
# Copyright (c) 2003-2006, 2017 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)
# bring in rules for testing
import testing ;
# quick test (for CI)
run quick.cpp ;
# full test suite
run bind_test.cpp ;
run bind_dm_test.cpp ;
run bind_eq_test.cpp ;
run bind_const_test.cpp ;
run bind_cv_test.cpp ;
run bind_stateful_test.cpp ;
run bind_dm2_test.cpp ;
run bind_not_test.cpp ;
run bind_rel_test.cpp ;
run bind_function_test.cpp ;
run bind_lookup_problem_test.cpp ;
run bind_rv_sp_test.cpp ;
compile bind_unary_addr.cpp ;
run bind_dm3_test.cpp ;
run bind_visit_test.cpp ;
run bind_placeholder_test.cpp ;
run bind_rvalue_test.cpp ;
run bind_and_or_test.cpp ;
run bind_void_test.cpp ;
run bind_void_dm_test.cpp ;
run bind_void_mf_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 ;
run bind_eq2_test.cpp ;
run mem_fn_ref_test.cpp ;
run bind_ref_test.cpp ;
run bind_eq3_test.cpp ;
run protect_test.cpp ;
run mem_fn_unary_addr_test.cpp ;
run bind_function2_test.cpp ;
run bind_fwd_test.cpp ;
run bind_fwd2_test.cpp ;
run bind_no_placeholders_test.cpp ;
run placeholder_const_ref_test.cpp ;
run bind_function_ap_test.cpp ;
run bind_type_test.cpp ;
run bind_unique_ptr_test.cpp ;
run bind_nested_rv_test.cpp ;
compile arg_copy_test.cpp ;
compile-fail arg_copy_fail.cpp ;
run placeholder_std_bind_test.cpp ;
run bind_fastcall_test.cpp ;
run bind_stdcall_test.cpp ;
run bind_cdecl_mf_test.cpp ;
run bind_fastcall_mf_test.cpp ;
run bind_stdcall_mf_test.cpp ;
run mem_fn_cdecl_test.cpp ;
run mem_fn_fastcall_test.cpp ;
run mem_fn_stdcall_test.cpp ;
run bind_noexcept_test.cpp ;
run bind_noexcept_mf_test.cpp ;
run global_placeholders.cpp ;
run mem_fn_noexcept_test.cpp ;
run bind_cpp20_test.cpp ;
run protect_test2.cpp ;
run protect_cpp20_test.cpp ;
run bind_noexcept_mf2_test.cpp ;
run std_placeholders_test.cpp ;
run apply_test.cpp ;
run apply_test2.cpp ;
run apply_rv_test.cpp ;
run apply_rv_test2.cpp ;

View File

@@ -0,0 +1,77 @@
// Copyright 2021 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include<boost/bind/apply.hpp>
#include<boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_RVALUE_REFERENCES is defined")
int main() {}
#elif defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined")
int main() {}
#else
struct F
{
public:
int operator()( int & x ) const
{
return x;
}
int operator()( int && x ) const
{
return -x;
}
};
int& get_lvalue_arg()
{
static int a = 1;
return a;
}
int get_prvalue_arg()
{
return 2;
}
F& get_lvalue_f()
{
static F f;
return f;
}
F get_prvalue_f()
{
return F();
}
int main()
{
using namespace boost::placeholders;
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_lvalue_f), boost::bind(get_lvalue_arg))(), 1 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_lvalue_f), boost::bind(get_prvalue_arg))(), -2 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_prvalue_f), boost::bind(get_lvalue_arg))(), 1 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_prvalue_f), boost::bind(get_prvalue_arg))(), -2 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F&>(), _1), boost::bind(boost::apply<int&>(), _2))(get_lvalue_f, get_lvalue_arg), 1 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F&>(), _1), boost::bind(boost::apply<int>(), _2))(get_lvalue_f, get_prvalue_arg), -2 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F>(), _1), boost::bind(boost::apply<int&>(), _2))(get_prvalue_f, get_lvalue_arg), 1 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F>(), _1), boost::bind(boost::apply<int>(), _2))(get_prvalue_f, get_prvalue_arg), -2 );
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,92 @@
// Copyright 2021 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include<boost/bind/apply.hpp>
#include<boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_RVALUE_REFERENCES is defined")
int main() {}
#elif defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined")
int main() {}
#elif defined(BOOST_NO_CXX11_REF_QUALIFIERS)
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_REF_QUALIFIERS is defined")
int main() {}
#else
struct F
{
public:
int operator()( int & x ) &
{
return x;
}
int operator()( int && x ) &
{
return -x;
}
int operator()( int & x ) &&
{
return x + 10;
}
int operator()( int && x ) &&
{
return -x - 10;
}
};
int& get_lvalue_arg()
{
static int a = 1;
return a;
}
int get_prvalue_arg()
{
return 2;
}
F& get_lvalue_f()
{
static F f;
return f;
}
F get_prvalue_f()
{
return F();
}
int main()
{
using namespace boost::placeholders;
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_lvalue_f), boost::bind(get_lvalue_arg))(), 1 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_lvalue_f), boost::bind(get_prvalue_arg))(), -2 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_prvalue_f), boost::bind(get_lvalue_arg))(), 11 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_prvalue_f), boost::bind(get_prvalue_arg))(), -12 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F&>(), _1), boost::bind(boost::apply<int&>(), _2))(get_lvalue_f, get_lvalue_arg), 1 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F&>(), _1), boost::bind(boost::apply<int>(), _2))(get_lvalue_f, get_prvalue_arg), -2 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F>(), _1), boost::bind(boost::apply<int&>(), _2))(get_prvalue_f, get_lvalue_arg), 11 );
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F>(), _1), boost::bind(boost::apply<int>(), _2))(get_prvalue_f, get_prvalue_arg), -12 );
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,29 @@
// Copyright 2021 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/bind/apply.hpp>
#include <boost/bind/protect.hpp>
#include <boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
int f( int x )
{
return x;
}
int main()
{
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _1 ) ), 1 )(), 1 );
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _2 ) ), 1, 2 )(), 2 );
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _3 ) ), 1, 2, 3 )(), 3 );
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _4 ) ), 1, 2, 3, 4 )(), 4 );
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _5 ) ), 1, 2, 3, 4, 5 )(), 5 );
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _6 ) ), 1, 2, 3, 4, 5, 6 )(), 6 );
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _7 ) ), 1, 2, 3, 4, 5, 6, 7 )(), 7 );
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _8 ) ), 1, 2, 3, 4, 5, 6, 7, 8 )(), 8 );
return boost::report_errors();
}

View File

@@ -0,0 +1,15 @@
// Copyright 2021 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/bind/apply.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/core/is_same.hpp>
int main()
{
BOOST_TEST_TRAIT_TRUE((boost::core::is_same<void, boost::apply<void>::result_type>));
BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int&, boost::apply<int&>::result_type>));
return boost::report_errors();
}

View File

@@ -0,0 +1,19 @@
//
// arg_copy_fail.cpp - arg<1> to arg<2>
//
// Copyright 2016 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/arg.hpp>
//
int main()
{
boost::arg<1> a1(( boost::arg<2>() ));
(void)a1;
}

View File

@@ -0,0 +1,34 @@
//
// arg_copy_test.cpp - copying a custom placeholder _1 to arg<1>
//
// Copyright 2016 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/is_placeholder.hpp>
#include <boost/bind/arg.hpp>
//
template<int I> struct ph
{
};
namespace boost
{
template<int I> struct is_placeholder< ::ph<I> >
{
enum _vt { value = I };
};
} // namespace boost
int main()
{
boost::arg<1> a1 = ph<1>();
(void)a1;
}

View File

@@ -0,0 +1,77 @@
#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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
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();
}

View File

@@ -0,0 +1,165 @@
#include <boost/config.hpp>
#ifndef BOOST_MSVC
int main()
{
}
#else
#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_cdecl_mf_test.cpp - test for bind.hpp + __cdecl (member functions)
//
// Copyright (c) 2005 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)
//
#define BOOST_MEM_FN_ENABLE_CDECL
#include <boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
//
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int __cdecl f0() { f1(17); return 0; }
int __cdecl g0() const { g1(17); return 0; }
int __cdecl f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int __cdecl g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int __cdecl f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
int __cdecl g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
int __cdecl f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
int __cdecl g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
int __cdecl f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
int __cdecl g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
int __cdecl f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
int __cdecl g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
int __cdecl f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int __cdecl 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 __cdecl 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 __cdecl 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 __cdecl 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 __cdecl 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(&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();
}
#endif

View File

@@ -0,0 +1,175 @@
#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_const_test.cpp - test const bind objects
//
// Copyright (c) 2001-2004 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001 David Abrahams
//
// 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/bind.hpp>
#include <boost/ref.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
long f_0()
{
return 17041L;
}
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;
}
long global_result;
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;
}
template<class F, class A> long test(F const & f, A const & a)
{
return f(a);
}
template<class F, class A> long testv(F const & f, A const & a)
{
f(a);
return global_result;
}
void function_test()
{
using namespace boost;
int const i = 1;
BOOST_TEST( test( bind(f_0), i ) == 17041L );
BOOST_TEST( test( bind(f_1, _1), i ) == 1L );
BOOST_TEST( test( bind(f_2, _1, 2), i ) == 21L );
BOOST_TEST( test( bind(f_3, _1, 2, 3), i ) == 321L );
BOOST_TEST( test( bind(f_4, _1, 2, 3, 4), i ) == 4321L );
BOOST_TEST( test( bind(f_5, _1, 2, 3, 4, 5), i ) == 54321L );
BOOST_TEST( test( bind(f_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
BOOST_TEST( test( bind(f_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
BOOST_TEST( test( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
BOOST_TEST( test( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
BOOST_TEST( testv( bind(fv_0), i ) == 17041L );
BOOST_TEST( testv( bind(fv_1, _1), i ) == 1L );
BOOST_TEST( testv( bind(fv_2, _1, 2), i ) == 21L );
BOOST_TEST( testv( bind(fv_3, _1, 2, 3), i ) == 321L );
BOOST_TEST( testv( bind(fv_4, _1, 2, 3, 4), i ) == 4321L );
BOOST_TEST( testv( bind(fv_5, _1, 2, 3, 4, 5), i ) == 54321L );
BOOST_TEST( testv( bind(fv_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
BOOST_TEST( testv( bind(fv_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
BOOST_TEST( testv( bind(fv_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
BOOST_TEST( testv( bind(fv_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
}
int main()
{
function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,42 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt)
#include <boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <functional>
//
int main()
{
BOOST_TEST_EQ( boost::bind( std::plus<int>(), 1, 2 )(), 3 );
BOOST_TEST_EQ( boost::bind( std::minus<int>(), 1, 2 )(), -1 );
BOOST_TEST_EQ( boost::bind( std::multiplies<int>(), 1, 2 )(), 2 );
BOOST_TEST_EQ( boost::bind( std::divides<int>(), 1, 2 )(), 0 );
BOOST_TEST_EQ( boost::bind( std::modulus<int>(), 1, 2 )(), 1 );
BOOST_TEST_EQ( boost::bind( std::negate<int>(), 1 )(), -1 );
BOOST_TEST_EQ( boost::bind( std::equal_to<int>(), 1, 2 )(), false );
BOOST_TEST_EQ( boost::bind( std::not_equal_to<int>(), 1, 2 )(), true );
BOOST_TEST_EQ( boost::bind( std::greater<int>(), 1, 2 )(), false );
BOOST_TEST_EQ( boost::bind( std::less<int>(), 1, 2 )(), true );
BOOST_TEST_EQ( boost::bind( std::greater_equal<int>(), 1, 2 )(), false );
BOOST_TEST_EQ( boost::bind( std::less_equal<int>(), 1, 2 )(), true );
BOOST_TEST_EQ( boost::bind( std::logical_and<int>(), 1, 2 )(), true );
BOOST_TEST_EQ( boost::bind( std::logical_or<int>(), 1, 2 )(), true );
BOOST_TEST_EQ( boost::bind( std::logical_not<int>(), 1 )(), false );
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1600)
BOOST_TEST_EQ( boost::bind( std::bit_and<int>(), 1, 2 )(), 0 );
BOOST_TEST_EQ( boost::bind( std::bit_or<int>(), 1, 2 )(), 3 );
BOOST_TEST_EQ( boost::bind( std::bit_xor<int>(), 1, 2 )(), 3 );
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,155 @@
#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_cv_test.cpp
//
// Copyright (c) 2004 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
//
struct X
{
// SGI-related compilers have odd compiler-synthesized ctors dtors
#ifdef __PATHSCALE__
X() {}
~X() {}
#endif
int operator()()
{
return 17041;
}
int operator()() const
{
return -17041;
}
int operator()(int x1)
{
return x1;
}
int operator()(int x1) const
{
return -x1;
}
int operator()(int x1, int x2)
{
return x1+x2;
}
int operator()(int x1, int x2) const
{
return -(x1+x2);
}
int operator()(int x1, int x2, int x3)
{
return x1+x2+x3;
}
int operator()(int x1, int x2, int x3) const
{
return -(x1+x2+x3);
}
int operator()(int x1, int x2, int x3, int x4)
{
return x1+x2+x3+x4;
}
int operator()(int x1, int x2, int x3, int x4) const
{
return -(x1+x2+x3+x4);
}
int operator()(int x1, int x2, int x3, int x4, int x5)
{
return x1+x2+x3+x4+x5;
}
int operator()(int x1, int x2, int x3, int x4, int x5) const
{
return -(x1+x2+x3+x4+x5);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6)
{
return x1+x2+x3+x4+x5+x6;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6) const
{
return -(x1+x2+x3+x4+x5+x6);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7)
{
return x1+x2+x3+x4+x5+x6+x7;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) const
{
return -(x1+x2+x3+x4+x5+x6+x7);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
{
return x1+x2+x3+x4+x5+x6+x7+x8;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) const
{
return -(x1+x2+x3+x4+x5+x6+x7+x8);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9)
{
return x1+x2+x3+x4+x5+x6+x7+x8+x9;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) const
{
return -(x1+x2+x3+x4+x5+x6+x7+x8+x9);
}
};
template<class F> void test(F f, int r)
{
F const & cf = f;
BOOST_TEST( cf() == -r );
BOOST_TEST( f() == r );
}
int main()
{
test( boost::bind<int>( X() ), 17041 );
test( boost::bind<int>( X(), 1 ), 1 );
test( boost::bind<int>( X(), 1, 2 ), 1+2 );
test( boost::bind<int>( X(), 1, 2, 3 ), 1+2+3 );
test( boost::bind<int>( X(), 1, 2, 3, 4 ), 1+2+3+4 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5 ), 1+2+3+4+5 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6 ), 1+2+3+4+5+6 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7 ), 1+2+3+4+5+6+7 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 1+2+3+4+5+6+7+8 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 1+2+3+4+5+6+7+8+9 );
return boost::report_errors();
}

View File

@@ -0,0 +1,63 @@
#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_dm2_test.cpp - data members, advanced uses
//
// Copyright (c) 2005 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
#include <string>
using namespace boost::placeholders;
//
struct X
{
int m;
};
struct Y
{
char m[ 64 ];
};
int main()
{
X x = { 0 };
X * px = &x;
boost::bind< int& >( &X::m, _1 )( px ) = 42;
BOOST_TEST( x.m == 42 );
boost::bind< int& >( &X::m, boost::ref(x) )() = 17041;
BOOST_TEST( x.m == 17041 );
X const * pcx = &x;
BOOST_TEST( boost::bind< long >( &X::m, _1 )( pcx ) == 17041L );
BOOST_TEST( boost::bind< long >( &X::m, pcx )() == 17041L );
Y y = { "test" };
std::string v( "test" );
BOOST_TEST( boost::bind< char const* >( &Y::m, &y )() == v );
BOOST_TEST( boost::bind< std::string >( &Y::m, &y )() == v );
return boost::report_errors();
}

View File

@@ -0,0 +1,39 @@
#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_dm3_test.cpp - data members (regression 1.31 - 1.32)
//
// Copyright (c) 2005 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
#include <utility>
using namespace boost::placeholders;
//
int main()
{
typedef std::pair<int, int> pair_type;
pair_type pair( 10, 20 );
int const & x = boost::bind( &pair_type::first, _1 )( pair );
BOOST_TEST( &pair.first == &x );
return boost::report_errors();
}

View File

@@ -0,0 +1,66 @@
#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_dm_test.cpp - data members
//
// Copyright (c) 2005 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
struct X
{
int m;
};
X f( int v )
{
X r = { v };
return r;
}
int main()
{
X x = { 17041 };
X * px = &x;
BOOST_TEST( boost::bind( &X::m, _1 )( x ) == 17041 );
BOOST_TEST( boost::bind( &X::m, _1 )( px ) == 17041 );
BOOST_TEST( boost::bind( &X::m, x )() == 17041 );
BOOST_TEST( boost::bind( &X::m, px )() == 17041 );
BOOST_TEST( boost::bind( &X::m, boost::ref(x) )() == 17041 );
X const cx = x;
X const * pcx = &cx;
BOOST_TEST( boost::bind( &X::m, _1 )( cx ) == 17041 );
BOOST_TEST( boost::bind( &X::m, _1 )( pcx ) == 17041 );
BOOST_TEST( boost::bind( &X::m, cx )() == 17041 );
BOOST_TEST( boost::bind( &X::m, pcx )() == 17041 );
BOOST_TEST( boost::bind( &X::m, boost::ref(cx) )() == 17041 );
int const v = 42;
BOOST_TEST( boost::bind( &X::m, boost::bind( f, _1 ) )( v ) == v );
return boost::report_errors();
}

View File

@@ -0,0 +1,53 @@
#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_eq2_test.cpp - boost::bind equality operator
//
// Copyright (c) 2004, 2005, 2009 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/bind.hpp>
#include <boost/function_equal.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
void f( int )
{
}
int g( int i )
{
return i + 5;
}
template< class F > void test_self_equal( F f )
{
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
using boost::function_equal;
#endif
BOOST_TEST( function_equal( f, f ) );
}
int main()
{
test_self_equal( boost::bind( f, _1 ) );
test_self_equal( boost::bind( g, _1 ) );
test_self_equal( boost::bind( f, boost::bind( g, _1 ) ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,49 @@
#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_eq3_test.cpp - function_equal with bind and weak_ptr
//
// Copyright (c) 2004, 2005, 2009 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/bind.hpp>
#include <boost/function_equal.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/core/lightweight_test.hpp>
//
using namespace boost::placeholders;
int f( boost::weak_ptr<void> wp )
{
return wp.use_count();
}
template< class F > void test_self_equal( F f )
{
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
using boost::function_equal;
#endif
BOOST_TEST( function_equal( f, f ) );
}
int main()
{
test_self_equal( boost::bind( f, _1 ) );
test_self_equal( boost::bind( f, boost::weak_ptr<void>() ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,404 @@
#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_eq_test.cpp - boost::bind equality operator
//
// Copyright (c) 2004, 2005 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/bind.hpp>
#include <boost/ref.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
struct X
{
int i_;
explicit X(int i): i_(i)
{
}
bool operator==(X const & rhs) const
{
return i_ == rhs.i_;
}
};
// f_*
int f_0()
{
return 0;
}
int f_1(X)
{
return 0;
}
int f_2(X, X)
{
return 0;
}
int f_3(X, X, X)
{
return 0;
}
int f_4(X, X, X, X)
{
return 0;
}
int f_5(X, X, X, X, X)
{
return 0;
}
int f_6(X, X, X, X, X, X)
{
return 0;
}
int f_7(X, X, X, X, X, X, X)
{
return 0;
}
int f_8(X, X, X, X, X, X, X, X)
{
return 0;
}
int f_9(X, X, X, X, X, X, X, X, X)
{
return 0;
}
// fv_*
void fv_0()
{
}
void fv_1(X)
{
}
void fv_2(X, X)
{
}
void fv_3(X, X, X)
{
}
void fv_4(X, X, X, X)
{
}
void fv_5(X, X, X, X, X)
{
}
void fv_6(X, X, X, X, X, X)
{
}
void fv_7(X, X, X, X, X, X, X)
{
}
void fv_8(X, X, X, X, X, X, X, X)
{
}
void fv_9(X, X, X, X, X, X, X, X, X)
{
}
template<class F> void test_eq(F f1, F f2)
{
BOOST_TEST( function_equal( f1, f2 ) );
}
template<class F> void test_ne(F f1, F f2)
{
BOOST_TEST( !function_equal( f1, f2 ) );
}
// 0
template<class F> void test_0(F f)
{
test_eq( boost::bind(f), boost::bind(f) );
}
// 1
template<class F, class V> void test_1_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1), boost::bind(f, v1) );
test_ne( boost::bind(f, v1), boost::bind(f, v2) );
}
template<class F> void test_1(F f)
{
test_eq( boost::bind(f, _1), boost::bind(f, _1) );
test_1_( f, X(1), X(2) );
X a(0), b(0);
test_1_( f, boost::ref(a), boost::ref(b) );
}
// 2
template<class F, class V> void test_2_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1), boost::bind(f, v1, v1) );
test_ne( boost::bind(f, v1, v1), boost::bind(f, v1, v2) );
test_ne( boost::bind(f, v1, v1), boost::bind(f, v2, v1) );
}
template<class F> void test_2(F f)
{
test_eq( boost::bind(f, _1, _2), boost::bind(f, _1, _2) );
test_2_( f, X(1), X(2) );
X a(0), b(0);
test_2_( f, boost::ref(a), boost::ref(b) );
}
// 3
template<class F, class V> void test_3_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1), boost::bind(f, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1), boost::bind(f, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1), boost::bind(f, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1), boost::bind(f, v2, v1, v1) );
}
template<class F> void test_3(F f)
{
test_eq( boost::bind(f, _1, _2, _3), boost::bind(f, _1, _2, _3) );
test_3_( f, X(1), X(2) );
X a(0), b(0);
test_3_( f, boost::ref(a), boost::ref(b) );
}
// 4
template<class F, class V> void test_4_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1) );
}
template<class F> void test_4(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4), boost::bind(f, _1, _2, _3, _4) );
test_4_( f, X(1), X(2) );
X a(0), b(0);
test_4_( f, boost::ref(a), boost::ref(b) );
}
// 5
template<class F, class V> void test_5_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1) );
}
template<class F> void test_5(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4, _5), boost::bind(f, _1, _2, _3, _4, _5) );
test_5_( f, X(1), X(2) );
X a(0), b(0);
test_5_( f, boost::ref(a), boost::ref(b) );
}
// 6
template<class F, class V> void test_6_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1) );
}
template<class F> void test_6(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6), boost::bind(f, _1, _2, _3, _4, _5, _6) );
test_6_( f, X(1), X(2) );
X a(0), b(0);
test_6_( f, boost::ref(a), boost::ref(b) );
}
// 7
template<class F, class V> void test_7_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1, v1) );
}
template<class F> void test_7(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6, _7), boost::bind(f, _1, _2, _3, _4, _5, _6, _7) );
test_7_( f, X(1), X(2) );
X a(0), b(0);
test_7_( f, boost::ref(a), boost::ref(b) );
}
// 8
template<class F, class V> void test_8_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1, v1, v1) );
}
template<class F> void test_8(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8), boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8) );
test_8_( f, X(1), X(2) );
X a(0), b(0);
test_8_( f, boost::ref(a), boost::ref(b) );
}
// 9
template<class F, class V> void test_9_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1, v1, v1, v1) );
}
template<class F> void test_9(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8, _9), boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8, _9) );
test_9_( f, X(1), X(2) );
X a(0), b(0);
test_9_( f, boost::ref(a), boost::ref(b) );
}
int main()
{
// 0
test_0( f_0 );
test_0( fv_0 );
// 1
test_1( f_1 );
test_1( fv_1 );
// 2
test_2( f_2 );
test_2( fv_2 );
// 3
test_3( f_3 );
test_3( fv_3 );
// 4
test_4( f_4 );
test_4( fv_4 );
// 5
test_5( f_5 );
test_5( fv_5 );
// 6
test_6( f_6 );
test_6( fv_6 );
// 7
test_7( f_7 );
test_7( fv_7 );
// 8
test_8( f_8 );
test_8( fv_8 );
// 9
test_9( f_9 );
test_9( fv_9 );
return boost::report_errors();
}

View File

@@ -0,0 +1,165 @@
#include <boost/config.hpp>
#ifndef BOOST_MSVC
int main()
{
}
#else
#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_stdcall_mf_test.cpp - test for bind.hpp + __stdcall (member functions)
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// 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)
//
#define BOOST_MEM_FN_ENABLE_FASTCALL
#include <boost/bind/bind.hpp>
#include <boost/core/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();
}
#endif

View File

@@ -0,0 +1,111 @@
#include <boost/config.hpp>
#ifndef BOOST_MSVC
int main()
{
}
#else
#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_fastcall_test.cpp - test for bind.hpp + __fastcall (free functions)
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//
// 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)
//
#define BOOST_BIND_ENABLE_FASTCALL
#include <boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
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();
}
#endif

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_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/bind.hpp>
#include <boost/core/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();
}

View File

@@ -0,0 +1,67 @@
#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/bind.hpp>
#include <boost/core/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

@@ -0,0 +1,130 @@
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ( defined(BOOST_GCC) && BOOST_GCC < 40600 )
BOOST_PRAGMA_MESSAGE( "Skipping test for GCC 4.4 -std=c++0x" )
int main() {}
#else
//
// bind_function2_test.cpp - regression test
//
// Copyright (c) 2015 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/bind.hpp>
#include <boost/function.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
void fv1( int & a )
{
a = 17041;
}
void fv2( int & a, int b )
{
a = b;
}
void fv3( int & a, int b, int c )
{
a = b + c;
}
void fv4( int & a, int b, int c, int d )
{
a = b + c + d;
}
void fv5( int & a, int b, int c, int d, int e )
{
a = b + c + d + e;
}
void fv6( int & a, int b, int c, int d, int e, int f )
{
a = b + c + d + e + f;
}
void fv7( int & a, int b, int c, int d, int e, int f, int g )
{
a = b + c + d + e + f + g;
}
void fv8( int & a, int b, int c, int d, int e, int f, int g, int h )
{
a = b + c + d + e + f + g + h;
}
void fv9( int & a, int b, int c, int d, int e, int f, int g, int h, int i )
{
a = b + c + d + e + f + g + h + i;
}
void function_test()
{
int x = 0;
{
boost::function<void(int&)> fw1 = boost::bind( fv1, _1 );
fw1( x ); BOOST_TEST( x == 17041 );
}
{
boost::function<void(int&, int)> fw2 = boost::bind( fv2, _1, _2 );
fw2( x, 1 ); BOOST_TEST( x == 1 );
}
{
boost::function<void(int&, int, int)> fw3 = boost::bind( fv3, _1, _2, _3 );
fw3( x, 1, 2 ); BOOST_TEST( x == 1+2 );
}
{
boost::function<void(int&, int, int, int)> fw4 = boost::bind( fv4, _1, _2, _3, _4 );
fw4( x, 1, 2, 3 ); BOOST_TEST( x == 1+2+3 );
}
{
boost::function<void(int&, int, int, int, int)> fw5 = boost::bind( fv5, _1, _2, _3, _4, _5 );
fw5( x, 1, 2, 3, 4 ); BOOST_TEST( x == 1+2+3+4 );
}
{
boost::function<void(int&, int, int, int, int, int)> fw6 = boost::bind( fv6, _1, _2, _3, _4, _5, _6 );
fw6( x, 1, 2, 3, 4, 5 ); BOOST_TEST( x == 1+2+3+4+5 );
}
{
boost::function<void(int&, int, int, int, int, int, int)> fw7 = boost::bind( fv7, _1, _2, _3, _4, _5, _6, _7 );
fw7( x, 1, 2, 3, 4, 5, 6 ); BOOST_TEST( x == 1+2+3+4+5+6 );
}
{
boost::function<void(int&, int, int, int, int, int, int, int)> fw8 = boost::bind( fv8, _1, _2, _3, _4, _5, _6, _7, _8 );
fw8( x, 1, 2, 3, 4, 5, 6, 7 ); BOOST_TEST( x == 1+2+3+4+5+6+7 );
}
{
boost::function<void(int&, int, int, int, int, int, int, int, int)> fw9 = boost::bind( fv9, _1, _2, _3, _4, _5, _6, _7, _8, _9 );
fw9( x, 1, 2, 3, 4, 5, 6, 7, 8 ); BOOST_TEST( x == 1+2+3+4+5+6+7+8 );
}
}
int main()
{
function_test();
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,241 @@
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
//
// bind_function_ap_test.cpp - regression test
//
// Copyright (c) 2015 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
//
#if defined(BOOST_NO_AUTO_PTR)
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_AUTO_PTR is defined" )
int main() {}
#elif !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ( defined(BOOST_GCC) && BOOST_GCC < 40600 )
BOOST_PRAGMA_MESSAGE( "Skipping test for GCC 4.4 -std=c++0x" )
int main() {}
#else
#if defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 406 )
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined( __clang__ ) && defined( __has_warning )
# if __has_warning( "-Wdeprecated-declarations" )
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# endif
#endif
#include <boost/bind/bind.hpp>
#include <boost/function.hpp>
#include <boost/core/lightweight_test.hpp>
#include <memory>
using namespace boost::placeholders;
//
void fv1( std::auto_ptr<int> p1 )
{
BOOST_TEST( *p1 == 1 );
}
void fv2( std::auto_ptr<int> p1, std::auto_ptr<int> p2 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
}
void fv3( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
}
void fv4( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
}
void fv5( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
BOOST_TEST( *p5 == 5 );
}
void fv6( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
BOOST_TEST( *p5 == 5 );
BOOST_TEST( *p6 == 6 );
}
void fv7( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6, std::auto_ptr<int> p7 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
BOOST_TEST( *p5 == 5 );
BOOST_TEST( *p6 == 6 );
BOOST_TEST( *p7 == 7 );
}
void fv8( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6, std::auto_ptr<int> p7, std::auto_ptr<int> p8 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
BOOST_TEST( *p5 == 5 );
BOOST_TEST( *p6 == 6 );
BOOST_TEST( *p7 == 7 );
BOOST_TEST( *p8 == 8 );
}
void fv9( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6, std::auto_ptr<int> p7, std::auto_ptr<int> p8, std::auto_ptr<int> p9 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
BOOST_TEST( *p5 == 5 );
BOOST_TEST( *p6 == 6 );
BOOST_TEST( *p7 == 7 );
BOOST_TEST( *p8 == 8 );
BOOST_TEST( *p9 == 9 );
}
void test()
{
{
boost::function<void(std::auto_ptr<int>)> fw1 = boost::bind( fv1, _1 );
std::auto_ptr<int> p1( new int(1) );
fw1( p1 );
}
{
boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>)> fw2 = boost::bind( fv2, _1, _2 );
std::auto_ptr<int> p1( new int(1) );
std::auto_ptr<int> p2( new int(2) );
fw2( p1, p2 );
}
{
boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw3 = boost::bind( fv3, _1, _2, _3 );
std::auto_ptr<int> p1( new int(1) );
std::auto_ptr<int> p2( new int(2) );
std::auto_ptr<int> p3( new int(3) );
fw3( p1, p2, p3 );
}
{
boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw4 = boost::bind( fv4, _1, _2, _3, _4 );
std::auto_ptr<int> p1( new int(1) );
std::auto_ptr<int> p2( new int(2) );
std::auto_ptr<int> p3( new int(3) );
std::auto_ptr<int> p4( new int(4) );
fw4( p1, p2, p3, p4 );
}
{
boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw5 = boost::bind( fv5, _1, _2, _3, _4, _5 );
std::auto_ptr<int> p1( new int(1) );
std::auto_ptr<int> p2( new int(2) );
std::auto_ptr<int> p3( new int(3) );
std::auto_ptr<int> p4( new int(4) );
std::auto_ptr<int> p5( new int(5) );
fw5( p1, p2, p3, p4, p5 );
}
{
boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw6 = boost::bind( fv6, _1, _2, _3, _4, _5, _6 );
std::auto_ptr<int> p1( new int(1) );
std::auto_ptr<int> p2( new int(2) );
std::auto_ptr<int> p3( new int(3) );
std::auto_ptr<int> p4( new int(4) );
std::auto_ptr<int> p5( new int(5) );
std::auto_ptr<int> p6( new int(6) );
fw6( p1, p2, p3, p4, p5, p6 );
}
{
boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw7 = boost::bind( fv7, _1, _2, _3, _4, _5, _6, _7 );
std::auto_ptr<int> p1( new int(1) );
std::auto_ptr<int> p2( new int(2) );
std::auto_ptr<int> p3( new int(3) );
std::auto_ptr<int> p4( new int(4) );
std::auto_ptr<int> p5( new int(5) );
std::auto_ptr<int> p6( new int(6) );
std::auto_ptr<int> p7( new int(7) );
fw7( p1, p2, p3, p4, p5, p6, p7 );
}
{
boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw8 = boost::bind( fv8, _1, _2, _3, _4, _5, _6, _7, _8 );
std::auto_ptr<int> p1( new int(1) );
std::auto_ptr<int> p2( new int(2) );
std::auto_ptr<int> p3( new int(3) );
std::auto_ptr<int> p4( new int(4) );
std::auto_ptr<int> p5( new int(5) );
std::auto_ptr<int> p6( new int(6) );
std::auto_ptr<int> p7( new int(7) );
std::auto_ptr<int> p8( new int(8) );
fw8( p1, p2, p3, p4, p5, p6, p7, p8 );
}
{
boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw9 = boost::bind( fv9, _1, _2, _3, _4, _5, _6, _7, _8, _9 );
std::auto_ptr<int> p1( new int(1) );
std::auto_ptr<int> p2( new int(2) );
std::auto_ptr<int> p3( new int(3) );
std::auto_ptr<int> p4( new int(4) );
std::auto_ptr<int> p5( new int(5) );
std::auto_ptr<int> p6( new int(6) );
std::auto_ptr<int> p7( new int(7) );
std::auto_ptr<int> p8( new int(8) );
std::auto_ptr<int> p9( new int(9) );
fw9( p1, p2, p3, p4, p5, p6, p7, p8, p9 );
}
}
int main()
{
test();
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,69 @@
#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_function_test.cpp - function<>
//
// Copyright (c) 2005 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/bind.hpp>
#include <boost/function.hpp>
#include <boost/core/lightweight_test.hpp>
//
int f( int x )
{
return x;
}
int g( int x )
{
return x + 1;
}
int main()
{
boost::function0<int> fn;
BOOST_TEST( !fn.contains( boost::bind( f, 1 ) ) );
BOOST_TEST( !fn.contains( boost::bind( f, 2 ) ) );
BOOST_TEST( !fn.contains( boost::bind( g, 1 ) ) );
fn = boost::bind( f, 1 );
BOOST_TEST( fn() == 1 );
BOOST_TEST( fn.contains( boost::bind( f, 1 ) ) );
BOOST_TEST( !fn.contains( boost::bind( f, 2 ) ) );
BOOST_TEST( !fn.contains( boost::bind( g, 1 ) ) );
fn = boost::bind( f, 2 );
BOOST_TEST( fn() == 2 );
BOOST_TEST( !fn.contains( boost::bind( f, 1 ) ) );
BOOST_TEST( fn.contains( boost::bind( f, 2 ) ) );
BOOST_TEST( !fn.contains( boost::bind( g, 1 ) ) );
fn = boost::bind( g, 1 );
BOOST_TEST( fn() == 2 );
BOOST_TEST( !fn.contains( boost::bind( f, 1 ) ) );
BOOST_TEST( !fn.contains( boost::bind( f, 2 ) ) );
BOOST_TEST( fn.contains( boost::bind( g, 1 ) ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,123 @@
#include <boost/config.hpp>
//
// bind_fwd2_test.cpp - forwarding test for 2 arguments
//
// Copyright (c) 2015 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
int fv1( int const & a )
{
return a;
}
void fv2_1( int & a, int const & b )
{
a = b;
}
void fv2_2( int const & a, int & b )
{
b = a;
}
int fv2_3( int const & a, int const & b )
{
return a+b;
}
void test()
{
{
int const a = 1;
int r = boost::bind( fv1, _1 )( a );
BOOST_TEST( r == 1 );
}
{
int r = boost::bind( fv1, _1 )( 1 );
BOOST_TEST( r == 1 );
}
{
int a = 1;
int const b = 2;
boost::bind( fv2_1, _1, _2 )( a, b );
BOOST_TEST( a == 2 );
}
{
int a = 1;
boost::bind( fv2_1, _1, _2 )( a, 2 );
BOOST_TEST( a == 2 );
}
{
int const a = 1;
int b = 2;
boost::bind( fv2_2, _1, _2 )( a, b );
BOOST_TEST( b == 1 );
}
{
int b = 2;
boost::bind( fv2_2, _1, _2 )( 1, b );
BOOST_TEST( b == 1 );
}
{
int const a = 1;
int const b = 2;
int r = boost::bind( fv2_3, _1, _2 )( a, b );
BOOST_TEST( r == 3 );
}
{
int const a = 1;
int r = boost::bind( fv2_3, _1, _2 )( a, 2 );
BOOST_TEST( r == 3 );
}
{
int const b = 2;
int r = boost::bind( fv2_3, _1, _2 )( 1, b );
BOOST_TEST( r == 3 );
}
{
int r = boost::bind( fv2_3, _1, _2 )( 1, 2 );
BOOST_TEST( r == 3 );
}
}
int main()
{
test();
return boost::report_errors();
}

View File

@@ -0,0 +1,252 @@
#include <boost/config.hpp>
//
// bind_fwd_test.cpp - forwarding test
//
// Copyright (c) 2015 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
void fv1( int & a )
{
a = 1;
}
void fv2( int & a, int & b )
{
a = 1;
b = 2;
}
void fv3( int & a, int & b, int & c )
{
a = 1;
b = 2;
c = 3;
}
void fv4( int & a, int & b, int & c, int & d )
{
a = 1;
b = 2;
c = 3;
d = 4;
}
void fv5( int & a, int & b, int & c, int & d, int & e )
{
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
}
void fv6( int & a, int & b, int & c, int & d, int & e, int & f )
{
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
}
void fv7( int & a, int & b, int & c, int & d, int & e, int & f, int & g )
{
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
g = 7;
}
void fv8( int & a, int & b, int & c, int & d, int & e, int & f, int & g, int & h )
{
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
g = 7;
h = 8;
}
void fv9( int & a, int & b, int & c, int & d, int & e, int & f, int & g, int & h, int & i )
{
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
g = 7;
h = 8;
i = 9;
}
void test()
{
{
int a = 0;
boost::bind( fv1, _1 )( a );
BOOST_TEST( a == 1 );
}
{
int a = 0;
int b = 0;
boost::bind( fv2, _1, _2 )( a, b );
BOOST_TEST( a == 1 );
BOOST_TEST( b == 2 );
}
{
int a = 0;
int b = 0;
int c = 0;
boost::bind( fv3, _1, _2, _3 )( a, b, c );
BOOST_TEST( a == 1 );
BOOST_TEST( b == 2 );
BOOST_TEST( c == 3 );
}
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
boost::bind( fv4, _1, _2, _3, _4 )( a, b, c, d );
BOOST_TEST( a == 1 );
BOOST_TEST( b == 2 );
BOOST_TEST( c == 3 );
BOOST_TEST( d == 4 );
}
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
boost::bind( fv5, _1, _2, _3, _4, _5 )( a, b, c, d, e );
BOOST_TEST( a == 1 );
BOOST_TEST( b == 2 );
BOOST_TEST( c == 3 );
BOOST_TEST( d == 4 );
BOOST_TEST( e == 5 );
}
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
boost::bind( fv6, _1, _2, _3, _4, _5, _6 )( a, b, c, d, e, f );
BOOST_TEST( a == 1 );
BOOST_TEST( b == 2 );
BOOST_TEST( c == 3 );
BOOST_TEST( d == 4 );
BOOST_TEST( e == 5 );
BOOST_TEST( f == 6 );
}
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
boost::bind( fv7, _1, _2, _3, _4, _5, _6, _7 )( a, b, c, d, e, f, g );
BOOST_TEST( a == 1 );
BOOST_TEST( b == 2 );
BOOST_TEST( c == 3 );
BOOST_TEST( d == 4 );
BOOST_TEST( e == 5 );
BOOST_TEST( f == 6 );
BOOST_TEST( g == 7 );
}
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
boost::bind( fv8, _1, _2, _3, _4, _5, _6, _7, _8 )( a, b, c, d, e, f, g, h );
BOOST_TEST( a == 1 );
BOOST_TEST( b == 2 );
BOOST_TEST( c == 3 );
BOOST_TEST( d == 4 );
BOOST_TEST( e == 5 );
BOOST_TEST( f == 6 );
BOOST_TEST( g == 7 );
BOOST_TEST( h == 8 );
}
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
int i = 0;
boost::bind( fv9, _1, _2, _3, _4, _5, _6, _7, _8, _9 )( a, b, c, d, e, f, g, h, i );
BOOST_TEST( a == 1 );
BOOST_TEST( b == 2 );
BOOST_TEST( c == 3 );
BOOST_TEST( d == 4 );
BOOST_TEST( e == 5 );
BOOST_TEST( f == 6 );
BOOST_TEST( g == 7 );
BOOST_TEST( h == 8 );
BOOST_TEST( i == 9 );
}
}
int main()
{
test();
return boost::report_errors();
}

View File

@@ -0,0 +1,40 @@
//
// bind_lookup_problem_test.cpp
//
// 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
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind/bind.hpp>
template<class T> void value();
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) { }
int main()
{
boost::bind(f0);
boost::bind(f1, 0);
boost::bind(f2, 0, 0);
boost::bind(f3, 0, 0, 0);
boost::bind(f4, 0, 0, 0, 0);
boost::bind(f5, 0, 0, 0, 0, 0);
boost::bind(f6, 0, 0, 0, 0, 0, 0);
boost::bind(f7, 0, 0, 0, 0, 0, 0, 0);
boost::bind(f8, 0, 0, 0, 0, 0, 0, 0, 0);
boost::bind(f9, 0, 0, 0, 0, 0, 0, 0, 0, 0);
return 0;
}

View File

@@ -0,0 +1,153 @@
#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/bind.hpp>
#include <boost/core/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();
}

View File

@@ -0,0 +1,179 @@
#include <boost/config.hpp>
//
// bind_nested_rv_test.cpp
//
// Copyright (c) 2016 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/bind.hpp>
#include <boost/make_shared.hpp>
#include <boost/function.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
bool f1( boost::shared_ptr<int> p1 )
{
BOOST_TEST( p1 != 0 && *p1 == 1 );
return true;
}
bool f2( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2 )
{
BOOST_TEST( p1 != 0 && *p1 == 1 );
BOOST_TEST( p2 != 0 && *p2 == 2 );
return true;
}
bool f3( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3 )
{
BOOST_TEST( p1 != 0 && *p1 == 1 );
BOOST_TEST( p2 != 0 && *p2 == 2 );
BOOST_TEST( p3 != 0 && *p3 == 3 );
return true;
}
bool f4( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4 )
{
BOOST_TEST( p1 != 0 && *p1 == 1 );
BOOST_TEST( p2 != 0 && *p2 == 2 );
BOOST_TEST( p3 != 0 && *p3 == 3 );
BOOST_TEST( p4 != 0 && *p4 == 4 );
return true;
}
bool f5( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5 )
{
BOOST_TEST( p1 != 0 && *p1 == 1 );
BOOST_TEST( p2 != 0 && *p2 == 2 );
BOOST_TEST( p3 != 0 && *p3 == 3 );
BOOST_TEST( p4 != 0 && *p4 == 4 );
BOOST_TEST( p5 != 0 && *p5 == 5 );
return true;
}
bool f6( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6 )
{
BOOST_TEST( p1 != 0 && *p1 == 1 );
BOOST_TEST( p2 != 0 && *p2 == 2 );
BOOST_TEST( p3 != 0 && *p3 == 3 );
BOOST_TEST( p4 != 0 && *p4 == 4 );
BOOST_TEST( p5 != 0 && *p5 == 5 );
BOOST_TEST( p6 != 0 && *p6 == 6 );
return true;
}
bool f7( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6, boost::shared_ptr<int> p7 )
{
BOOST_TEST( p1 != 0 && *p1 == 1 );
BOOST_TEST( p2 != 0 && *p2 == 2 );
BOOST_TEST( p3 != 0 && *p3 == 3 );
BOOST_TEST( p4 != 0 && *p4 == 4 );
BOOST_TEST( p5 != 0 && *p5 == 5 );
BOOST_TEST( p6 != 0 && *p6 == 6 );
BOOST_TEST( p7 != 0 && *p7 == 7 );
return true;
}
bool f8( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6, boost::shared_ptr<int> p7, boost::shared_ptr<int> p8 )
{
BOOST_TEST( p1 != 0 && *p1 == 1 );
BOOST_TEST( p2 != 0 && *p2 == 2 );
BOOST_TEST( p3 != 0 && *p3 == 3 );
BOOST_TEST( p4 != 0 && *p4 == 4 );
BOOST_TEST( p5 != 0 && *p5 == 5 );
BOOST_TEST( p6 != 0 && *p6 == 6 );
BOOST_TEST( p7 != 0 && *p7 == 7 );
BOOST_TEST( p8 != 0 && *p8 == 8 );
return true;
}
bool f9( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6, boost::shared_ptr<int> p7, boost::shared_ptr<int> p8, boost::shared_ptr<int> p9 )
{
BOOST_TEST( p1 != 0 && *p1 == 1 );
BOOST_TEST( p2 != 0 && *p2 == 2 );
BOOST_TEST( p3 != 0 && *p3 == 3 );
BOOST_TEST( p4 != 0 && *p4 == 4 );
BOOST_TEST( p5 != 0 && *p5 == 5 );
BOOST_TEST( p6 != 0 && *p6 == 6 );
BOOST_TEST( p7 != 0 && *p7 == 7 );
BOOST_TEST( p8 != 0 && *p8 == 8 );
BOOST_TEST( p9 != 0 && *p9 == 9 );
return true;
}
void test()
{
{
boost::function<bool(boost::shared_ptr<int>)> f( f1 );
( boost::bind( f, _1 ) && boost::bind( f1, _1 ) )( boost::make_shared<int>( 1 ) );
}
{
boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f2 );
( boost::bind( f, _1, _2 ) && boost::bind( f2, _1, _2 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ) );
}
{
boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f3 );
( boost::bind( f, _1, _2, _3 ) && boost::bind( f3, _1, _2, _3 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ) );
}
{
boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f3 );
( boost::bind( f, _1, _2, _3 ) && boost::bind( f3, _1, _2, _3 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ) );
}
{
boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f4 );
( boost::bind( f, _1, _2, _3, _4 ) && boost::bind( f4, _1, _2, _3, _4 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ) );
}
{
boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f5 );
( boost::bind( f, _1, _2, _3, _4, _5 ) && boost::bind( f5, _1, _2, _3, _4, _5 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ), boost::make_shared<int>( 5 ) );
}
{
boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f6 );
( boost::bind( f, _1, _2, _3, _4, _5, _6 ) && boost::bind( f6, _1, _2, _3, _4, _5, _6 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ), boost::make_shared<int>( 5 ), boost::make_shared<int>( 6 ) );
}
{
boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f7 );
( boost::bind( f, _1, _2, _3, _4, _5, _6, _7 ) && boost::bind( f7, _1, _2, _3, _4, _5, _6, _7 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ), boost::make_shared<int>( 5 ), boost::make_shared<int>( 6 ), boost::make_shared<int>( 7 ) );
}
{
boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f8 );
( boost::bind( f, _1, _2, _3, _4, _5, _6, _7, _8 ) && boost::bind( f8, _1, _2, _3, _4, _5, _6, _7, _8 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ), boost::make_shared<int>( 5 ), boost::make_shared<int>( 6 ), boost::make_shared<int>( 7 ), boost::make_shared<int>( 8 ) );
}
{
boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f9 );
( boost::bind( f, _1, _2, _3, _4, _5, _6, _7, _8, _9 ) && boost::bind( f9, _1, _2, _3, _4, _5, _6, _7, _8, _9 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ), boost::make_shared<int>( 5 ), boost::make_shared<int>( 6 ), boost::make_shared<int>( 7 ), boost::make_shared<int>( 8 ), boost::make_shared<int>( 9 ) );
}
}
int main()
{
test();
return boost::report_errors();
}

View File

@@ -0,0 +1,99 @@
//
// bind_no_placeholders_test.cpp - test for BOOST_BIND_NO_PLACEHOLDERS
//
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001 David Abrahams
// Copyright (c) 2015 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
//
#define BOOST_BIND_NO_PLACEHOLDERS
#include <boost/bind.hpp>
#include <boost/core/lightweight_test.hpp>
//
long f_0()
{
return 17041L;
}
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;
}
void function_test()
{
using namespace boost;
arg<1> _1;
arg<2> _2;
arg<3> _3;
arg<4> _4;
arg<5> _5;
arg<6> _6;
arg<7> _7;
arg<8> _8;
arg<9> _9;
BOOST_TEST( bind(f_0)() == 17041L );
BOOST_TEST( bind(f_1, _1)(1) == 1L );
BOOST_TEST( bind(f_2, _1, _2)(1, 2) == 21L );
BOOST_TEST( bind(f_3, _1, _2, _3)(1, 2, 3) == 321L );
BOOST_TEST( bind(f_4, _1, _2, _3, _4)(1, 2, 3, 4) == 4321L );
BOOST_TEST( bind(f_5, _1, _2, _3, _4, _5)(1, 2, 3, 4, 5) == 54321L );
BOOST_TEST( bind(f_6, _1, _2, _3, _4, _5, _6)(1, 2, 3, 4, 5, 6) == 654321L );
BOOST_TEST( bind(f_7, _1, _2, _3, _4, _5, _6, _7)(1, 2, 3, 4, 5, 6, 7) == 7654321L );
BOOST_TEST( bind(f_8, _1, _2, _3, _4, _5, _6, _7, _8)(1, 2, 3, 4, 5, 6, 7, 8) == 87654321L );
BOOST_TEST( bind(f_9, _1, _2, _3, _4, _5, _6, _7, _8, _9)(1, 2, 3, 4, 5, 6, 7, 8, 9) == 987654321L );
}
int main()
{
function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,154 @@
//
// bind_noexcept_mf2_test.cpp - noexcept member functions w/ the type<> syntax
//
// Copyright 2017 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/bind.hpp>
#include <boost/ref.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#if defined(BOOST_NO_CXX11_NOEXCEPT)
int main()
{
}
#else
//
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int f0() noexcept { f1(17); return 0; }
int g0() const noexcept { g1(17); return 0; }
int f1(int a1) noexcept { hash = (hash * 17041 + a1) % 32768; return 0; }
int g1(int a1) const noexcept { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int f2(int a1, int a2) noexcept { f1(a1); f1(a2); return 0; }
int g2(int a1, int a2) const noexcept { g1(a1); g1(a2); return 0; }
int f3(int a1, int a2, int a3) noexcept { f2(a1, a2); f1(a3); return 0; }
int g3(int a1, int a2, int a3) const noexcept { g2(a1, a2); g1(a3); return 0; }
int f4(int a1, int a2, int a3, int a4) noexcept { f3(a1, a2, a3); f1(a4); return 0; }
int g4(int a1, int a2, int a3, int a4) const noexcept { g3(a1, a2, a3); g1(a4); return 0; }
int f5(int a1, int a2, int a3, int a4, int a5) noexcept { f4(a1, a2, a3, a4); f1(a5); return 0; }
int g5(int a1, int a2, int a3, int a4, int a5) const noexcept { g4(a1, a2, a3, a4); g1(a5); return 0; }
int f6(int a1, int a2, int a3, int a4, int a5, int a6) noexcept { 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 noexcept { 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) noexcept { 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 noexcept { 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) noexcept { 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 noexcept { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
};
void member_function_test()
{
X x;
// 0
boost::bind(boost::type<void>(), &X::f0, &x)();
boost::bind(boost::type<void>(), &X::f0, boost::ref(x))();
boost::bind(boost::type<void>(), &X::g0, &x)();
boost::bind(boost::type<void>(), &X::g0, x)();
boost::bind(boost::type<void>(), &X::g0, boost::ref(x))();
// 1
boost::bind(boost::type<void>(), &X::f1, &x, 1)();
boost::bind(boost::type<void>(), &X::f1, boost::ref(x), 1)();
boost::bind(boost::type<void>(), &X::g1, &x, 1)();
boost::bind(boost::type<void>(), &X::g1, x, 1)();
boost::bind(boost::type<void>(), &X::g1, boost::ref(x), 1)();
// 2
boost::bind(boost::type<void>(), &X::f2, &x, 1, 2)();
boost::bind(boost::type<void>(), &X::f2, boost::ref(x), 1, 2)();
boost::bind(boost::type<void>(), &X::g2, &x, 1, 2)();
boost::bind(boost::type<void>(), &X::g2, x, 1, 2)();
boost::bind(boost::type<void>(), &X::g2, boost::ref(x), 1, 2)();
// 3
boost::bind(boost::type<void>(), &X::f3, &x, 1, 2, 3)();
boost::bind(boost::type<void>(), &X::f3, boost::ref(x), 1, 2, 3)();
boost::bind(boost::type<void>(), &X::g3, &x, 1, 2, 3)();
boost::bind(boost::type<void>(), &X::g3, x, 1, 2, 3)();
boost::bind(boost::type<void>(), &X::g3, boost::ref(x), 1, 2, 3)();
// 4
boost::bind(boost::type<void>(), &X::f4, &x, 1, 2, 3, 4)();
boost::bind(boost::type<void>(), &X::f4, boost::ref(x), 1, 2, 3, 4)();
boost::bind(boost::type<void>(), &X::g4, &x, 1, 2, 3, 4)();
boost::bind(boost::type<void>(), &X::g4, x, 1, 2, 3, 4)();
boost::bind(boost::type<void>(), &X::g4, boost::ref(x), 1, 2, 3, 4)();
// 5
boost::bind(boost::type<void>(), &X::f5, &x, 1, 2, 3, 4, 5)();
boost::bind(boost::type<void>(), &X::f5, boost::ref(x), 1, 2, 3, 4, 5)();
boost::bind(boost::type<void>(), &X::g5, &x, 1, 2, 3, 4, 5)();
boost::bind(boost::type<void>(), &X::g5, x, 1, 2, 3, 4, 5)();
boost::bind(boost::type<void>(), &X::g5, boost::ref(x), 1, 2, 3, 4, 5)();
// 6
boost::bind(boost::type<void>(), &X::f6, &x, 1, 2, 3, 4, 5, 6)();
boost::bind(boost::type<void>(), &X::f6, boost::ref(x), 1, 2, 3, 4, 5, 6)();
boost::bind(boost::type<void>(), &X::g6, &x, 1, 2, 3, 4, 5, 6)();
boost::bind(boost::type<void>(), &X::g6, x, 1, 2, 3, 4, 5, 6)();
boost::bind(boost::type<void>(), &X::g6, boost::ref(x), 1, 2, 3, 4, 5, 6)();
// 7
boost::bind(boost::type<void>(), &X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
boost::bind(boost::type<void>(), &X::f7, boost::ref(x), 1, 2, 3, 4, 5, 6, 7)();
boost::bind(boost::type<void>(), &X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
boost::bind(boost::type<void>(), &X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
boost::bind(boost::type<void>(), &X::g7, boost::ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
boost::bind(boost::type<void>(), &X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(boost::type<void>(), &X::f8, boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(boost::type<void>(), &X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(boost::type<void>(), &X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(boost::type<void>(), &X::g8, boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
}
int main()
{
member_function_test();
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,154 @@
//
// bind_noexcept_mf_test.cpp
//
// Copyright 2017 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/bind.hpp>
#include <boost/ref.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#if defined(BOOST_NO_CXX11_NOEXCEPT)
int main()
{
}
#else
//
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int f0() noexcept { f1(17); return 0; }
int g0() const noexcept { g1(17); return 0; }
int f1(int a1) noexcept { hash = (hash * 17041 + a1) % 32768; return 0; }
int g1(int a1) const noexcept { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int f2(int a1, int a2) noexcept { f1(a1); f1(a2); return 0; }
int g2(int a1, int a2) const noexcept { g1(a1); g1(a2); return 0; }
int f3(int a1, int a2, int a3) noexcept { f2(a1, a2); f1(a3); return 0; }
int g3(int a1, int a2, int a3) const noexcept { g2(a1, a2); g1(a3); return 0; }
int f4(int a1, int a2, int a3, int a4) noexcept { f3(a1, a2, a3); f1(a4); return 0; }
int g4(int a1, int a2, int a3, int a4) const noexcept { g3(a1, a2, a3); g1(a4); return 0; }
int f5(int a1, int a2, int a3, int a4, int a5) noexcept { f4(a1, a2, a3, a4); f1(a5); return 0; }
int g5(int a1, int a2, int a3, int a4, int a5) const noexcept { g4(a1, a2, a3, a4); g1(a5); return 0; }
int f6(int a1, int a2, int a3, int a4, int a5, int a6) noexcept { 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 noexcept { 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) noexcept { 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 noexcept { 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) noexcept { 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 noexcept { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
};
void member_function_test()
{
X x;
// 0
boost::bind(&X::f0, &x)();
boost::bind(&X::f0, boost::ref(x))();
boost::bind(&X::g0, &x)();
boost::bind(&X::g0, x)();
boost::bind(&X::g0, boost::ref(x))();
// 1
boost::bind(&X::f1, &x, 1)();
boost::bind(&X::f1, boost::ref(x), 1)();
boost::bind(&X::g1, &x, 1)();
boost::bind(&X::g1, x, 1)();
boost::bind(&X::g1, boost::ref(x), 1)();
// 2
boost::bind(&X::f2, &x, 1, 2)();
boost::bind(&X::f2, boost::ref(x), 1, 2)();
boost::bind(&X::g2, &x, 1, 2)();
boost::bind(&X::g2, x, 1, 2)();
boost::bind(&X::g2, boost::ref(x), 1, 2)();
// 3
boost::bind(&X::f3, &x, 1, 2, 3)();
boost::bind(&X::f3, boost::ref(x), 1, 2, 3)();
boost::bind(&X::g3, &x, 1, 2, 3)();
boost::bind(&X::g3, x, 1, 2, 3)();
boost::bind(&X::g3, boost::ref(x), 1, 2, 3)();
// 4
boost::bind(&X::f4, &x, 1, 2, 3, 4)();
boost::bind(&X::f4, boost::ref(x), 1, 2, 3, 4)();
boost::bind(&X::g4, &x, 1, 2, 3, 4)();
boost::bind(&X::g4, x, 1, 2, 3, 4)();
boost::bind(&X::g4, boost::ref(x), 1, 2, 3, 4)();
// 5
boost::bind(&X::f5, &x, 1, 2, 3, 4, 5)();
boost::bind(&X::f5, boost::ref(x), 1, 2, 3, 4, 5)();
boost::bind(&X::g5, &x, 1, 2, 3, 4, 5)();
boost::bind(&X::g5, x, 1, 2, 3, 4, 5)();
boost::bind(&X::g5, boost::ref(x), 1, 2, 3, 4, 5)();
// 6
boost::bind(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
boost::bind(&X::f6, boost::ref(x), 1, 2, 3, 4, 5, 6)();
boost::bind(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
boost::bind(&X::g6, x, 1, 2, 3, 4, 5, 6)();
boost::bind(&X::g6, boost::ref(x), 1, 2, 3, 4, 5, 6)();
// 7
boost::bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
boost::bind(&X::f7, boost::ref(x), 1, 2, 3, 4, 5, 6, 7)();
boost::bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
boost::bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
boost::bind(&X::g7, boost::ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
boost::bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(&X::f8, boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(&X::g8, boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
}
int main()
{
member_function_test();
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,99 @@
//
// bind_noexcept_test.cpp
//
// Copyright 2017 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
using namespace boost::placeholders;
#if defined(BOOST_NO_CXX11_NOEXCEPT)
int main()
{
}
#else
//
long f_0() noexcept
{
return 17041L;
}
long f_1(long a) noexcept
{
return a;
}
long f_2(long a, long b) noexcept
{
return a + 10 * b;
}
long f_3(long a, long b, long c) noexcept
{
return a + 10 * b + 100 * c;
}
long f_4(long a, long b, long c, long d) noexcept
{
return a + 10 * b + 100 * c + 1000 * d;
}
long f_5(long a, long b, long c, long d, long e) noexcept
{
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) noexcept
{
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) noexcept
{
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) noexcept
{
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) noexcept
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
void function_test()
{
int const i = 1;
BOOST_TEST( boost::bind(f_0)(i) == 17041L );
BOOST_TEST( boost::bind(f_1, _1)(i) == 1L );
BOOST_TEST( boost::bind(f_2, _1, 2)(i) == 21L );
BOOST_TEST( boost::bind(f_3, _1, 2, 3)(i) == 321L );
BOOST_TEST( boost::bind(f_4, _1, 2, 3, 4)(i) == 4321L );
BOOST_TEST( boost::bind(f_5, _1, 2, 3, 4, 5)(i) == 54321L );
BOOST_TEST( boost::bind(f_6, _1, 2, 3, 4, 5, 6)(i) == 654321L );
BOOST_TEST( boost::bind(f_7, _1, 2, 3, 4, 5, 6, 7)(i) == 7654321L );
BOOST_TEST( boost::bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i) == 87654321L );
BOOST_TEST( boost::bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i) == 987654321L );
}
int main()
{
function_test();
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,50 @@
#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_not_test.cpp - operator!
//
// Copyright (c) 2005 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
template<class F, class A1, class R> void test( F f, A1 a1, R r )
{
BOOST_TEST( f(a1) == r );
}
bool f( bool v )
{
return v;
}
int g( int v )
{
return v;
}
int main()
{
test( !boost::bind( f, true ), 0, !f( true ) );
test( !boost::bind( g, _1 ), 5, !g( 5 ) );
test( boost::bind( f, !boost::bind( f, true ) ), 0, f( !f( true ) ) );
test( boost::bind( f, !boost::bind( f, _1 ) ), true, f( !f( true ) ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,72 @@
#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_placeholder_test.cpp - test custom placeholders
//
// Copyright (c) 2006 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
//
long f( 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;
}
template< int I > struct custom_placeholder
{
};
namespace boost
{
template< int I > struct is_placeholder< custom_placeholder< I > >
{
enum { value = I };
};
} // namespace boost
int main()
{
int const x1 = 1;
int const x2 = 2;
int const x3 = 3;
int const x4 = 4;
int const x5 = 5;
int const x6 = 6;
int const x7 = 7;
int const x8 = 8;
int const x9 = 9;
custom_placeholder<1> p1;
custom_placeholder<2> p2;
custom_placeholder<3> p3;
custom_placeholder<4> p4;
custom_placeholder<5> p5;
custom_placeholder<6> p6;
custom_placeholder<7> p7;
custom_placeholder<8> p8;
custom_placeholder<9> p9;
BOOST_TEST(
boost::bind( f, p1, p2, p3, p4, p5, p6, p7, p8, p9 )
( x1, x2, x3, x4, x5, x6, x7, x8, x9 ) == 987654321L );
return boost::report_errors();
}

View File

@@ -0,0 +1,40 @@
//
// bind_ref_test.cpp - reference_wrapper
//
// Copyright (c) 2009 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/bind.hpp>
#include <boost/ref.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
struct X
{
int f( int x )
{
return x;
}
int g( int x ) const
{
return -x;
}
};
int main()
{
X x;
BOOST_TEST( boost::bind( &X::f, _1, 1 )( boost::ref( x ) ) == 1 );
BOOST_TEST( boost::bind( &X::g, _1, 2 )( boost::cref( x ) ) == -2 );
return boost::report_errors();
}

View File

@@ -0,0 +1,90 @@
#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_rel_test.cpp - ==, !=, <, <=, >, >= operators
//
// Copyright (c) 2005 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
int f( int x )
{
return x + x;
}
int g( int x )
{
return 2 * x;
}
int main()
{
int x = 4;
int y = x + x;
// bind op value
BOOST_TEST( ( boost::bind( f, _1 ) == y )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) != y )( x ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) < y )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) < y + 1 )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) > y )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) > y - 1 )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) <= y - 1 )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) <= y )( x ) );
BOOST_TEST( ( boost::bind( f, _1 ) <= y + 1 )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) >= y + 1 )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) >= y )( x ) );
BOOST_TEST( ( boost::bind( f, _1 ) >= y - 1 )( x ) );
// bind op ref
BOOST_TEST( ( boost::bind( f, _1 ) == boost::ref( y ) )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) != boost::ref( y ) )( x ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) < boost::ref( y ) )( x ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) > boost::ref( y ) )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) <= boost::ref( y ) )( x ) );
BOOST_TEST( ( boost::bind( f, _1 ) >= boost::ref( y ) )( x ) );
// bind op placeholder
BOOST_TEST( ( boost::bind( f, _1 ) == _2 )( x, y ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) != _2 )( x, y ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) < _2 )( x, y ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) > _2 )( x, y ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) <= _2 )( x, y ) );
BOOST_TEST( ( boost::bind( f, _1 ) >= _2 )( x, y ) );
// bind op bind
// important: bind( f, _1 ) and bind( g, _1 ) have the same type
BOOST_TEST( ( boost::bind( f, _1 ) == boost::bind( g, _1 ) )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) != boost::bind( g, _1 ) )( x ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) < boost::bind( g, _1 ) )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) <= boost::bind( g, _1 ) )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) > boost::bind( g, _1 ) )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) >= boost::bind( g, _1 ) )( x ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,55 @@
#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_rv_sp_test.cpp - smart pointer returned by value from an inner bind
//
// Copyright (c) 2005 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/shared_ptr.hpp>
//
struct X
{
int v_;
X( int v ): v_( v )
{
}
int f()
{
return v_;
}
};
struct Y
{
boost::shared_ptr<X> f()
{
return boost::shared_ptr<X>( new X( 42 ) );
}
};
int main()
{
Y y;
BOOST_TEST( boost::bind( &X::f, boost::bind( &Y::f, &y ) )() == 42 );
return boost::report_errors();
}

View File

@@ -0,0 +1,72 @@
#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_rvalue_test.cpp
//
// Copyright (c) 2006 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
int f( int x )
{
return x;
}
int main()
{
BOOST_TEST(
boost::bind( f, _1 )
( 1 ) == 1 );
BOOST_TEST(
boost::bind( f, _2 )
( 1, 2 ) == 2 );
BOOST_TEST(
boost::bind( f, _3 )
( 1, 2, 3 ) == 3 );
BOOST_TEST(
boost::bind( f, _4 )
( 1, 2, 3, 4 ) == 4 );
BOOST_TEST(
boost::bind( f, _5 )
( 1, 2, 3, 4, 5 ) == 5 );
BOOST_TEST(
boost::bind( f, _6 )
( 1, 2, 3, 4, 5, 6 ) == 6 );
BOOST_TEST(
boost::bind( f, _7 )
( 1, 2, 3, 4, 5, 6, 7 ) == 7 );
BOOST_TEST(
boost::bind( f, _8 )
( 1, 2, 3, 4, 5, 6, 7, 8 ) == 8 );
BOOST_TEST(
boost::bind( f, _9 )
( 1, 2, 3, 4, 5, 6, 7, 8, 9 ) == 9 );
return boost::report_errors();
}

View File

@@ -0,0 +1,218 @@
#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_stateful_test.cpp
//
// Copyright (c) 2004 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
//
class X
{
private:
int state_;
public:
X(): state_(0)
{
}
// SGI-related compilers have odd compiler-synthesized ctors and dtors
#ifdef __PATHSCALE__
~X() {}
#endif
int state() const
{
return state_;
}
int operator()()
{
return state_ += 17041;
}
int operator()(int x1)
{
return state_ += x1;
}
int operator()(int x1, int x2)
{
return state_ += x1+x2;
}
int operator()(int x1, int x2, int x3)
{
return state_ += x1+x2+x3;
}
int operator()(int x1, int x2, int x3, int x4)
{
return state_ += x1+x2+x3+x4;
}
int operator()(int x1, int x2, int x3, int x4, int x5)
{
return state_ += x1+x2+x3+x4+x5;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6)
{
return state_ += x1+x2+x3+x4+x5+x6;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7)
{
return state_ += x1+x2+x3+x4+x5+x6+x7;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
{
return state_ += x1+x2+x3+x4+x5+x6+x7+x8;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9)
{
return state_ += x1+x2+x3+x4+x5+x6+x7+x8+x9;
}
};
int f0(int & state_)
{
return state_ += 17041;
}
int f1(int & state_, int x1)
{
return state_ += x1;
}
int f2(int & state_, int x1, int x2)
{
return state_ += x1+x2;
}
int f3(int & state_, int x1, int x2, int x3)
{
return state_ += x1+x2+x3;
}
int f4(int & state_, int x1, int x2, int x3, int x4)
{
return state_ += x1+x2+x3+x4;
}
int f5(int & state_, int x1, int x2, int x3, int x4, int x5)
{
return state_ += x1+x2+x3+x4+x5;
}
int f6(int & state_, int x1, int x2, int x3, int x4, int x5, int x6)
{
return state_ += x1+x2+x3+x4+x5+x6;
}
int f7(int & state_, int x1, int x2, int x3, int x4, int x5, int x6, int x7)
{
return state_ += x1+x2+x3+x4+x5+x6+x7;
}
int f8(int & state_, int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
{
return state_ += x1+x2+x3+x4+x5+x6+x7+x8;
}
template<class F> void test(F f, int a, int b)
{
BOOST_TEST( f() == a + b );
BOOST_TEST( f() == a + 2*b );
BOOST_TEST( f() == a + 3*b );
}
void stateful_function_object_test()
{
test( boost::bind<int>( X() ), 0, 17041 );
test( boost::bind<int>( X(), 1 ), 0, 1 );
test( boost::bind<int>( X(), 1, 2 ), 0, 1+2 );
test( boost::bind<int>( X(), 1, 2, 3 ), 0, 1+2+3 );
test( boost::bind<int>( X(), 1, 2, 3, 4 ), 0, 1+2+3+4 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 0, 1+2+3+4+5+6+7+8+9 );
X x;
int n = x.state();
test( boost::bind<int>( boost::ref(x) ), n, 17041 );
n += 3*17041;
test( boost::bind<int>( boost::ref(x), 1 ), n, 1 );
n += 3*1;
test( boost::bind<int>( boost::ref(x), 1, 2 ), n, 1+2 );
n += 3*(1+2);
test( boost::bind<int>( boost::ref(x), 1, 2, 3 ), n, 1+2+3 );
n += 3*(1+2+3);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4 ), n, 1+2+3+4 );
n += 3*(1+2+3+4);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4, 5 ), n, 1+2+3+4+5 );
n += 3*(1+2+3+4+5);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4, 5, 6 ), n, 1+2+3+4+5+6 );
n += 3*(1+2+3+4+5+6);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4, 5, 6, 7 ), n, 1+2+3+4+5+6+7 );
n += 3*(1+2+3+4+5+6+7);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8 ), n, 1+2+3+4+5+6+7+8 );
n += 3*(1+2+3+4+5+6+7+8);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), n, 1+2+3+4+5+6+7+8+9 );
n += 3*(1+2+3+4+5+6+7+8+9);
BOOST_TEST( x.state() == n );
}
void stateful_function_test()
{
test( boost::bind( f0, 0 ), 0, 17041 );
test( boost::bind( f1, 0, 1 ), 0, 1 );
test( boost::bind( f2, 0, 1, 2 ), 0, 1+2 );
test( boost::bind( f3, 0, 1, 2, 3 ), 0, 1+2+3 );
test( boost::bind( f4, 0, 1, 2, 3, 4 ), 0, 1+2+3+4 );
test( boost::bind( f5, 0, 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 );
test( boost::bind( f6, 0, 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 );
test( boost::bind( f7, 0, 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 );
test( boost::bind( f8, 0, 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 );
}
int main()
{
stateful_function_object_test();
stateful_function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,165 @@
#include <boost/config.hpp>
#ifndef BOOST_MSVC
int main()
{
}
#else
#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_stdcall_mf_test.cpp - test for bind.hpp + __stdcall (member functions)
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// 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)
//
#define BOOST_MEM_FN_ENABLE_STDCALL
#include <boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
//
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int __stdcall f0() { f1(17); return 0; }
int __stdcall g0() const { g1(17); return 0; }
int __stdcall f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int __stdcall g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int __stdcall f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
int __stdcall g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
int __stdcall f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
int __stdcall g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
int __stdcall f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
int __stdcall g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
int __stdcall f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
int __stdcall g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
int __stdcall f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int __stdcall 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 __stdcall 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 __stdcall 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 __stdcall 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 __stdcall 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(&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();
}
#endif

View File

@@ -0,0 +1,113 @@
#include <boost/config.hpp>
#ifndef BOOST_MSVC
int main()
{
}
#else
#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_stdcall_test.cpp - test for bind.hpp + __stdcall (free functions)
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// 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)
//
#define BOOST_BIND_ENABLE_STDCALL
#include <boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
long __stdcall f_0()
{
return 17041L;
}
long __stdcall f_1(long a)
{
return a;
}
long __stdcall f_2(long a, long b)
{
return a + 10 * b;
}
long __stdcall f_3(long a, long b, long c)
{
return a + 10 * b + 100 * c;
}
long __stdcall f_4(long a, long b, long c, long d)
{
return a + 10 * b + 100 * c + 1000 * d;
}
long __stdcall f_5(long a, long b, long c, long d, long e)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
long __stdcall 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 __stdcall 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 __stdcall 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 __stdcall 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();
}
#endif

View File

@@ -0,0 +1,512 @@
#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_test.cpp - monolithic test for bind.hpp
//
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001 David Abrahams
//
// 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/bind.hpp>
#include <boost/ref.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
long f_0()
{
return 17041L;
}
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;
}
long global_result;
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;
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 );
BOOST_TEST( (bind(fv_0)(i), (global_result == 17041L)) );
BOOST_TEST( (bind(fv_1, _1)(i), (global_result == 1L)) );
BOOST_TEST( (bind(fv_2, _1, 2)(i), (global_result == 21L)) );
BOOST_TEST( (bind(fv_3, _1, 2, 3)(i), (global_result == 321L)) );
BOOST_TEST( (bind(fv_4, _1, 2, 3, 4)(i), (global_result == 4321L)) );
BOOST_TEST( (bind(fv_5, _1, 2, 3, 4, 5)(i), (global_result == 54321L)) );
BOOST_TEST( (bind(fv_6, _1, 2, 3, 4, 5, 6)(i), (global_result == 654321L)) );
BOOST_TEST( (bind(fv_7, _1, 2, 3, 4, 5, 6, 7)(i), (global_result == 7654321L)) );
BOOST_TEST( (bind(fv_8, _1, 2, 3, 4, 5, 6, 7, 8)(i), (global_result == 87654321L)) );
BOOST_TEST( (bind(fv_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i), (global_result == 987654321L)) );
}
//
struct Y
{
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; }
void operator() (long a, long b, long c, long d) const { global_result = a + 10 * b + 100 * c + 1000 * d; }
};
void function_object_test()
{
using namespace boost;
short i(6);
int const k = 3;
BOOST_TEST( bind<short>(Y(), ref(i))() == 7 );
BOOST_TEST( bind<short>(Y(), ref(i))() == 8 );
BOOST_TEST( bind<int>(Y(), i, _1)(k) == 38 );
BOOST_TEST( bind<long>(Y(), i, _1, 9)(k) == 938 );
#if !defined(__MWERKS__) || (__MWERKS__ > 0x2407) // 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)
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;
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; }
};
struct V
{
mutable unsigned int hash;
V(): hash(0) {}
void f0() { f1(17); }
void g0() const { g1(17); }
void f1(int a1) { hash = (hash * 17041 + a1) % 32768; }
void g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; }
void f2(int a1, int a2) { f1(a1); f1(a2); }
void g2(int a1, int a2) const { g1(a1); g1(a2); }
void f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); }
void g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); }
void f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); }
void g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); }
void f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); }
void g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); }
void f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); }
void g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); }
void 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 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 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 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 );
}
void member_function_void_test()
{
using namespace boost;
V v;
// 0
bind(&V::f0, &v)();
bind(&V::f0, ref(v))();
bind(&V::g0, &v)();
bind(&V::g0, v)();
bind(&V::g0, ref(v))();
// 1
bind(&V::f1, &v, 1)();
bind(&V::f1, ref(v), 1)();
bind(&V::g1, &v, 1)();
bind(&V::g1, v, 1)();
bind(&V::g1, ref(v), 1)();
// 2
bind(&V::f2, &v, 1, 2)();
bind(&V::f2, ref(v), 1, 2)();
bind(&V::g2, &v, 1, 2)();
bind(&V::g2, v, 1, 2)();
bind(&V::g2, ref(v), 1, 2)();
// 3
bind(&V::f3, &v, 1, 2, 3)();
bind(&V::f3, ref(v), 1, 2, 3)();
bind(&V::g3, &v, 1, 2, 3)();
bind(&V::g3, v, 1, 2, 3)();
bind(&V::g3, ref(v), 1, 2, 3)();
// 4
bind(&V::f4, &v, 1, 2, 3, 4)();
bind(&V::f4, ref(v), 1, 2, 3, 4)();
bind(&V::g4, &v, 1, 2, 3, 4)();
bind(&V::g4, v, 1, 2, 3, 4)();
bind(&V::g4, ref(v), 1, 2, 3, 4)();
// 5
bind(&V::f5, &v, 1, 2, 3, 4, 5)();
bind(&V::f5, ref(v), 1, 2, 3, 4, 5)();
bind(&V::g5, &v, 1, 2, 3, 4, 5)();
bind(&V::g5, v, 1, 2, 3, 4, 5)();
bind(&V::g5, ref(v), 1, 2, 3, 4, 5)();
// 6
bind(&V::f6, &v, 1, 2, 3, 4, 5, 6)();
bind(&V::f6, ref(v), 1, 2, 3, 4, 5, 6)();
bind(&V::g6, &v, 1, 2, 3, 4, 5, 6)();
bind(&V::g6, v, 1, 2, 3, 4, 5, 6)();
bind(&V::g6, ref(v), 1, 2, 3, 4, 5, 6)();
// 7
bind(&V::f7, &v, 1, 2, 3, 4, 5, 6, 7)();
bind(&V::f7, ref(v), 1, 2, 3, 4, 5, 6, 7)();
bind(&V::g7, &v, 1, 2, 3, 4, 5, 6, 7)();
bind(&V::g7, v, 1, 2, 3, 4, 5, 6, 7)();
bind(&V::g7, ref(v), 1, 2, 3, 4, 5, 6, 7)();
// 8
bind(&V::f8, &v, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&V::f8, ref(v), 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&V::g8, &v, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&V::g8, v, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&V::g8, ref(v), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( v.hash == 23558 );
}
void nested_bind_test()
{
using namespace boost;
int const x = 1;
int const y = 2;
BOOST_TEST( bind(f_1, bind(f_1, _1))(x) == 1L );
BOOST_TEST( bind(f_1, bind(f_2, _1, _2))(x, y) == 21L );
BOOST_TEST( bind(f_2, bind(f_1, _1), bind(f_1, _1))(x) == 11L );
BOOST_TEST( bind(f_2, bind(f_1, _1), bind(f_1, _2))(x, y) == 21L );
BOOST_TEST( bind(f_1, bind(f_0))() == 17041L );
BOOST_TEST( (bind(fv_1, bind(f_1, _1))(x), (global_result == 1L)) );
BOOST_TEST( (bind(fv_1, bind(f_2, _1, _2))(x, y), (global_result == 21L)) );
BOOST_TEST( (bind(fv_2, bind(f_1, _1), bind(f_1, _1))(x), (global_result == 11L)) );
BOOST_TEST( (bind(fv_2, bind(f_1, _1), bind(f_1, _2))(x, y), (global_result == 21L)) );
BOOST_TEST( (bind(fv_1, bind(f_0))(), (global_result == 17041L)) );
}
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();
#endif
member_function_test();
member_function_void_test();
nested_bind_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,77 @@
#include <boost/config.hpp>
//
// bind_type_test.cpp
//
// Copyright (c) 2015 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
template<int I> struct X
{
};
void fv1( X<1> )
{
}
void fv2( X<1>, X<2> )
{
}
void fv3( X<1>, X<2>, X<3> )
{
}
void fv4( X<1>, X<2>, X<3>, X<4> )
{
}
void fv5( X<1>, X<2>, X<3>, X<4>, X<5> )
{
}
void fv6( X<1>, X<2>, X<3>, X<4>, X<5>, X<6> )
{
}
void fv7( X<1>, X<2>, X<3>, X<4>, X<5>, X<6>, X<7> )
{
}
void fv8( X<1>, X<2>, X<3>, X<4>, X<5>, X<6>, X<7>, X<8> )
{
}
void fv9( X<1>, X<2>, X<3>, X<4>, X<5>, X<6>, X<7>, X<8>, X<9> )
{
}
void test()
{
boost::bind( fv1, _1 )( X<1>() );
boost::bind( fv2, _1, _2 )( X<1>(), X<2>() );
boost::bind( fv3, _1, _2, _3 )( X<1>(), X<2>(), X<3>() );
boost::bind( fv4, _1, _2, _3, _4 )( X<1>(), X<2>(), X<3>(), X<4>() );
boost::bind( fv5, _1, _2, _3, _4, _5 )( X<1>(), X<2>(), X<3>(), X<4>(), X<5>() );
boost::bind( fv6, _1, _2, _3, _4, _5, _6 )( X<1>(), X<2>(), X<3>(), X<4>(), X<5>(), X<6>() );
boost::bind( fv7, _1, _2, _3, _4, _5, _6, _7 )( X<1>(), X<2>(), X<3>(), X<4>(), X<5>(), X<6>(), X<7>() );
boost::bind( fv8, _1, _2, _3, _4, _5, _6, _7, _8 )( X<1>(), X<2>(), X<3>(), X<4>(), X<5>(), X<6>(), X<7>(), X<8>() );
boost::bind( fv9, _1, _2, _3, _4, _5, _6, _7, _8, _9 )( X<1>(), X<2>(), X<3>(), X<4>(), X<5>(), X<6>(), X<7>(), X<8>(), X<9>() );
}
int main()
{
test();
return boost::report_errors();
}

View File

@@ -0,0 +1,139 @@
#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_unary_addr.cpp
//
// Copyright (c) 2005 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/bind.hpp>
//
class X
{
private:
void operator& ();
void operator& () const;
public:
void operator()()
{
}
void operator()() const
{
}
void operator()(int)
{
}
void operator()(int) const
{
}
void operator()(int, int)
{
}
void operator()(int, int) const
{
}
void operator()(int, int, int)
{
}
void operator()(int, int, int) const
{
}
void operator()(int, int, int, int)
{
}
void operator()(int, int, int, int) const
{
}
void operator()(int, int, int, int, int)
{
}
void operator()(int, int, int, int, int) const
{
}
void operator()(int, int, int, int, int, int)
{
}
void operator()(int, int, int, int, int, int) const
{
}
void operator()(int, int, int, int, int, int, int)
{
}
void operator()(int, int, int, int, int, int, int) const
{
}
void operator()(int, int, int, int, int, int, int, int)
{
}
void operator()(int, int, int, int, int, int, int, int) const
{
}
void operator()(int, int, int, int, int, int, int, int, int)
{
}
void operator()(int, int, int, int, int, int, int, int, int) const
{
}
};
template<class F> void test_const( F const & f )
{
f();
}
template<class F> void test( F f )
{
f();
test_const( f );
}
int main()
{
test( boost::bind<void>( X() ) );
test( boost::bind<void>( X(), 1 ) );
test( boost::bind<void>( X(), 1, 2 ) );
test( boost::bind<void>( X(), 1, 2, 3 ) );
test( boost::bind<void>( X(), 1, 2, 3, 4 ) );
test( boost::bind<void>( X(), 1, 2, 3, 4, 5 ) );
test( boost::bind<void>( X(), 1, 2, 3, 4, 5, 6 ) );
test( boost::bind<void>( X(), 1, 2, 3, 4, 5, 6, 7 ) );
test( boost::bind<void>( X(), 1, 2, 3, 4, 5, 6, 7, 8 ) );
test( boost::bind<void>( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ) );
return 0;
}

View File

@@ -0,0 +1,219 @@
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_CXX11_RVALUE_REFERENCES is defined" )
int main() {}
#elif defined(BOOST_NO_CXX11_SMART_PTR)
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_CXX11_SMART_PTR is defined" )
int main() {}
#elif defined(BOOST_GCC) && BOOST_GCC < 40600
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_GCC is less than 40600" )
int main() {}
#else
//
// bind_unique_ptr_test.cpp
//
// Copyright (c) 2015 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
#include <memory>
using namespace boost::placeholders;
//
void fv1( std::unique_ptr<int> p1 )
{
BOOST_TEST( *p1 == 1 );
}
void fv2( std::unique_ptr<int> p1, std::unique_ptr<int> p2 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
}
void fv3( std::unique_ptr<int> p1, std::unique_ptr<int> p2, std::unique_ptr<int> p3 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
}
void fv4( std::unique_ptr<int> p1, std::unique_ptr<int> p2, std::unique_ptr<int> p3, std::unique_ptr<int> p4 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
}
void fv5( std::unique_ptr<int> p1, std::unique_ptr<int> p2, std::unique_ptr<int> p3, std::unique_ptr<int> p4, std::unique_ptr<int> p5 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
BOOST_TEST( *p5 == 5 );
}
void fv6( std::unique_ptr<int> p1, std::unique_ptr<int> p2, std::unique_ptr<int> p3, std::unique_ptr<int> p4, std::unique_ptr<int> p5, std::unique_ptr<int> p6 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
BOOST_TEST( *p5 == 5 );
BOOST_TEST( *p6 == 6 );
}
void fv7( std::unique_ptr<int> p1, std::unique_ptr<int> p2, std::unique_ptr<int> p3, std::unique_ptr<int> p4, std::unique_ptr<int> p5, std::unique_ptr<int> p6, std::unique_ptr<int> p7 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
BOOST_TEST( *p5 == 5 );
BOOST_TEST( *p6 == 6 );
BOOST_TEST( *p7 == 7 );
}
void fv8( std::unique_ptr<int> p1, std::unique_ptr<int> p2, std::unique_ptr<int> p3, std::unique_ptr<int> p4, std::unique_ptr<int> p5, std::unique_ptr<int> p6, std::unique_ptr<int> p7, std::unique_ptr<int> p8 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
BOOST_TEST( *p5 == 5 );
BOOST_TEST( *p6 == 6 );
BOOST_TEST( *p7 == 7 );
BOOST_TEST( *p8 == 8 );
}
void fv9( std::unique_ptr<int> p1, std::unique_ptr<int> p2, std::unique_ptr<int> p3, std::unique_ptr<int> p4, std::unique_ptr<int> p5, std::unique_ptr<int> p6, std::unique_ptr<int> p7, std::unique_ptr<int> p8, std::unique_ptr<int> p9 )
{
BOOST_TEST( *p1 == 1 );
BOOST_TEST( *p2 == 2 );
BOOST_TEST( *p3 == 3 );
BOOST_TEST( *p4 == 4 );
BOOST_TEST( *p5 == 5 );
BOOST_TEST( *p6 == 6 );
BOOST_TEST( *p7 == 7 );
BOOST_TEST( *p8 == 8 );
BOOST_TEST( *p9 == 9 );
}
void test()
{
{
std::unique_ptr<int> p1( new int(1) );
boost::bind( fv1, _1 )( std::move( p1 ) );
}
{
std::unique_ptr<int> p1( new int(1) );
std::unique_ptr<int> p2( new int(2) );
boost::bind( fv2, _1, _2 )( std::move( p1 ), std::move( p2 ) );
}
{
std::unique_ptr<int> p1( new int(1) );
std::unique_ptr<int> p2( new int(2) );
std::unique_ptr<int> p3( new int(3) );
boost::bind( fv3, _1, _2, _3 )( std::move( p1 ), std::move( p2 ), std::move( p3 ) );
}
{
std::unique_ptr<int> p1( new int(1) );
std::unique_ptr<int> p2( new int(2) );
std::unique_ptr<int> p3( new int(3) );
std::unique_ptr<int> p4( new int(4) );
boost::bind( fv4, _1, _2, _3, _4 )( std::move( p1 ), std::move( p2 ), std::move( p3 ), std::move( p4 ) );
}
{
std::unique_ptr<int> p1( new int(1) );
std::unique_ptr<int> p2( new int(2) );
std::unique_ptr<int> p3( new int(3) );
std::unique_ptr<int> p4( new int(4) );
std::unique_ptr<int> p5( new int(5) );
boost::bind( fv5, _1, _2, _3, _4, _5 )( std::move( p1 ), std::move( p2 ), std::move( p3 ), std::move( p4 ), std::move( p5 ) );
}
{
std::unique_ptr<int> p1( new int(1) );
std::unique_ptr<int> p2( new int(2) );
std::unique_ptr<int> p3( new int(3) );
std::unique_ptr<int> p4( new int(4) );
std::unique_ptr<int> p5( new int(5) );
std::unique_ptr<int> p6( new int(6) );
boost::bind( fv6, _1, _2, _3, _4, _5, _6 )( std::move( p1 ), std::move( p2 ), std::move( p3 ), std::move( p4 ), std::move( p5 ), std::move( p6 ) );
}
{
std::unique_ptr<int> p1( new int(1) );
std::unique_ptr<int> p2( new int(2) );
std::unique_ptr<int> p3( new int(3) );
std::unique_ptr<int> p4( new int(4) );
std::unique_ptr<int> p5( new int(5) );
std::unique_ptr<int> p6( new int(6) );
std::unique_ptr<int> p7( new int(7) );
boost::bind( fv7, _1, _2, _3, _4, _5, _6, _7 )( std::move( p1 ), std::move( p2 ), std::move( p3 ), std::move( p4 ), std::move( p5 ), std::move( p6 ), std::move( p7 ) );
}
{
std::unique_ptr<int> p1( new int(1) );
std::unique_ptr<int> p2( new int(2) );
std::unique_ptr<int> p3( new int(3) );
std::unique_ptr<int> p4( new int(4) );
std::unique_ptr<int> p5( new int(5) );
std::unique_ptr<int> p6( new int(6) );
std::unique_ptr<int> p7( new int(7) );
std::unique_ptr<int> p8( new int(8) );
boost::bind( fv8, _1, _2, _3, _4, _5, _6, _7, _8 )( std::move( p1 ), std::move( p2 ), std::move( p3 ), std::move( p4 ), std::move( p5 ), std::move( p6 ), std::move( p7 ), std::move( p8 ) );
}
{
std::unique_ptr<int> p1( new int(1) );
std::unique_ptr<int> p2( new int(2) );
std::unique_ptr<int> p3( new int(3) );
std::unique_ptr<int> p4( new int(4) );
std::unique_ptr<int> p5( new int(5) );
std::unique_ptr<int> p6( new int(6) );
std::unique_ptr<int> p7( new int(7) );
std::unique_ptr<int> p8( new int(8) );
std::unique_ptr<int> p9( new int(9) );
boost::bind( fv9, _1, _2, _3, _4, _5, _6, _7, _8, _9 )( std::move( p1 ), std::move( p2 ), std::move( p3 ), std::move( p4 ), std::move( p5 ), std::move( p6 ), std::move( p7 ), std::move( p8 ), std::move( p9 ) );
}
}
int main()
{
test();
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,61 @@
#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
# pragma warning(disable: 4100) // unreferenced formal parameter (it is referenced!)
#endif
// Copyright (c) 2006 Douglas Gregor <doug.gregor@gmail.com>
// Copyright (c) 2006 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/bind.hpp>
#include <boost/visit_each.hpp>
#include <boost/core/lightweight_test.hpp>
#include <typeinfo>
using namespace boost::placeholders;
//
struct visitor
{
int hash;
visitor(): hash( 0 )
{
}
template<typename T> void operator()( T const & t )
{
std::cout << "visitor::operator()( T ): " << typeid( t ).name() << std::endl;
}
void operator()( int const & t )
{
std::cout << "visitor::operator()( int ): " << t << std::endl;
hash = hash * 10 + t;
}
};
int f( int x, int y, int z )
{
return x + y + z;
}
int main()
{
visitor vis;
boost::visit_each( vis, boost::bind( f, 3, _1, 4 ) );
BOOST_TEST( vis.hash == 34 );
return boost::report_errors();
}

View File

@@ -0,0 +1,63 @@
#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_void_mf_test.cpp - test for bind<void> with member functions
//
// Copyright (c) 2008 Peter Dimov
// Copyright (c) 2014 Agustin Berge
//
// 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/bind.hpp>
#include <boost/ref.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
struct Z
{
int m;
};
void member_data_test()
{
Z z = { 17041 };
Z * pz = &z;
boost::bind<void>( &Z::m, _1 )( z );
boost::bind<void>( &Z::m, _1 )( pz );
boost::bind<void>( &Z::m, z )();
boost::bind<void>( &Z::m, pz )();
boost::bind<void>( &Z::m, boost::ref(z) )();
Z const cz = z;
Z const * pcz = &cz;
boost::bind<void>( &Z::m, _1 )( cz );
boost::bind<void>( &Z::m, _1 )( pcz );
boost::bind<void>( &Z::m, cz )();
boost::bind<void>( &Z::m, pcz )();
boost::bind<void>( &Z::m, boost::ref(cz) )();
}
int main()
{
member_data_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,187 @@
#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_void_mf_test.cpp - test for bind<void> with member functions
//
// Copyright (c) 2008 Peter Dimov
// Copyright (c) 2014 Agustin Berge
//
// 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/bind.hpp>
#include <boost/ref.hpp>
#include <boost/core/lightweight_test.hpp>
//
long global_result;
//
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int f0() { f1(17); return 0; }
int g0() const { g1(17); return 0; }
void h0() { h1(17); }
int f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
void h1(int a1) { hash = (hash * 17041 + a1 * 2) % 32768; }
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; }
void h2(int a1, int a2) { h1(a1); h1(a2); }
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; }
void h3(int a1, int a2, int a3) { h2(a1, a2); h1(a3); }
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; }
void h4(int a1, int a2, int a3, int a4) { h3(a1, a2, a3); h1(a4); }
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; }
void h5(int a1, int a2, int a3, int a4, int a5) { h4(a1, a2, a3, a4); h1(a5); }
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; }
void h6(int a1, int a2, int a3, int a4, int a5, int a6) { h5(a1, a2, a3, a4, a5); h1(a6); }
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; }
void h7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { h6(a1, a2, a3, a4, a5, a6); h1(a7); }
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 h8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { h7(a1, a2, a3, a4, a5, a6, a7); h1(a8); }
};
void member_function_test()
{
using namespace boost;
X x;
// 0
bind<void>(&X::f0, &x)();
bind<void>(&X::f0, ref(x))();
bind<void>(&X::g0, &x)();
bind<void>(&X::g0, x)();
bind<void>(&X::g0, ref(x))();
bind<void>(&X::h0, x)();
// 1
bind<void>(&X::f1, &x, 1)();
bind<void>(&X::f1, ref(x), 1)();
bind<void>(&X::g1, &x, 1)();
bind<void>(&X::g1, x, 1)();
bind<void>(&X::g1, ref(x), 1)();
bind<void>(&X::h1, x, 1)();
// 2
bind<void>(&X::f2, &x, 1, 2)();
bind<void>(&X::f2, ref(x), 1, 2)();
bind<void>(&X::g2, &x, 1, 2)();
bind<void>(&X::g2, x, 1, 2)();
bind<void>(&X::g2, ref(x), 1, 2)();
bind<void>(&X::h2, x, 1, 2)();
// 3
bind<void>(&X::f3, &x, 1, 2, 3)();
bind<void>(&X::f3, ref(x), 1, 2, 3)();
bind<void>(&X::g3, &x, 1, 2, 3)();
bind<void>(&X::g3, x, 1, 2, 3)();
bind<void>(&X::g3, ref(x), 1, 2, 3)();
bind<void>(&X::h3, x, 1, 2, 3)();
// 4
bind<void>(&X::f4, &x, 1, 2, 3, 4)();
bind<void>(&X::f4, ref(x), 1, 2, 3, 4)();
bind<void>(&X::g4, &x, 1, 2, 3, 4)();
bind<void>(&X::g4, x, 1, 2, 3, 4)();
bind<void>(&X::g4, ref(x), 1, 2, 3, 4)();
bind<void>(&X::h4, x, 1, 2, 3, 4)();
// 5
bind<void>(&X::f5, &x, 1, 2, 3, 4, 5)();
bind<void>(&X::f5, ref(x), 1, 2, 3, 4, 5)();
bind<void>(&X::g5, &x, 1, 2, 3, 4, 5)();
bind<void>(&X::g5, x, 1, 2, 3, 4, 5)();
bind<void>(&X::g5, ref(x), 1, 2, 3, 4, 5)();
bind<void>(&X::h5, x, 1, 2, 3, 4, 5)();
// 6
bind<void>(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
bind<void>(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)();
bind<void>(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
bind<void>(&X::g6, x, 1, 2, 3, 4, 5, 6)();
bind<void>(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)();
bind<void>(&X::h6, x, 1, 2, 3, 4, 5, 6)();
// 7
bind<void>(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind<void>(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind<void>(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind<void>(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
bind<void>(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind<void>(&X::h7, x, 1, 2, 3, 4, 5, 6, 7)();
// 8
bind<void>(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind<void>(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
bind<void>(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind<void>(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind<void>(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
bind<void>(&X::h8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
}
int main()
{
member_function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,130 @@
#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_void_test.cpp - test for bind<void>
//
// Copyright (c) 2008 Peter Dimov
// Copyright (c) 2014 Agustin Berge
//
// 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/bind.hpp>
#include <boost/ref.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
long global_result;
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 function_test()
{
using namespace boost;
int const i = 1;
BOOST_TEST( (bind<void>(f_0)(i), (global_result == 17041L)) );
BOOST_TEST( (bind<void>(f_1, _1)(i), (global_result == 1L)) );
BOOST_TEST( (bind<void>(f_2, _1, 2)(i), (global_result == 21L)) );
BOOST_TEST( (bind<void>(f_3, _1, 2, 3)(i), (global_result == 321L)) );
BOOST_TEST( (bind<void>(f_4, _1, 2, 3, 4)(i), (global_result == 4321L)) );
BOOST_TEST( (bind<void>(f_5, _1, 2, 3, 4, 5)(i), (global_result == 54321L)) );
BOOST_TEST( (bind<void>(f_6, _1, 2, 3, 4, 5, 6)(i), (global_result == 654321L)) );
BOOST_TEST( (bind<void>(f_7, _1, 2, 3, 4, 5, 6, 7)(i), (global_result == 7654321L)) );
BOOST_TEST( (bind<void>(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i), (global_result == 87654321L)) );
BOOST_TEST( (bind<void>(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i), (global_result == 987654321L)) );
}
//
struct Y
{
short operator()(short & r) const { return global_result = ++r; }
int operator()(int a, int b) const { return global_result = a + 10 * b; }
long operator() (long a, long b, long c) const { return global_result = a + 10 * b + 100 * c; }
void operator() (long a, long b, long c, long d) const { global_result = a + 10 * b + 100 * c + 1000 * d; }
};
void function_object_test()
{
using namespace boost;
short i(6);
int const k = 3;
BOOST_TEST( (bind<void>(Y(), ref(i))(), (global_result == 7)) );
BOOST_TEST( (bind<void>(Y(), ref(i))(), (global_result == 8)) );
BOOST_TEST( (bind<void>(Y(), i, _1)(k), (global_result == 38)) );
BOOST_TEST( (bind<void>(Y(), i, _1, 9)(k), (global_result == 938)) );
BOOST_TEST( (bind<void>(Y(), i, _1, 9, 4)(k), (global_result == 4938)) );
}
int main()
{
function_test();
function_object_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,18 @@
# Copyright 2018, 2019 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
cmake_minimum_required(VERSION 3.5...3.16)
project(cmake_install_test LANGUAGES CXX)
find_package(boost_bind REQUIRED)
find_package(boost_core REQUIRED)
add_executable(quick ../quick.cpp)
target_link_libraries(quick Boost::bind Boost::core)
enable_testing()
add_test(quick quick)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

View File

@@ -0,0 +1,20 @@
# Copyright 2018, 2019 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
cmake_minimum_required(VERSION 3.5...3.16)
project(cmake_subdir_test LANGUAGES CXX)
add_subdirectory(../.. boostorg/bind)
add_subdirectory(../../../assert boostorg/assert)
add_subdirectory(../../../config boostorg/config)
add_subdirectory(../../../core boostorg/core)
add_executable(quick ../quick.cpp)
target_link_libraries(quick Boost::bind Boost::core)
enable_testing()
add_test(quick quick)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

View File

@@ -0,0 +1,22 @@
// Copyright 2017, 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/bind.hpp>
#include <boost/core/lightweight_test.hpp>
//
int f( int a, int b, int c )
{
return a + 10 * b + 100 * c;
}
int main()
{
int const i = 1;
BOOST_TEST_EQ( boost::bind( f, _1, 2, _2 )( i, 3 ), 321 );
return boost::report_errors();
}

View File

@@ -0,0 +1,196 @@
#include <boost/config.hpp>
#ifndef BOOST_MSVC
int main()
{
}
#else
#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
//
// mem_fn_cdecl_test.cpp - a test for mem_fn.hpp + __cdecl
//
// Copyright (c) 2005 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)
//
#define BOOST_MEM_FN_ENABLE_CDECL
#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) {}
int __cdecl f0() { f1(17); return 0; }
int __cdecl g0() const { g1(17); return 0; }
int __cdecl f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int __cdecl g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int __cdecl f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
int __cdecl g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
int __cdecl f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
int __cdecl g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
int __cdecl f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
int __cdecl g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
int __cdecl f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
int __cdecl g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
int __cdecl f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int __cdecl 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 __cdecl 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 __cdecl 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 __cdecl 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 __cdecl 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 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);
}
#endif

View File

@@ -0,0 +1,188 @@
#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
//
// mem_fn_derived_test.cpp - tests mem_fn.hpp with derived objects
//
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
//
// 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/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 B
{
mutable unsigned int hash;
B(): 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; }
};
struct X: public B
{
};
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(mem_fn(&X::hash)(x) == 17610 && mem_fn(&X::hash)(sp) == 2155);
}

View File

@@ -0,0 +1,67 @@
#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
//
// mem_fn_dm_test.cpp - data members
//
// Copyright (c) 2005 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/mem_fn.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
{
int m;
};
int main()
{
X x = { 0 };
boost::mem_fn( &X::m )( x ) = 401;
BOOST_TEST( x.m == 401 );
BOOST_TEST( boost::mem_fn( &X::m )( x ) == 401 );
boost::mem_fn( &X::m )( &x ) = 502;
BOOST_TEST( x.m == 502 );
BOOST_TEST( boost::mem_fn( &X::m )( &x ) == 502 );
X * px = &x;
boost::mem_fn( &X::m )( px ) = 603;
BOOST_TEST( x.m == 603 );
BOOST_TEST( boost::mem_fn( &X::m )( px ) == 603 );
X const & cx = x;
X const * pcx = &x;
BOOST_TEST( boost::mem_fn( &X::m )( cx ) == 603 );
BOOST_TEST( boost::mem_fn( &X::m )( pcx ) == 603 );
return boost::report_errors();
}

View File

@@ -0,0 +1,300 @@
#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
//
// mem_fn_eq_test.cpp - boost::mem_fn equality operator
//
// Copyright (c) 2004 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/mem_fn.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
{
int dm_1;
int dm_2;
// 0
int mf0_1() { return 0; }
int mf0_2() { return 1; }
int cmf0_1() const { return 0; }
int cmf0_2() const { return 1; }
void mf0v_1() {}
void mf0v_2() { static int x; ++x; }
void cmf0v_1() const {}
void cmf0v_2() const { static int x; ++x; }
// 1
int mf1_1(int) { return 0; }
int mf1_2(int) { return 1; }
int cmf1_1(int) const { return 0; }
int cmf1_2(int) const { return 1; }
void mf1v_1(int) {}
void mf1v_2(int) { static int x; ++x; }
void cmf1v_1(int) const {}
void cmf1v_2(int) const { static int x; ++x; }
// 2
int mf2_1(int, int) { return 0; }
int mf2_2(int, int) { return 1; }
int cmf2_1(int, int) const { return 0; }
int cmf2_2(int, int) const { return 1; }
void mf2v_1(int, int) {}
void mf2v_2(int, int) { static int x; ++x; }
void cmf2v_1(int, int) const {}
void cmf2v_2(int, int) const { static int x; ++x; }
// 3
int mf3_1(int, int, int) { return 0; }
int mf3_2(int, int, int) { return 1; }
int cmf3_1(int, int, int) const { return 0; }
int cmf3_2(int, int, int) const { return 1; }
void mf3v_1(int, int, int) {}
void mf3v_2(int, int, int) { static int x; ++x; }
void cmf3v_1(int, int, int) const {}
void cmf3v_2(int, int, int) const { static int x; ++x; }
// 4
int mf4_1(int, int, int, int) { return 0; }
int mf4_2(int, int, int, int) { return 1; }
int cmf4_1(int, int, int, int) const { return 0; }
int cmf4_2(int, int, int, int) const { return 1; }
void mf4v_1(int, int, int, int) {}
void mf4v_2(int, int, int, int) { static int x; ++x; }
void cmf4v_1(int, int, int, int) const {}
void cmf4v_2(int, int, int, int) const { static int x; ++x; }
// 5
int mf5_1(int, int, int, int, int) { return 0; }
int mf5_2(int, int, int, int, int) { return 1; }
int cmf5_1(int, int, int, int, int) const { return 0; }
int cmf5_2(int, int, int, int, int) const { return 1; }
void mf5v_1(int, int, int, int, int) {}
void mf5v_2(int, int, int, int, int) { static int x; ++x; }
void cmf5v_1(int, int, int, int, int) const {}
void cmf5v_2(int, int, int, int, int) const { static int x; ++x; }
// 6
int mf6_1(int, int, int, int, int, int) { return 0; }
int mf6_2(int, int, int, int, int, int) { return 1; }
int cmf6_1(int, int, int, int, int, int) const { return 0; }
int cmf6_2(int, int, int, int, int, int) const { return 1; }
void mf6v_1(int, int, int, int, int, int) {}
void mf6v_2(int, int, int, int, int, int) { static int x; ++x; }
void cmf6v_1(int, int, int, int, int, int) const {}
void cmf6v_2(int, int, int, int, int, int) const { static int x; ++x; }
// 7
int mf7_1(int, int, int, int, int, int, int) { return 0; }
int mf7_2(int, int, int, int, int, int, int) { return 1; }
int cmf7_1(int, int, int, int, int, int, int) const { return 0; }
int cmf7_2(int, int, int, int, int, int, int) const { return 1; }
void mf7v_1(int, int, int, int, int, int, int) {}
void mf7v_2(int, int, int, int, int, int, int) { static int x; ++x; }
void cmf7v_1(int, int, int, int, int, int, int) const {}
void cmf7v_2(int, int, int, int, int, int, int) const { static int x; ++x; }
// 8
int mf8_1(int, int, int, int, int, int, int, int) { return 0; }
int mf8_2(int, int, int, int, int, int, int, int) { return 1; }
int cmf8_1(int, int, int, int, int, int, int, int) const { return 0; }
int cmf8_2(int, int, int, int, int, int, int, int) const { return 1; }
void mf8v_1(int, int, int, int, int, int, int, int) {}
void mf8v_2(int, int, int, int, int, int, int, int) { static int x; ++x; }
void cmf8v_1(int, int, int, int, int, int, int, int) const {}
void cmf8v_2(int, int, int, int, int, int, int, int) const { static int x; ++x; }
};
int main()
{
BOOST_TEST( boost::mem_fn(&X::dm_1) == boost::mem_fn(&X::dm_1) );
BOOST_TEST( boost::mem_fn(&X::dm_1) != boost::mem_fn(&X::dm_2) );
// 0
BOOST_TEST( boost::mem_fn(&X::mf0_1) == boost::mem_fn(&X::mf0_1) );
BOOST_TEST( boost::mem_fn(&X::mf0_1) != boost::mem_fn(&X::mf0_2) );
BOOST_TEST( boost::mem_fn(&X::cmf0_1) == boost::mem_fn(&X::cmf0_1) );
BOOST_TEST( boost::mem_fn(&X::cmf0_1) != boost::mem_fn(&X::cmf0_2) );
BOOST_TEST( boost::mem_fn(&X::mf0v_1) == boost::mem_fn(&X::mf0v_1) );
BOOST_TEST( boost::mem_fn(&X::mf0v_1) != boost::mem_fn(&X::mf0v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf0v_1) == boost::mem_fn(&X::cmf0v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf0v_1) != boost::mem_fn(&X::cmf0v_2) );
// 1
BOOST_TEST( boost::mem_fn(&X::mf1_1) == boost::mem_fn(&X::mf1_1) );
BOOST_TEST( boost::mem_fn(&X::mf1_1) != boost::mem_fn(&X::mf1_2) );
BOOST_TEST( boost::mem_fn(&X::cmf1_1) == boost::mem_fn(&X::cmf1_1) );
BOOST_TEST( boost::mem_fn(&X::cmf1_1) != boost::mem_fn(&X::cmf1_2) );
BOOST_TEST( boost::mem_fn(&X::mf1v_1) == boost::mem_fn(&X::mf1v_1) );
BOOST_TEST( boost::mem_fn(&X::mf1v_1) != boost::mem_fn(&X::mf1v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf1v_1) == boost::mem_fn(&X::cmf1v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf1v_1) != boost::mem_fn(&X::cmf1v_2) );
// 2
BOOST_TEST( boost::mem_fn(&X::mf2_1) == boost::mem_fn(&X::mf2_1) );
BOOST_TEST( boost::mem_fn(&X::mf2_1) != boost::mem_fn(&X::mf2_2) );
BOOST_TEST( boost::mem_fn(&X::cmf2_1) == boost::mem_fn(&X::cmf2_1) );
BOOST_TEST( boost::mem_fn(&X::cmf2_1) != boost::mem_fn(&X::cmf2_2) );
BOOST_TEST( boost::mem_fn(&X::mf2v_1) == boost::mem_fn(&X::mf2v_1) );
BOOST_TEST( boost::mem_fn(&X::mf2v_1) != boost::mem_fn(&X::mf2v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf2v_1) == boost::mem_fn(&X::cmf2v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf2v_1) != boost::mem_fn(&X::cmf2v_2) );
// 3
BOOST_TEST( boost::mem_fn(&X::mf3_1) == boost::mem_fn(&X::mf3_1) );
BOOST_TEST( boost::mem_fn(&X::mf3_1) != boost::mem_fn(&X::mf3_2) );
BOOST_TEST( boost::mem_fn(&X::cmf3_1) == boost::mem_fn(&X::cmf3_1) );
BOOST_TEST( boost::mem_fn(&X::cmf3_1) != boost::mem_fn(&X::cmf3_2) );
BOOST_TEST( boost::mem_fn(&X::mf3v_1) == boost::mem_fn(&X::mf3v_1) );
BOOST_TEST( boost::mem_fn(&X::mf3v_1) != boost::mem_fn(&X::mf3v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf3v_1) == boost::mem_fn(&X::cmf3v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf3v_1) != boost::mem_fn(&X::cmf3v_2) );
// 4
BOOST_TEST( boost::mem_fn(&X::mf4_1) == boost::mem_fn(&X::mf4_1) );
BOOST_TEST( boost::mem_fn(&X::mf4_1) != boost::mem_fn(&X::mf4_2) );
BOOST_TEST( boost::mem_fn(&X::cmf4_1) == boost::mem_fn(&X::cmf4_1) );
BOOST_TEST( boost::mem_fn(&X::cmf4_1) != boost::mem_fn(&X::cmf4_2) );
BOOST_TEST( boost::mem_fn(&X::mf4v_1) == boost::mem_fn(&X::mf4v_1) );
BOOST_TEST( boost::mem_fn(&X::mf4v_1) != boost::mem_fn(&X::mf4v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf4v_1) == boost::mem_fn(&X::cmf4v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf4v_1) != boost::mem_fn(&X::cmf4v_2) );
// 5
BOOST_TEST( boost::mem_fn(&X::mf5_1) == boost::mem_fn(&X::mf5_1) );
BOOST_TEST( boost::mem_fn(&X::mf5_1) != boost::mem_fn(&X::mf5_2) );
BOOST_TEST( boost::mem_fn(&X::cmf5_1) == boost::mem_fn(&X::cmf5_1) );
BOOST_TEST( boost::mem_fn(&X::cmf5_1) != boost::mem_fn(&X::cmf5_2) );
BOOST_TEST( boost::mem_fn(&X::mf5v_1) == boost::mem_fn(&X::mf5v_1) );
BOOST_TEST( boost::mem_fn(&X::mf5v_1) != boost::mem_fn(&X::mf5v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf5v_1) == boost::mem_fn(&X::cmf5v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf5v_1) != boost::mem_fn(&X::cmf5v_2) );
// 6
BOOST_TEST( boost::mem_fn(&X::mf6_1) == boost::mem_fn(&X::mf6_1) );
BOOST_TEST( boost::mem_fn(&X::mf6_1) != boost::mem_fn(&X::mf6_2) );
BOOST_TEST( boost::mem_fn(&X::cmf6_1) == boost::mem_fn(&X::cmf6_1) );
BOOST_TEST( boost::mem_fn(&X::cmf6_1) != boost::mem_fn(&X::cmf6_2) );
BOOST_TEST( boost::mem_fn(&X::mf6v_1) == boost::mem_fn(&X::mf6v_1) );
BOOST_TEST( boost::mem_fn(&X::mf6v_1) != boost::mem_fn(&X::mf6v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf6v_1) == boost::mem_fn(&X::cmf6v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf6v_1) != boost::mem_fn(&X::cmf6v_2) );
// 7
BOOST_TEST( boost::mem_fn(&X::mf7_1) == boost::mem_fn(&X::mf7_1) );
BOOST_TEST( boost::mem_fn(&X::mf7_1) != boost::mem_fn(&X::mf7_2) );
BOOST_TEST( boost::mem_fn(&X::cmf7_1) == boost::mem_fn(&X::cmf7_1) );
BOOST_TEST( boost::mem_fn(&X::cmf7_1) != boost::mem_fn(&X::cmf7_2) );
BOOST_TEST( boost::mem_fn(&X::mf7v_1) == boost::mem_fn(&X::mf7v_1) );
BOOST_TEST( boost::mem_fn(&X::mf7v_1) != boost::mem_fn(&X::mf7v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf7v_1) == boost::mem_fn(&X::cmf7v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf7v_1) != boost::mem_fn(&X::cmf7v_2) );
// 8
BOOST_TEST( boost::mem_fn(&X::mf8_1) == boost::mem_fn(&X::mf8_1) );
BOOST_TEST( boost::mem_fn(&X::mf8_1) != boost::mem_fn(&X::mf8_2) );
BOOST_TEST( boost::mem_fn(&X::cmf8_1) == boost::mem_fn(&X::cmf8_1) );
BOOST_TEST( boost::mem_fn(&X::cmf8_1) != boost::mem_fn(&X::cmf8_2) );
BOOST_TEST( boost::mem_fn(&X::mf8v_1) == boost::mem_fn(&X::mf8v_1) );
BOOST_TEST( boost::mem_fn(&X::mf8v_1) != boost::mem_fn(&X::mf8v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf8v_1) == boost::mem_fn(&X::cmf8v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf8v_1) != boost::mem_fn(&X::cmf8v_2) );
return boost::report_errors();
}

View File

@@ -0,0 +1,196 @@
#include <boost/config.hpp>
#ifndef BOOST_MSVC
int main()
{
}
#else
#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
//
// mem_fn_fastcall_test.cpp - a test for mem_fn.hpp + __fastcall
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//
// 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)
//
#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);
}
#endif

View File

@@ -0,0 +1,169 @@
// Copyright 2001, 2002, 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt)
#include <boost/mem_fn.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#if defined(BOOST_NO_CXX11_NOEXCEPT)
int main()
{
}
#else
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int f0() noexcept { f1(17); return 0; }
int g0() const noexcept { g1(17); return 0; }
int f1(int a1) noexcept { hash = (hash * 17041 + a1) % 32768; return 0; }
int g1(int a1) const noexcept { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int f2(int a1, int a2) noexcept { f1(a1); f1(a2); return 0; }
int g2(int a1, int a2) const noexcept { g1(a1); g1(a2); return 0; }
int f3(int a1, int a2, int a3) noexcept { f2(a1, a2); f1(a3); return 0; }
int g3(int a1, int a2, int a3) const noexcept { g2(a1, a2); g1(a3); return 0; }
int f4(int a1, int a2, int a3, int a4) noexcept { f3(a1, a2, a3); f1(a4); return 0; }
int g4(int a1, int a2, int a3, int a4) const noexcept { g3(a1, a2, a3); g1(a4); return 0; }
int f5(int a1, int a2, int a3, int a4, int a5) noexcept { f4(a1, a2, a3, a4); f1(a5); return 0; }
int g5(int a1, int a2, int a3, int a4, int a5) const noexcept { g4(a1, a2, a3, a4); g1(a5); return 0; }
int f6(int a1, int a2, int a3, int a4, int a5, int a6) noexcept { 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 noexcept { 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) noexcept { 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 noexcept { 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) noexcept { 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 noexcept { 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 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(mem_fn(&X::hash)(x) == 17610 && mem_fn(&X::hash)(sp) == 2155);
}
#endif

View File

@@ -0,0 +1,36 @@
//
// mem_fn_ref_test.cpp - reference_wrapper
//
// Copyright (c) 2009 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/mem_fn.hpp>
#include <boost/ref.hpp>
#include <boost/detail/lightweight_test.hpp>
struct X
{
int f()
{
return 1;
}
int g() const
{
return 2;
}
};
int main()
{
X x;
BOOST_TEST( boost::mem_fn( &X::f )( boost::ref( x ) ) == 1 );
BOOST_TEST( boost::mem_fn( &X::g )( boost::cref( x ) ) == 2 );
return boost::report_errors();
}

View File

@@ -0,0 +1,117 @@
#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
//
// mem_fn_test.cpp - mem_fn.hpp with rvalues
//
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2005 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/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
unsigned int hash = 0;
struct X
{
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;
}
}
boost::shared_ptr<X> make()
{
return boost::shared_ptr<X>( new X );
}
int main()
{
using boost::mem_fn;
mem_fn(&X::f0)( make() );
mem_fn(&X::g0)( make() );
mem_fn(&X::f1)( make(), 1 );
mem_fn(&X::g1)( make(), 1 );
mem_fn(&X::f2)( make(), 1, 2 );
mem_fn(&X::g2)( make(), 1, 2 );
mem_fn(&X::f3)( make(), 1, 2, 3 );
mem_fn(&X::g3)( make(), 1, 2, 3 );
mem_fn(&X::f4)( make(), 1, 2, 3, 4 );
mem_fn(&X::g4)( make(), 1, 2, 3, 4 );
mem_fn(&X::f5)( make(), 1, 2, 3, 4, 5 );
mem_fn(&X::g5)( make(), 1, 2, 3, 4, 5 );
mem_fn(&X::f6)( make(), 1, 2, 3, 4, 5, 6 );
mem_fn(&X::g6)( make(), 1, 2, 3, 4, 5, 6 );
mem_fn(&X::f7)( make(), 1, 2, 3, 4, 5, 6, 7 );
mem_fn(&X::g7)( make(), 1, 2, 3, 4, 5, 6, 7 );
mem_fn(&X::f8)( make(), 1, 2, 3, 4, 5, 6, 7, 8 );
mem_fn(&X::g8)( make(), 1, 2, 3, 4, 5, 6, 7, 8 );
return detect_errors( hash == 2155 );
}

View File

@@ -0,0 +1,196 @@
#include <boost/config.hpp>
#ifndef BOOST_MSVC
int main()
{
}
#else
#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
//
// mem_fn_stdcall_test.cpp - a test for mem_fn.hpp + __stdcall
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// 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)
//
#define BOOST_MEM_FN_ENABLE_STDCALL
#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) {}
int __stdcall f0() { f1(17); return 0; }
int __stdcall g0() const { g1(17); return 0; }
int __stdcall f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int __stdcall g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int __stdcall f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
int __stdcall g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
int __stdcall f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
int __stdcall g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
int __stdcall f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
int __stdcall g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
int __stdcall f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
int __stdcall g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
int __stdcall f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int __stdcall 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 __stdcall 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 __stdcall 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 __stdcall 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 __stdcall 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 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);
}
#endif

View File

@@ -0,0 +1,184 @@
#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
//
// mem_fn_test.cpp - a test for mem_fn.hpp
//
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
//
// 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/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) {}
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 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(mem_fn(&X::hash)(x) == 17610 && mem_fn(&X::hash)(sp) == 2155);
}

View File

@@ -0,0 +1,151 @@
#include <boost/config.hpp>
#include <boost/detail/workaround.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
//
// mem_fn_unary_addr_test.cpp - poisoned operator& test
//
// Copyright (c) 2009 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/mem_fn.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
unsigned int hash = 0;
struct X
{
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; }
};
template<class T> class Y
{
private:
T * pt_;
void operator& ();
void operator& () const;
public:
explicit Y( T * pt ): pt_( pt )
{
}
T * get() const
{
return pt_;
}
};
#if defined( BOOST_BORLANDC ) && BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT( 0x620 ) )
namespace boost
{
#endif
template<class T> T * get_pointer( Y< T > const & y )
{
return y.get();
}
#if defined( BOOST_BORLANDC ) && BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT( 0x620 ) )
} // namespace boost
#endif
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;
Y<X> px( &x );
Y<X const> pcx( &x );
mem_fn(&X::f0)( px );
mem_fn(&X::g0)( pcx );
mem_fn(&X::f1)( px, 1 );
mem_fn(&X::g1)( pcx, 1 );
mem_fn(&X::f2)( px, 1, 2 );
mem_fn(&X::g2)( pcx, 1, 2 );
mem_fn(&X::f3)( px, 1, 2, 3 );
mem_fn(&X::g3)( pcx, 1, 2, 3 );
mem_fn(&X::f4)( px, 1, 2, 3, 4 );
mem_fn(&X::g4)( pcx, 1, 2, 3, 4 );
mem_fn(&X::f5)( px, 1, 2, 3, 4, 5 );
mem_fn(&X::g5)( pcx, 1, 2, 3, 4, 5 );
mem_fn(&X::f6)( px, 1, 2, 3, 4, 5, 6 );
mem_fn(&X::g6)( pcx, 1, 2, 3, 4, 5, 6 );
mem_fn(&X::f7)( px, 1, 2, 3, 4, 5, 6, 7 );
mem_fn(&X::g7)( pcx, 1, 2, 3, 4, 5, 6, 7 );
mem_fn(&X::f8)( px, 1, 2, 3, 4, 5, 6, 7, 8 );
mem_fn(&X::g8)( pcx, 1, 2, 3, 4, 5, 6, 7, 8 );
return detect_errors( hash == 2155 );
}

View File

@@ -0,0 +1,184 @@
#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
//
// mem_fn_void_test.cpp - a test for mem_fn.hpp + void returns
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// 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/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 f0() { f1(17); }
void g0() const { g1(17); }
void f1(int a1) { hash = (hash * 17041 + a1) % 32768; }
void g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; }
void f2(int a1, int a2) { f1(a1); f1(a2); }
void g2(int a1, int a2) const { g1(a1); g1(a2); }
void f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); }
void g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); }
void f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); }
void g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); }
void f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); }
void g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); }
void f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); }
void g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); }
void 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 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 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 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);
}

View File

@@ -0,0 +1,37 @@
//
// placeholder_const_ref_test.cpp - forming a const& to _1
//
// Copyright 2015 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/placeholders.hpp>
#include <boost/is_placeholder.hpp>
#include <boost/core/lightweight_test.hpp>
//
template<class T> void test( T const &, int i )
{
BOOST_TEST_EQ( boost::is_placeholder<T>::value, i );
}
int main()
{
using namespace boost::placeholders;
test( _1, 1 );
test( _2, 2 );
test( _3, 3 );
test( _4, 4 );
test( _5, 5 );
test( _6, 6 );
test( _7, 7 );
test( _8, 8 );
test( _9, 9 );
return boost::report_errors();
}

View File

@@ -0,0 +1,55 @@
//
// placeholder_std_bind_test.cpp - std::bind with Boost's _1
//
// Copyright 2016 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/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_CXX11_HDR_FUNCTIONAL is defined" )
int main() {}
#elif defined(BOOST_GCC) && BOOST_GCC < 40600
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_GCC is less than 40600" )
int main() {}
#else
#include <boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
#include <functional>
using namespace boost::placeholders;
//
namespace std
{
template<int N> struct is_placeholder< boost::arg<N> >: public integral_constant<int, N> {};
} // namespace std
int foo( int i )
{
return i;
}
int main()
{
BOOST_TEST_EQ( std::bind( foo, _1 )( 1 ), 1 );
BOOST_TEST_EQ( std::bind( foo, _2 )( 1, 2 ), 2 );
BOOST_TEST_EQ( std::bind( foo, _3 )( 1, 2, 3 ), 3 );
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,42 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt)
#include <boost/bind/protect.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <functional>
//
int main()
{
BOOST_TEST_EQ( boost::protect( std::plus<int>() )( 1, 2 ), 3 );
BOOST_TEST_EQ( boost::protect( std::minus<int>() )( 1, 2 ), -1 );
BOOST_TEST_EQ( boost::protect( std::multiplies<int>() )( 1, 2 ), 2 );
BOOST_TEST_EQ( boost::protect( std::divides<int>() )( 1, 2 ), 0 );
BOOST_TEST_EQ( boost::protect( std::modulus<int>() )( 1, 2 ), 1 );
BOOST_TEST_EQ( boost::protect( std::negate<int>() )( 1 ), -1 );
BOOST_TEST_EQ( boost::protect( std::equal_to<int>() )( 1, 2 ), false );
BOOST_TEST_EQ( boost::protect( std::not_equal_to<int>() )( 1, 2 ), true );
BOOST_TEST_EQ( boost::protect( std::greater<int>() )( 1, 2 ), false );
BOOST_TEST_EQ( boost::protect( std::less<int>() )( 1, 2 ), true );
BOOST_TEST_EQ( boost::protect( std::greater_equal<int>() )( 1, 2 ), false );
BOOST_TEST_EQ( boost::protect( std::less_equal<int>() )( 1, 2 ), true );
BOOST_TEST_EQ( boost::protect( std::logical_and<int>() )( 1, 2 ), true );
BOOST_TEST_EQ( boost::protect( std::logical_or<int>() )( 1, 2 ), true );
BOOST_TEST_EQ( boost::protect( std::logical_not<int>() )( 1 ), false );
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1600)
BOOST_TEST_EQ( boost::protect( std::bit_and<int>() )( 1, 2 ), 0 );
BOOST_TEST_EQ( boost::protect( std::bit_or<int>() )( 1, 2 ), 3 );
BOOST_TEST_EQ( boost::protect( std::bit_xor<int>() )( 1, 2 ), 3 );
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,284 @@
// protect_test.cpp
//
// Copyright (c) 2009 Steven Watanabe
//
// 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/protect.hpp>
#include <boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
int f(int x)
{
return x;
}
int& g(int& x)
{
return x;
}
template<class T>
const T& constify(const T& arg)
{
return arg;
}
int main()
{
int i[9] = {0,1,2,3,4,5,6,7,8};
// non-const
// test nullary
BOOST_TEST(boost::protect(boost::bind(f, 1))() == 1);
// test lvalues
BOOST_TEST(&boost::protect(boost::bind(g, _1))(i[0]) == &i[0]);
BOOST_TEST(&boost::protect(boost::bind(g, _1))(i[0], i[1]) == &i[0]);
BOOST_TEST(&boost::protect(boost::bind(g, _2))(i[0], i[1]) == &i[1]);
BOOST_TEST(&boost::protect(boost::bind(g, _1))(i[0], i[1], i[2]) == &i[0]);
BOOST_TEST(&boost::protect(boost::bind(g, _2))(i[0], i[1], i[2]) == &i[1]);
BOOST_TEST(&boost::protect(boost::bind(g, _3))(i[0], i[1], i[2]) == &i[2]);
BOOST_TEST(&boost::protect(boost::bind(g, _1))(i[0], i[1], i[2], i[3]) == &i[0]);
BOOST_TEST(&boost::protect(boost::bind(g, _2))(i[0], i[1], i[2], i[3]) == &i[1]);
BOOST_TEST(&boost::protect(boost::bind(g, _3))(i[0], i[1], i[2], i[3]) == &i[2]);
BOOST_TEST(&boost::protect(boost::bind(g, _4))(i[0], i[1], i[2], i[3]) == &i[3]);
BOOST_TEST(&boost::protect(boost::bind(g, _1))(i[0], i[1], i[2], i[3], i[4]) == &i[0]);
BOOST_TEST(&boost::protect(boost::bind(g, _2))(i[0], i[1], i[2], i[3], i[4]) == &i[1]);
BOOST_TEST(&boost::protect(boost::bind(g, _3))(i[0], i[1], i[2], i[3], i[4]) == &i[2]);
BOOST_TEST(&boost::protect(boost::bind(g, _4))(i[0], i[1], i[2], i[3], i[4]) == &i[3]);
BOOST_TEST(&boost::protect(boost::bind(g, _5))(i[0], i[1], i[2], i[3], i[4]) == &i[4]);
BOOST_TEST(&boost::protect(boost::bind(g, _1))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[0]);
BOOST_TEST(&boost::protect(boost::bind(g, _2))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[1]);
BOOST_TEST(&boost::protect(boost::bind(g, _3))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[2]);
BOOST_TEST(&boost::protect(boost::bind(g, _4))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[3]);
BOOST_TEST(&boost::protect(boost::bind(g, _5))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[4]);
BOOST_TEST(&boost::protect(boost::bind(g, _6))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[5]);
BOOST_TEST(&boost::protect(boost::bind(g, _1))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[0]);
BOOST_TEST(&boost::protect(boost::bind(g, _2))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[1]);
BOOST_TEST(&boost::protect(boost::bind(g, _3))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[2]);
BOOST_TEST(&boost::protect(boost::bind(g, _4))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[3]);
BOOST_TEST(&boost::protect(boost::bind(g, _5))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[4]);
BOOST_TEST(&boost::protect(boost::bind(g, _6))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[5]);
BOOST_TEST(&boost::protect(boost::bind(g, _7))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[6]);
BOOST_TEST(&boost::protect(boost::bind(g, _1))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[0]);
BOOST_TEST(&boost::protect(boost::bind(g, _2))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[1]);
BOOST_TEST(&boost::protect(boost::bind(g, _3))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[2]);
BOOST_TEST(&boost::protect(boost::bind(g, _4))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[3]);
BOOST_TEST(&boost::protect(boost::bind(g, _5))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[4]);
BOOST_TEST(&boost::protect(boost::bind(g, _6))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[5]);
BOOST_TEST(&boost::protect(boost::bind(g, _7))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[6]);
BOOST_TEST(&boost::protect(boost::bind(g, _8))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[7]);
BOOST_TEST(&boost::protect(boost::bind(g, _1))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[0]);
BOOST_TEST(&boost::protect(boost::bind(g, _2))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[1]);
BOOST_TEST(&boost::protect(boost::bind(g, _3))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[2]);
BOOST_TEST(&boost::protect(boost::bind(g, _4))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[3]);
BOOST_TEST(&boost::protect(boost::bind(g, _5))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[4]);
BOOST_TEST(&boost::protect(boost::bind(g, _6))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[5]);
BOOST_TEST(&boost::protect(boost::bind(g, _7))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[6]);
BOOST_TEST(&boost::protect(boost::bind(g, _8))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[7]);
BOOST_TEST(&boost::protect(boost::bind(g, _9))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[8]);
// test rvalues
BOOST_TEST(boost::protect(boost::bind(f, _1))(0) == 0);
BOOST_TEST(boost::protect(boost::bind(f, _1))(0, 1) == 0);
BOOST_TEST(boost::protect(boost::bind(f, _2))(0, 1) == 1);
BOOST_TEST(boost::protect(boost::bind(f, _1))(0, 1, 2) == 0);
BOOST_TEST(boost::protect(boost::bind(f, _2))(0, 1, 2) == 1);
BOOST_TEST(boost::protect(boost::bind(f, _3))(0, 1, 2) == 2);
BOOST_TEST(boost::protect(boost::bind(f, _1))(0, 1, 2, 3) == 0);
BOOST_TEST(boost::protect(boost::bind(f, _2))(0, 1, 2, 3) == 1);
BOOST_TEST(boost::protect(boost::bind(f, _3))(0, 1, 2, 3) == 2);
BOOST_TEST(boost::protect(boost::bind(f, _4))(0, 1, 2, 3) == 3);
BOOST_TEST(boost::protect(boost::bind(f, _1))(0, 1, 2, 3, 4) == 0);
BOOST_TEST(boost::protect(boost::bind(f, _2))(0, 1, 2, 3, 4) == 1);
BOOST_TEST(boost::protect(boost::bind(f, _3))(0, 1, 2, 3, 4) == 2);
BOOST_TEST(boost::protect(boost::bind(f, _4))(0, 1, 2, 3, 4) == 3);
BOOST_TEST(boost::protect(boost::bind(f, _5))(0, 1, 2, 3, 4) == 4);
BOOST_TEST(boost::protect(boost::bind(f, _1))(0, 1, 2, 3, 4, 5) == 0);
BOOST_TEST(boost::protect(boost::bind(f, _2))(0, 1, 2, 3, 4, 5) == 1);
BOOST_TEST(boost::protect(boost::bind(f, _3))(0, 1, 2, 3, 4, 5) == 2);
BOOST_TEST(boost::protect(boost::bind(f, _4))(0, 1, 2, 3, 4, 5) == 3);
BOOST_TEST(boost::protect(boost::bind(f, _5))(0, 1, 2, 3, 4, 5) == 4);
BOOST_TEST(boost::protect(boost::bind(f, _6))(0, 1, 2, 3, 4, 5) == 5);
BOOST_TEST(boost::protect(boost::bind(f, _1))(0, 1, 2, 3, 4, 5, 6) == 0);
BOOST_TEST(boost::protect(boost::bind(f, _2))(0, 1, 2, 3, 4, 5, 6) == 1);
BOOST_TEST(boost::protect(boost::bind(f, _3))(0, 1, 2, 3, 4, 5, 6) == 2);
BOOST_TEST(boost::protect(boost::bind(f, _4))(0, 1, 2, 3, 4, 5, 6) == 3);
BOOST_TEST(boost::protect(boost::bind(f, _5))(0, 1, 2, 3, 4, 5, 6) == 4);
BOOST_TEST(boost::protect(boost::bind(f, _6))(0, 1, 2, 3, 4, 5, 6) == 5);
BOOST_TEST(boost::protect(boost::bind(f, _7))(0, 1, 2, 3, 4, 5, 6) == 6);
BOOST_TEST(boost::protect(boost::bind(f, _1))(0, 1, 2, 3, 4, 5, 6, 7) == 0);
BOOST_TEST(boost::protect(boost::bind(f, _2))(0, 1, 2, 3, 4, 5, 6, 7) == 1);
BOOST_TEST(boost::protect(boost::bind(f, _3))(0, 1, 2, 3, 4, 5, 6, 7) == 2);
BOOST_TEST(boost::protect(boost::bind(f, _4))(0, 1, 2, 3, 4, 5, 6, 7) == 3);
BOOST_TEST(boost::protect(boost::bind(f, _5))(0, 1, 2, 3, 4, 5, 6, 7) == 4);
BOOST_TEST(boost::protect(boost::bind(f, _6))(0, 1, 2, 3, 4, 5, 6, 7) == 5);
BOOST_TEST(boost::protect(boost::bind(f, _7))(0, 1, 2, 3, 4, 5, 6, 7) == 6);
BOOST_TEST(boost::protect(boost::bind(f, _8))(0, 1, 2, 3, 4, 5, 6, 7) == 7);
BOOST_TEST(boost::protect(boost::bind(f, _1))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 0);
BOOST_TEST(boost::protect(boost::bind(f, _2))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 1);
BOOST_TEST(boost::protect(boost::bind(f, _3))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 2);
BOOST_TEST(boost::protect(boost::bind(f, _4))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 3);
BOOST_TEST(boost::protect(boost::bind(f, _5))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 4);
BOOST_TEST(boost::protect(boost::bind(f, _6))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 5);
BOOST_TEST(boost::protect(boost::bind(f, _7))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 6);
BOOST_TEST(boost::protect(boost::bind(f, _8))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 7);
BOOST_TEST(boost::protect(boost::bind(f, _9))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 8);
// test mixed perfect forwarding
BOOST_TEST(boost::protect(boost::bind(f, _1))(i[0], 1) == 0);
BOOST_TEST(boost::protect(boost::bind(f, _2))(i[0], 1) == 1);
BOOST_TEST(boost::protect(boost::bind(f, _1))(0, i[1]) == 0);
BOOST_TEST(boost::protect(boost::bind(f, _2))(0, i[1]) == 1);
// const
// test nullary
BOOST_TEST(constify(constify(boost::protect(boost::bind(f, 1))))() == 1);
// test lvalues
BOOST_TEST(&constify(constify(boost::protect(boost::bind(g, _1))))(i[0]) == &i[0]);
BOOST_TEST(&constify(constify(boost::protect(boost::bind(g, _1))))(i[0], i[1]) == &i[0]);
BOOST_TEST(&constify(constify(boost::protect(boost::bind(g, _2))))(i[0], i[1]) == &i[1]);
BOOST_TEST(&constify(constify(boost::protect(boost::bind(g, _1))))(i[0], i[1], i[2]) == &i[0]);
BOOST_TEST(&constify(constify(boost::protect(boost::bind(g, _2))))(i[0], i[1], i[2]) == &i[1]);
BOOST_TEST(&constify(constify(boost::protect(boost::bind(g, _3))))(i[0], i[1], i[2]) == &i[2]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _1)))(i[0], i[1], i[2], i[3]) == &i[0]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _2)))(i[0], i[1], i[2], i[3]) == &i[1]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _3)))(i[0], i[1], i[2], i[3]) == &i[2]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _4)))(i[0], i[1], i[2], i[3]) == &i[3]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _1)))(i[0], i[1], i[2], i[3], i[4]) == &i[0]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _2)))(i[0], i[1], i[2], i[3], i[4]) == &i[1]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _3)))(i[0], i[1], i[2], i[3], i[4]) == &i[2]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _4)))(i[0], i[1], i[2], i[3], i[4]) == &i[3]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _5)))(i[0], i[1], i[2], i[3], i[4]) == &i[4]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _1)))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[0]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _2)))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[1]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _3)))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[2]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _4)))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[3]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _5)))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[4]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _6)))(i[0], i[1], i[2], i[3], i[4], i[5]) == &i[5]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _1)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[0]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _2)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[1]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _3)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[2]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _4)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[3]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _5)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[4]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _6)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[5]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _7)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6]) == &i[6]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _1)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[0]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _2)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[1]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _3)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[2]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _4)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[3]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _5)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[4]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _6)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[5]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _7)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[6]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _8)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]) == &i[7]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _1)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[0]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _2)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[1]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _3)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[2]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _4)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[3]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _5)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[4]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _6)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[5]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _7)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[6]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _8)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[7]);
BOOST_TEST(&constify(boost::protect(boost::bind(g, _9)))(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8]) == &i[8]);
// test rvalues
BOOST_TEST(constify(boost::protect(boost::bind(f, _1)))(0) == 0);
BOOST_TEST(constify(boost::protect(boost::bind(f, _1)))(0, 1) == 0);
BOOST_TEST(constify(boost::protect(boost::bind(f, _2)))(0, 1) == 1);
BOOST_TEST(constify(boost::protect(boost::bind(f, _1)))(0, 1, 2) == 0);
BOOST_TEST(constify(boost::protect(boost::bind(f, _2)))(0, 1, 2) == 1);
BOOST_TEST(constify(boost::protect(boost::bind(f, _3)))(0, 1, 2) == 2);
BOOST_TEST(constify(boost::protect(boost::bind(f, _1)))(0, 1, 2, 3) == 0);
BOOST_TEST(constify(boost::protect(boost::bind(f, _2)))(0, 1, 2, 3) == 1);
BOOST_TEST(constify(boost::protect(boost::bind(f, _3)))(0, 1, 2, 3) == 2);
BOOST_TEST(constify(boost::protect(boost::bind(f, _4)))(0, 1, 2, 3) == 3);
BOOST_TEST(constify(boost::protect(boost::bind(f, _1)))(0, 1, 2, 3, 4) == 0);
BOOST_TEST(constify(boost::protect(boost::bind(f, _2)))(0, 1, 2, 3, 4) == 1);
BOOST_TEST(constify(boost::protect(boost::bind(f, _3)))(0, 1, 2, 3, 4) == 2);
BOOST_TEST(constify(boost::protect(boost::bind(f, _4)))(0, 1, 2, 3, 4) == 3);
BOOST_TEST(constify(boost::protect(boost::bind(f, _5)))(0, 1, 2, 3, 4) == 4);
BOOST_TEST(constify(boost::protect(boost::bind(f, _1)))(0, 1, 2, 3, 4, 5) == 0);
BOOST_TEST(constify(boost::protect(boost::bind(f, _2)))(0, 1, 2, 3, 4, 5) == 1);
BOOST_TEST(constify(boost::protect(boost::bind(f, _3)))(0, 1, 2, 3, 4, 5) == 2);
BOOST_TEST(constify(boost::protect(boost::bind(f, _4)))(0, 1, 2, 3, 4, 5) == 3);
BOOST_TEST(constify(boost::protect(boost::bind(f, _5)))(0, 1, 2, 3, 4, 5) == 4);
BOOST_TEST(constify(boost::protect(boost::bind(f, _6)))(0, 1, 2, 3, 4, 5) == 5);
BOOST_TEST(constify(boost::protect(boost::bind(f, _1)))(0, 1, 2, 3, 4, 5, 6) == 0);
BOOST_TEST(constify(boost::protect(boost::bind(f, _2)))(0, 1, 2, 3, 4, 5, 6) == 1);
BOOST_TEST(constify(boost::protect(boost::bind(f, _3)))(0, 1, 2, 3, 4, 5, 6) == 2);
BOOST_TEST(constify(boost::protect(boost::bind(f, _4)))(0, 1, 2, 3, 4, 5, 6) == 3);
BOOST_TEST(constify(boost::protect(boost::bind(f, _5)))(0, 1, 2, 3, 4, 5, 6) == 4);
BOOST_TEST(constify(boost::protect(boost::bind(f, _6)))(0, 1, 2, 3, 4, 5, 6) == 5);
BOOST_TEST(constify(boost::protect(boost::bind(f, _7)))(0, 1, 2, 3, 4, 5, 6) == 6);
BOOST_TEST(constify(boost::protect(boost::bind(f, _1)))(0, 1, 2, 3, 4, 5, 6, 7) == 0);
BOOST_TEST(constify(boost::protect(boost::bind(f, _2)))(0, 1, 2, 3, 4, 5, 6, 7) == 1);
BOOST_TEST(constify(boost::protect(boost::bind(f, _3)))(0, 1, 2, 3, 4, 5, 6, 7) == 2);
BOOST_TEST(constify(boost::protect(boost::bind(f, _4)))(0, 1, 2, 3, 4, 5, 6, 7) == 3);
BOOST_TEST(constify(boost::protect(boost::bind(f, _5)))(0, 1, 2, 3, 4, 5, 6, 7) == 4);
BOOST_TEST(constify(boost::protect(boost::bind(f, _6)))(0, 1, 2, 3, 4, 5, 6, 7) == 5);
BOOST_TEST(constify(boost::protect(boost::bind(f, _7)))(0, 1, 2, 3, 4, 5, 6, 7) == 6);
BOOST_TEST(constify(boost::protect(boost::bind(f, _8)))(0, 1, 2, 3, 4, 5, 6, 7) == 7);
BOOST_TEST(constify(boost::protect(boost::bind(f, _1)))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 0);
BOOST_TEST(constify(boost::protect(boost::bind(f, _2)))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 1);
BOOST_TEST(constify(boost::protect(boost::bind(f, _3)))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 2);
BOOST_TEST(constify(boost::protect(boost::bind(f, _4)))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 3);
BOOST_TEST(constify(boost::protect(boost::bind(f, _5)))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 4);
BOOST_TEST(constify(boost::protect(boost::bind(f, _6)))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 5);
BOOST_TEST(constify(boost::protect(boost::bind(f, _7)))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 6);
BOOST_TEST(constify(boost::protect(boost::bind(f, _8)))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 7);
BOOST_TEST(constify(boost::protect(boost::bind(f, _9)))(0, 1, 2, 3, 4, 5, 6, 7, 8) == 8);
// test mixed perfect forwarding
BOOST_TEST(constify(boost::protect(boost::bind(f, _1)))(i[0], 1) == 0);
BOOST_TEST(constify(boost::protect(boost::bind(f, _2)))(i[0], 1) == 1);
BOOST_TEST(constify(boost::protect(boost::bind(f, _1)))(0, i[1]) == 0);
BOOST_TEST(constify(boost::protect(boost::bind(f, _2)))(0, i[1]) == 1);
return boost::report_errors();
}

View File

@@ -0,0 +1,46 @@
// protect_test2.cpp
//
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/bind/protect.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/core/is_same.hpp>
template<class T, class F> void test( F )
{
BOOST_TEST_TRAIT_TRUE((boost::core::is_same<typename T::result_type, typename F::result_type>));
}
struct X
{
struct result_type {};
};
struct Y
{
};
template<class T, class U> struct inherit: T, U
{
};
template<class F> void test2( F )
{
// test that F doesn't have ::result_type
BOOST_TEST_TRAIT_TRUE((boost::core::is_same<typename inherit<F, X>::result_type, typename X::result_type>));
}
int main()
{
test<X>( boost::protect( X() ) );
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DECLTYPE) && !(defined(BOOST_GCC) && BOOST_GCC < 40600)
test2( boost::protect( Y() ) );
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,31 @@
//
// quick.cpp - a quick test for boost/bind/bind.hpp
//
// Copyright 2017 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/bind.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::placeholders;
//
int f( int a, int b, int c )
{
return a + 10 * b + 100 * c;
}
int main()
{
int const i = 1;
BOOST_TEST_EQ( boost::bind( f, _1, 2, 3 )( i ), 321 );
return boost::report_errors();
}

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();
}

View File

@@ -0,0 +1,50 @@
// Copyright 2021 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/bind/bind.hpp>
#include <boost/core/lightweight_test.hpp>
#include <functional>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
BOOST_PRAGMA_MESSAGE( "Skipping test due to BOOST_NO_CXX11_HDR_FUNCTIONAL being defined" )
int main() {}
#elif defined(BOOST_NO_CXX11_DECLTYPE)
BOOST_PRAGMA_MESSAGE( "Skipping test due to BOOST_NO_CXX11_DECLTYPE being defined" )
int main() {}
#elif defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
BOOST_PRAGMA_MESSAGE( "Skipping test due to BOOST_NO_CXX11_HDR_TYPE_TRAITS being defined" )
int main() {}
#else
int f( int x )
{
return -x;
}
int main()
{
using namespace std::placeholders;
BOOST_TEST_EQ( boost::bind( f, _1 )( 1 ), -1 );
BOOST_TEST_EQ( boost::bind( f, _2 )( 1, 2 ), -2 );
BOOST_TEST_EQ( boost::bind( f, _3 )( 1, 2, 3 ), -3 );
BOOST_TEST_EQ( boost::bind( f, _4 )( 1, 2, 3, 4 ), -4 );
BOOST_TEST_EQ( boost::bind( f, _5 )( 1, 2, 3, 4, 5 ), -5 );
BOOST_TEST_EQ( boost::bind( f, _6 )( 1, 2, 3, 4, 5, 6 ), -6 );
BOOST_TEST_EQ( boost::bind( f, _7 )( 1, 2, 3, 4, 5, 6, 7 ), -7 );
BOOST_TEST_EQ( boost::bind( f, _8 )( 1, 2, 3, 4, 5, 6, 7, 8 ), -8 );
BOOST_TEST_EQ( boost::bind( f, _9 )( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), -9 );
return boost::report_errors();
}
#endif