483 changes: 349 additions & 134 deletions include/boost/bind/bind.hpp

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions test/Jamfile.v2
Expand Up @@ -52,4 +52,7 @@ test-suite "bind"
[ 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 ]
;
224 changes: 224 additions & 0 deletions test/bind_function_ap_test.cpp
@@ -0,0 +1,224 @@
#include <boost/config.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( __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.hpp>
#include <boost/function.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <memory>

//

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();
}
75 changes: 75 additions & 0 deletions test/bind_type_test.cpp
@@ -0,0 +1,75 @@
#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.hpp>
#include <boost/detail/lightweight_test.hpp>

//

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();
}
207 changes: 207 additions & 0 deletions test/bind_unique_ptr_test.cpp
@@ -0,0 +1,207 @@
#include <boost/config.hpp>

#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_SMART_PTR )

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.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <memory>

//

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 // #if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_SMART_PTR )