Fix Boost.Function unit tests for C++0x. Fixes #3012

Based on a patch from Richard Webb. Changed a bit so that it also
works for the Visual C++ 10 beta.

[SVN r54618]
This commit is contained in:
Daniel James
2009-07-03 22:21:40 +00:00
parent e8247198fa
commit ae534d7342
3 changed files with 17 additions and 17 deletions

View File

@ -35,12 +35,12 @@ form to use for your compiler.
<row> <row>
<entry> <entry>
<itemizedlist spacing="compact"> <itemizedlist spacing="compact">
<listitem><simpara>GNU C++ since 2.95.x</simpara></listitem> <listitem><simpara>GNU C++ 2.95.x, 3.0.x and later verseions</simpara></listitem>
<listitem><simpara>Comeau C++ 4.2.45.2</simpara></listitem> <listitem><simpara>Comeau C++ 4.2.45.2</simpara></listitem>
<listitem><simpara>SGI MIPSpro 7.3.0</simpara></listitem> <listitem><simpara>SGI MIPSpro 7.3.0</simpara></listitem>
<listitem><simpara>Intel C++ 5.0, 6.0</simpara></listitem> <listitem><simpara>Intel C++ 5.0, 6.0</simpara></listitem>
<listitem><simpara>Compaq's cxx 6.2</simpara></listitem> <listitem><simpara>Compaq's cxx 6.2</simpara></listitem>
<listitem><simpara>Microsoft Visual C++ since 7.1</simpara></listitem> <listitem><simpara>Microsoft Visual C++ 7.1 and later versions</simpara></listitem>
</itemizedlist> </itemizedlist>
</entry> </entry>
<entry> <entry>

View File

@ -13,8 +13,8 @@
#include <string> #include <string>
#include <utility> #include <utility>
using namespace boost; using boost::function;
using namespace std; using std::string;
int global_int; int global_int;
@ -525,7 +525,7 @@ test_zero_args()
static void static void
test_one_arg() test_one_arg()
{ {
negate<int> neg; std::negate<int> neg;
function<int (int)> f1(neg); function<int (int)> f1(neg);
BOOST_CHECK(f1(5) == -5); BOOST_CHECK(f1(5) == -5);
@ -607,12 +607,12 @@ struct add_with_throw_on_copy {
add_with_throw_on_copy(const add_with_throw_on_copy&) add_with_throw_on_copy(const add_with_throw_on_copy&)
{ {
throw runtime_error("But this CAN'T throw"); throw std::runtime_error("But this CAN'T throw");
} }
add_with_throw_on_copy& operator=(const add_with_throw_on_copy&) add_with_throw_on_copy& operator=(const add_with_throw_on_copy&)
{ {
throw runtime_error("But this CAN'T throw"); throw std::runtime_error("But this CAN'T throw");
} }
}; };
@ -621,10 +621,10 @@ test_ref()
{ {
add_with_throw_on_copy atc; add_with_throw_on_copy atc;
try { try {
boost::function<int (int, int)> f(ref(atc)); boost::function<int (int, int)> f(boost::ref(atc));
BOOST_CHECK(f(1, 3) == 4); BOOST_CHECK(f(1, 3) == 4);
} }
catch(runtime_error e) { catch(std::runtime_error e) {
BOOST_ERROR("Nonthrowing constructor threw an exception"); BOOST_ERROR("Nonthrowing constructor threw an exception");
} }
} }
@ -640,14 +640,14 @@ static void test_empty_ref()
f2(); f2();
BOOST_ERROR("Exception didn't throw for reference to empty function."); BOOST_ERROR("Exception didn't throw for reference to empty function.");
} }
catch(runtime_error e) {} catch(std::runtime_error e) {}
f1 = dummy; f1 = dummy;
try { try {
f2(); f2();
} }
catch(runtime_error e) { catch(std::runtime_error e) {
BOOST_ERROR("Error calling referenced function."); BOOST_ERROR("Error calling referenced function.");
} }
} }

View File

@ -15,21 +15,21 @@
#include <boost/lambda/bind.hpp> #include <boost/lambda/bind.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
using namespace std;
using namespace boost;
using namespace boost::lambda;
static unsigned static unsigned
func_impl(int arg1, bool arg2, double arg3) func_impl(int arg1, bool arg2, double arg3)
{ {
using namespace std;
return abs (static_cast<int>((arg2 ? arg1 : 2 * arg1) * arg3)); return abs (static_cast<int>((arg2 ? arg1 : 2 * arg1) * arg3));
} }
int test_main(int, char*[]) int test_main(int, char*[])
{ {
using boost::function;
using namespace boost::lambda;
function <unsigned(bool, double)> f1 = bind(func_impl, 15, _1, _2); function <unsigned(bool, double)> f1 = bind(func_impl, 15, _1, _2);
function <unsigned(double)> f2 = bind(f1, false, _1); function <unsigned(double)> f2 = boost::lambda::bind(f1, false, _1);
function <unsigned()> f3 = bind(f2, 4.0); function <unsigned()> f3 = boost::lambda::bind(f2, 4.0);
f3(); f3();