forked from boostorg/bind
Merge branch 'develop'
This commit is contained in:
@@ -859,7 +859,295 @@ public:
|
|||||||
|
|
||||||
// bind_t
|
// bind_t
|
||||||
|
|
||||||
#ifndef BOOST_NO_VOID_RETURNS
|
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||||
|
|
||||||
|
template< class A > struct list_add_cref
|
||||||
|
{
|
||||||
|
typedef A const & type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template< class A > struct list_add_cref< A& >
|
||||||
|
{
|
||||||
|
typedef A & type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class R, class F, class L> class bind_t
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
F f_;
|
||||||
|
L l_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef typename result_traits<R, F>::type result_type;
|
||||||
|
typedef bind_t this_type;
|
||||||
|
|
||||||
|
bind_t( F f, L const & l ): f_( f ), l_( l ) {}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
result_type operator()()
|
||||||
|
{
|
||||||
|
list0 a;
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type operator()() const
|
||||||
|
{
|
||||||
|
list0 a;
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1> result_type operator()( A1 && a1 )
|
||||||
|
{
|
||||||
|
list1< typename list_add_cref<A1>::type > a( a1 );
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1> result_type operator()( A1 && a1 ) const
|
||||||
|
{
|
||||||
|
list1< typename list_add_cref<A1>::type > a( a1 );
|
||||||
|
return l_(type<result_type>(), f_, a, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2> result_type operator()( A1 && a1, A2 && a2 )
|
||||||
|
{
|
||||||
|
list2< typename list_add_cref<A1>::type, typename list_add_cref<A2>::type > a( a1, a2 );
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2> result_type operator()( A1 && a1, A2 && a2 ) const
|
||||||
|
{
|
||||||
|
list2< typename list_add_cref<A1>::type, typename list_add_cref<A2>::type > a( a1, a2 );
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3> result_type operator()( A1 && a1, A2 && a2, A3 && a3 )
|
||||||
|
{
|
||||||
|
list3<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type
|
||||||
|
> a( a1, a2, a3 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3> result_type operator()( A1 && a1, A2 && a2, A3 && a3 ) const
|
||||||
|
{
|
||||||
|
list3<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type
|
||||||
|
> a( a1, a2, a3 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4 )
|
||||||
|
{
|
||||||
|
list4<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type
|
||||||
|
> a( a1, a2, a3, a4 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4 ) const
|
||||||
|
{
|
||||||
|
list4<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type
|
||||||
|
> a( a1, a2, a3, a4 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4, class A5> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5 )
|
||||||
|
{
|
||||||
|
list5<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type,
|
||||||
|
typename list_add_cref<A5>::type
|
||||||
|
> a( a1, a2, a3, a4, a5 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4, class A5> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5 ) const
|
||||||
|
{
|
||||||
|
list5<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type,
|
||||||
|
typename list_add_cref<A5>::type
|
||||||
|
> a( a1, a2, a3, a4, a5 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4, class A5, class A6> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6 )
|
||||||
|
{
|
||||||
|
list6<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type,
|
||||||
|
typename list_add_cref<A5>::type,
|
||||||
|
typename list_add_cref<A6>::type
|
||||||
|
> a( a1, a2, a3, a4, a5, a6 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4, class A5, class A6> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6 ) const
|
||||||
|
{
|
||||||
|
list6<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type,
|
||||||
|
typename list_add_cref<A5>::type,
|
||||||
|
typename list_add_cref<A6>::type
|
||||||
|
> a( a1, a2, a3, a4, a5, a6 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7 )
|
||||||
|
{
|
||||||
|
list7<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type,
|
||||||
|
typename list_add_cref<A5>::type,
|
||||||
|
typename list_add_cref<A6>::type,
|
||||||
|
typename list_add_cref<A7>::type
|
||||||
|
> a( a1, a2, a3, a4, a5, a6, a7 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7 ) const
|
||||||
|
{
|
||||||
|
list7<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type,
|
||||||
|
typename list_add_cref<A5>::type,
|
||||||
|
typename list_add_cref<A6>::type,
|
||||||
|
typename list_add_cref<A7>::type
|
||||||
|
> a( a1, a2, a3, a4, a5, a6, a7 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8 )
|
||||||
|
{
|
||||||
|
list8<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type,
|
||||||
|
typename list_add_cref<A5>::type,
|
||||||
|
typename list_add_cref<A6>::type,
|
||||||
|
typename list_add_cref<A7>::type,
|
||||||
|
typename list_add_cref<A8>::type
|
||||||
|
> a( a1, a2, a3, a4, a5, a6, a7, a8 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8 ) const
|
||||||
|
{
|
||||||
|
list8<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type,
|
||||||
|
typename list_add_cref<A5>::type,
|
||||||
|
typename list_add_cref<A6>::type,
|
||||||
|
typename list_add_cref<A7>::type,
|
||||||
|
typename list_add_cref<A8>::type
|
||||||
|
> a( a1, a2, a3, a4, a5, a6, a7, a8 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8, A9 && a9 )
|
||||||
|
{
|
||||||
|
list9<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type,
|
||||||
|
typename list_add_cref<A5>::type,
|
||||||
|
typename list_add_cref<A6>::type,
|
||||||
|
typename list_add_cref<A7>::type,
|
||||||
|
typename list_add_cref<A8>::type,
|
||||||
|
typename list_add_cref<A9>::type
|
||||||
|
> a( a1, a2, a3, a4, a5, a6, a7, a8, a9 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> result_type operator()( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8, A9 && a9 ) const
|
||||||
|
{
|
||||||
|
list9<
|
||||||
|
typename list_add_cref<A1>::type,
|
||||||
|
typename list_add_cref<A2>::type,
|
||||||
|
typename list_add_cref<A3>::type,
|
||||||
|
typename list_add_cref<A4>::type,
|
||||||
|
typename list_add_cref<A5>::type,
|
||||||
|
typename list_add_cref<A6>::type,
|
||||||
|
typename list_add_cref<A7>::type,
|
||||||
|
typename list_add_cref<A8>::type,
|
||||||
|
typename list_add_cref<A9>::type
|
||||||
|
> a( a1, a2, a3, a4, a5, a6, a7, a8, a9 );
|
||||||
|
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
template<class A> result_type eval( A & a )
|
||||||
|
{
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class A> result_type eval( A & a ) const
|
||||||
|
{
|
||||||
|
return l_( type<result_type>(), f_, a, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class V> void accept( V & v ) const
|
||||||
|
{
|
||||||
|
#if !defined( BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP ) && !defined( __BORLANDC__ )
|
||||||
|
using boost::visit_each;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BOOST_BIND_VISIT_EACH( v, f_, 0 );
|
||||||
|
l_.accept( v );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool compare( this_type const & rhs ) const
|
||||||
|
{
|
||||||
|
return ref_compare( f_, rhs.f_, 0 ) && l_ == rhs.l_;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#elif !defined( BOOST_NO_VOID_RETURNS )
|
||||||
|
|
||||||
template<class R, class F, class L> class bind_t
|
template<class R, class F, class L> class bind_t
|
||||||
{
|
{
|
||||||
@@ -875,7 +1163,7 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#else
|
#else // no void returns
|
||||||
|
|
||||||
template<class R> struct bind_t_generator
|
template<class R> struct bind_t_generator
|
||||||
{
|
{
|
||||||
|
@@ -47,4 +47,7 @@ test-suite "bind"
|
|||||||
[ run bind_eq3_test.cpp ]
|
[ run bind_eq3_test.cpp ]
|
||||||
[ run protect_test.cpp ]
|
[ run protect_test.cpp ]
|
||||||
[ run mem_fn_unary_addr_test.cpp ]
|
[ run mem_fn_unary_addr_test.cpp ]
|
||||||
|
[ run bind_function2_test.cpp ]
|
||||||
|
[ run bind_fwd_test.cpp ]
|
||||||
|
[ run bind_fwd2_test.cpp ]
|
||||||
;
|
;
|
||||||
|
118
test/bind_function2_test.cpp
Normal file
118
test/bind_function2_test.cpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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.hpp>
|
||||||
|
#include <boost/function.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
121
test/bind_fwd2_test.cpp
Normal file
121
test/bind_fwd2_test.cpp
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
#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.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
250
test/bind_fwd_test.cpp
Normal file
250
test/bind_fwd_test.cpp
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
#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.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
Reference in New Issue
Block a user