forked from boostorg/bind
Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41370]
This commit is contained in:
@@ -341,7 +341,7 @@ void render(image & target)
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
<A href="../function/index.html" >boost::function</A><void> onClick;
|
<A href="../function/index.html" >boost::function</A><void()> onClick;
|
||||||
};
|
};
|
||||||
|
|
||||||
class player
|
class player
|
||||||
|
@@ -31,32 +31,18 @@
|
|||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// default implementation of visit_each
|
//
|
||||||
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
template<class V, class T> void visit_each(V & v, T const & t, long)
|
|
||||||
{
|
|
||||||
v(t, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// visitor
|
|
||||||
|
|
||||||
int hash = 0;
|
|
||||||
|
|
||||||
struct visitor
|
struct visitor
|
||||||
{
|
{
|
||||||
template<class T> void operator()(boost::reference_wrapper<T> const & r, int) const
|
template<class T> void operator()( boost::reference_wrapper<T> const & r ) const
|
||||||
{
|
{
|
||||||
std::cout << "Reference to " << typeid(T).name() << " @ " << &r.get() << " (with value " << r.get() << ")\n";
|
std::cout << "Reference to " << typeid(T).name() << " @ " << &r.get() << " (with value " << r.get() << ")\n";
|
||||||
hash += r.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T> void operator()(T const &, long) const
|
template<class T> void operator()( T const & t ) const
|
||||||
{
|
{
|
||||||
std::cout << "Value of type " << typeid(T).name() << '\n';
|
std::cout << "Value of type " << typeid(T).name() << " (with value " << t << ")\n";
|
||||||
++hash;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,26 +56,10 @@ int f(int & i, int & j, int)
|
|||||||
int x = 2;
|
int x = 2;
|
||||||
int y = 7;
|
int y = 7;
|
||||||
|
|
||||||
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()
|
int main()
|
||||||
{
|
{
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
|
||||||
visitor v;
|
visitor v;
|
||||||
visit_each(v, bind<int>(bind(f, ref(x), _1, 42), ref(y)), 0);
|
visit_each(v, bind<int>(bind(f, ref(x), _1, 42), ref(y)), 0);
|
||||||
|
|
||||||
return detect_errors(hash == 12);
|
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,8 @@ test-suite "bind"
|
|||||||
[ compile bind_unary_addr.cpp ]
|
[ compile bind_unary_addr.cpp ]
|
||||||
[ run bind_dm3_test.cpp ]
|
[ run bind_dm3_test.cpp ]
|
||||||
[ run bind_visit_test.cpp ]
|
[ run bind_visit_test.cpp ]
|
||||||
|
[ run bind_placeholder_test.cpp ]
|
||||||
|
[ run bind_rvalue_test.cpp ]
|
||||||
[ run mem_fn_test.cpp ]
|
[ run mem_fn_test.cpp ]
|
||||||
[ run mem_fn_void_test.cpp ]
|
[ run mem_fn_void_test.cpp ]
|
||||||
[ run mem_fn_derived_test.cpp ]
|
[ run mem_fn_derived_test.cpp ]
|
||||||
|
83
test/bind_placeholder_test.cpp
Normal file
83
test/bind_placeholder_test.cpp
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#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.hpp>
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||||
|
#pragma warning(push, 3)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
long 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();
|
||||||
|
}
|
81
test/bind_rvalue_test.cpp
Normal file
81
test/bind_rvalue_test.cpp
Normal 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
|
||||||
|
|
||||||
|
// 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.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>
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
Reference in New Issue
Block a user