mirror of
https://github.com/boostorg/function.git
synced 2025-06-30 14:31:08 +02:00
Compare commits
1 Commits
boost-1.33
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
f3250a605b |
@ -5,7 +5,7 @@
|
||||
<title>History & Compatibility Notes</title>
|
||||
|
||||
<itemizedlist spacing="compact">
|
||||
<listitem><para><bold>Version 1.30.0</bold>: </para>
|
||||
<listitem><para><emphasis role="bold">Version 1.30.0</emphasis>: </para>
|
||||
<itemizedlist spacing="compact">
|
||||
<listitem><para>All features deprecated in version 1.29.0 have
|
||||
been removed from Boost.Function.</para></listitem>
|
||||
@ -32,7 +32,7 @@
|
||||
</itemizedlist>
|
||||
</listitem>
|
||||
|
||||
<listitem><para><bold>Version 1.29.0</bold>:
|
||||
<listitem><para><emphasis role="bold">Version 1.29.0</emphasis>:
|
||||
Boost.Function has been partially redesigned to minimize the
|
||||
interface and make it cleaner. Several seldom- or never-used
|
||||
features of the older Boost.Function have been deprecated and will
|
||||
|
@ -297,7 +297,7 @@
|
||||
<parameter name="aN"><paramtype>argN_type</paramtype></parameter>
|
||||
<effects><simpara><code>f(a1, a2, ..., aN)</code>, where <code>f</code> is the target of <code>*this</code>.</simpara></effects>
|
||||
<returns><simpara>if <code>R</code> is <code>void</code>, nothing is returned; otherwise, the return value of the call to <code>f</code> is returned.</simpara></returns>
|
||||
<throws><simpara><code><classname>bad_function_call</classname></code> if <code>this-><methodname>empty</methodname>()</code>. Otherwise, may through any exception thrown by the target function <code>f</code>.</simpara></throws>
|
||||
<throws><simpara><code><classname>bad_function_call</classname></code> if <code>!this-><methodname>empty</methodname>()</code>. Otherwise, may through any exception thrown by the target function <code>f</code>.</simpara></throws>
|
||||
</method>
|
||||
</method-group>
|
||||
|
||||
@ -719,7 +719,7 @@
|
||||
<parameter name="aN"><paramtype>argN_type</paramtype></parameter>
|
||||
<effects><simpara><code>f(a1, a2, ..., aN)</code>, where <code>f</code> is the target of <code>*this</code>.</simpara></effects>
|
||||
<returns><simpara>if <code>R</code> is <code>void</code>, nothing is returned; otherwise, the return value of the call to <code>f</code> is returned.</simpara></returns>
|
||||
<throws><simpara><code><classname>bad_function_call</classname></code> if <code>this-><methodname>empty</methodname>()</code>. Otherwise, may through any exception thrown by the target function <code>f</code>.</simpara></throws>
|
||||
<throws><simpara><code><classname>bad_function_call</classname></code> if <code>!this-><methodname>empty</methodname>()</code>. Otherwise, may through any exception thrown by the target function <code>f</code>.</simpara></throws>
|
||||
</method>
|
||||
</method-group>
|
||||
|
||||
|
@ -329,8 +329,8 @@ exceptions during assignment or construction.
|
||||
or <code>!=</code> against any function object that can be stored
|
||||
within the wrapper. If the function object wrapper contains a
|
||||
function object of that type, it will be compared against the given
|
||||
function object (which must be either be
|
||||
<conceptname>EqualityComparable</conceptname> or have an overloaded <functionname>boost::function_equal</functionname>). For instance:</para>
|
||||
function object (which must be
|
||||
<conceptname>EqualityComparable</conceptname>). For instance:</para>
|
||||
|
||||
<programlisting name="function.tutorial.compare">int compute_with_X(X*, int);
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <boost/function/detail/prologue.hpp>
|
||||
|
||||
// Visual Age C++ doesn't handle the file iteration well
|
||||
#if BOOST_WORKAROUND(__IBMCPP__, >= 500)
|
||||
#if BOOST_WORKAROUND(__IBMCPP__, <= 600)
|
||||
# if BOOST_FUNCTION_MAX_ARGS >= 0
|
||||
# include <boost/function/function0.hpp>
|
||||
# endif
|
||||
|
@ -63,19 +63,11 @@ namespace boost { namespace python { namespace objects {
|
||||
# define BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX
|
||||
#endif
|
||||
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
|
||||
# define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \
|
||||
typename ::boost::enable_if_c<(::boost::type_traits::ice_not< \
|
||||
(::boost::is_integral<Functor>::value)>::value), \
|
||||
Type>::type
|
||||
#else
|
||||
// BCC doesn't recognize this depends on a template argument and complains
|
||||
// about the use of 'typename'
|
||||
# define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \
|
||||
::boost::enable_if_c<(::boost::type_traits::ice_not< \
|
||||
(::boost::is_integral<Functor>::value)>::value), \
|
||||
#define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \
|
||||
typename ::boost::enable_if_c<(::boost::type_traits::ice_not< \
|
||||
(::boost::is_integral<Functor>::value)>::value), \
|
||||
Type>::type
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX)
|
||||
namespace boost {
|
||||
@ -422,12 +414,7 @@ public:
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
const Functor* target( Functor * = 0 ) const
|
||||
#else
|
||||
const Functor* target() const
|
||||
#endif
|
||||
{
|
||||
if (!manager) return 0;
|
||||
|
||||
@ -437,23 +424,14 @@ public:
|
||||
if (!result.obj_ptr) return 0;
|
||||
else {
|
||||
typedef typename detail::function::get_function_tag<Functor>::type tag;
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
return get_functor_pointer(tag(), 0, (Functor*)0);
|
||||
#else
|
||||
return get_functor_pointer<Functor>(tag(), 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
bool contains(const F& f) const
|
||||
{
|
||||
#if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
if (const F* fp = this->target( (F*)0 )) {
|
||||
#else
|
||||
if (const F* fp = this->template target<F>()) {
|
||||
#endif
|
||||
return function_equal(*fp, f);
|
||||
} else {
|
||||
return false;
|
||||
@ -491,36 +469,20 @@ public: // should be protected, but GCC 2.95.3 will fail to allow access
|
||||
|
||||
private:
|
||||
template<typename Functor>
|
||||
#if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
Functor* get_functor_pointer(detail::function::function_ptr_tag, int, Functor * = 0)
|
||||
#else
|
||||
Functor* get_functor_pointer(detail::function::function_ptr_tag, int)
|
||||
#endif
|
||||
{ return reinterpret_cast<Functor*>(&functor.func_ptr); }
|
||||
|
||||
template<typename Functor, typename Tag>
|
||||
#if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
Functor* get_functor_pointer(Tag, long, Functor * = 0)
|
||||
#else
|
||||
Functor* get_functor_pointer(Tag, long)
|
||||
#endif
|
||||
{ return static_cast<Functor*>(functor.obj_ptr); }
|
||||
|
||||
template<typename Functor>
|
||||
const Functor*
|
||||
#if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
get_functor_pointer(detail::function::function_ptr_tag, int, Functor * = 0) const
|
||||
#else
|
||||
get_functor_pointer(detail::function::function_ptr_tag, int) const
|
||||
#endif
|
||||
{ return reinterpret_cast<const Functor*>(&functor.func_ptr); }
|
||||
|
||||
template<typename Functor, typename Tag>
|
||||
#if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
const Functor* get_functor_pointer(Tag, long, Functor * = 0) const
|
||||
#else
|
||||
const Functor* get_functor_pointer(Tag, long) const
|
||||
#endif
|
||||
{ return static_cast<const Functor*>(functor.const_obj_ptr); }
|
||||
};
|
||||
|
||||
|
@ -61,14 +61,6 @@
|
||||
#define BOOST_FUNCTION_GET_STATELESS_FUNCTION_OBJ_INVOKER \
|
||||
BOOST_JOIN(get_stateless_function_obj_invoker,BOOST_FUNCTION_NUM_ARGS)
|
||||
|
||||
#ifndef BOOST_NO_VOID_RETURNS
|
||||
# define BOOST_FUNCTION_VOID_RETURN_TYPE void
|
||||
# define BOOST_FUNCTION_RETURN(X) X
|
||||
#else
|
||||
# define BOOST_FUNCTION_VOID_RETURN_TYPE ::boost::detail::function::unusable
|
||||
# define BOOST_FUNCTION_RETURN(X) X; return BOOST_FUNCTION_VOID_RETURN_TYPE ()
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
namespace function {
|
||||
@ -94,13 +86,13 @@ namespace boost {
|
||||
>
|
||||
struct BOOST_FUNCTION_VOID_FUNCTION_INVOKER
|
||||
{
|
||||
static BOOST_FUNCTION_VOID_RETURN_TYPE
|
||||
invoke(any_pointer function_ptr BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_PARMS)
|
||||
static unusable invoke(any_pointer function_ptr BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.func_ptr);
|
||||
BOOST_FUNCTION_RETURN(f(BOOST_FUNCTION_ARGS));
|
||||
f(BOOST_FUNCTION_ARGS);
|
||||
return unusable();
|
||||
}
|
||||
};
|
||||
|
||||
@ -127,13 +119,14 @@ namespace boost {
|
||||
>
|
||||
struct BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER
|
||||
{
|
||||
static BOOST_FUNCTION_VOID_RETURN_TYPE
|
||||
invoke(any_pointer function_obj_ptr BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_PARMS)
|
||||
static unusable invoke(any_pointer function_obj_ptr
|
||||
BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
FunctionObj* f = (FunctionObj*)(function_obj_ptr.obj_ptr);
|
||||
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
|
||||
(*f)(BOOST_FUNCTION_ARGS);
|
||||
return unusable();
|
||||
}
|
||||
};
|
||||
|
||||
@ -158,12 +151,13 @@ namespace boost {
|
||||
>
|
||||
struct BOOST_FUNCTION_STATELESS_VOID_FUNCTION_OBJ_INVOKER
|
||||
{
|
||||
static BOOST_FUNCTION_VOID_RETURN_TYPE
|
||||
invoke(any_pointer BOOST_FUNCTION_COMMA BOOST_FUNCTION_PARMS)
|
||||
static unusable invoke(any_pointer BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
FunctionObj f = FunctionObj();
|
||||
BOOST_FUNCTION_RETURN(f(BOOST_FUNCTION_ARGS));
|
||||
f(BOOST_FUNCTION_ARGS);
|
||||
return unusable();
|
||||
}
|
||||
};
|
||||
|
||||
@ -241,12 +235,8 @@ namespace boost {
|
||||
class BOOST_FUNCTION_FUNCTION : public function_base
|
||||
{
|
||||
public:
|
||||
#ifndef BOOST_NO_VOID_RETURNS
|
||||
typedef R result_type;
|
||||
#else
|
||||
typedef typename detail::function::function_return_type<R>::type
|
||||
result_type;
|
||||
#endif // BOOST_NO_VOID_RETURNS
|
||||
typedef typename detail::function::function_return_type<R>::type
|
||||
internal_result_type;
|
||||
|
||||
private:
|
||||
struct clear_type {};
|
||||
@ -258,7 +248,7 @@ namespace boost {
|
||||
template<typename Args>
|
||||
struct sig
|
||||
{
|
||||
typedef result_type type;
|
||||
typedef internal_result_type type;
|
||||
};
|
||||
|
||||
#if BOOST_FUNCTION_NUM_ARGS == 1
|
||||
@ -271,6 +261,11 @@ namespace boost {
|
||||
BOOST_STATIC_CONSTANT(int, arity = BOOST_FUNCTION_NUM_ARGS);
|
||||
BOOST_FUNCTION_ARG_TYPES
|
||||
|
||||
#ifndef BOOST_NO_VOID_RETURNS
|
||||
typedef R result_type;
|
||||
#else
|
||||
typedef internal_result_type result_type;
|
||||
#endif // BOOST_NO_VOID_RETURNS
|
||||
typedef Allocator allocator_type;
|
||||
typedef BOOST_FUNCTION_FUNCTION self_type;
|
||||
|
||||
@ -320,7 +315,15 @@ namespace boost {
|
||||
if (this->empty())
|
||||
boost::throw_exception(bad_function_call());
|
||||
|
||||
return invoker(this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
|
||||
internal_result_type result = invoker(this->functor
|
||||
BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_ARGS);
|
||||
|
||||
#ifndef BOOST_NO_VOID_RETURNS
|
||||
return static_cast<result_type>(result);
|
||||
#else
|
||||
return result;
|
||||
#endif // BOOST_NO_VOID_RETURNS
|
||||
}
|
||||
#else
|
||||
result_type operator()(BOOST_FUNCTION_PARMS) const;
|
||||
@ -467,7 +470,7 @@ namespace boost {
|
||||
template<typename FunctionObj>
|
||||
void assign_to(FunctionObj f, detail::function::function_obj_tag)
|
||||
{
|
||||
if (!detail::function::has_empty_target(boost::addressof(f))) {
|
||||
if (!detail::function::has_empty_target(addressof(f))) {
|
||||
typedef
|
||||
typename detail::function::BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER<
|
||||
FunctionObj,
|
||||
@ -536,9 +539,9 @@ namespace boost {
|
||||
this->functor = detail::function::make_any_pointer(this);
|
||||
}
|
||||
|
||||
typedef result_type (*invoker_type)(detail::function::any_pointer
|
||||
BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS);
|
||||
typedef internal_result_type (*invoker_type)(detail::function::any_pointer
|
||||
BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS);
|
||||
|
||||
invoker_type invoker;
|
||||
};
|
||||
@ -570,11 +573,19 @@ namespace boost {
|
||||
Allocator>
|
||||
::operator()(BOOST_FUNCTION_PARMS) const
|
||||
{
|
||||
if (this->empty())
|
||||
boost::throw_exception(bad_function_call());
|
||||
|
||||
return invoker(this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
if (this->empty())
|
||||
boost::throw_exception(bad_function_call());
|
||||
|
||||
internal_result_type result = invoker(this->functor
|
||||
BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_ARGS);
|
||||
|
||||
# ifndef BOOST_NO_VOID_RETURNS
|
||||
return static_cast<result_type>(result);
|
||||
# else
|
||||
return result;
|
||||
# endif // BOOST_NO_VOID_RETURNS
|
||||
}
|
||||
#endif
|
||||
|
||||
// Poison comparisons between boost::function objects of the same type.
|
||||
@ -708,5 +719,3 @@ public:
|
||||
#undef BOOST_FUNCTION_ARGS
|
||||
#undef BOOST_FUNCTION_ARG_TYPE
|
||||
#undef BOOST_FUNCTION_ARG_TYPES
|
||||
#undef BOOST_FUNCTION_VOID_RETURN_TYPE
|
||||
#undef BOOST_FUNCTION_RETURN
|
||||
|
@ -1,9 +1,6 @@
|
||||
// Copyright Douglas Gregor 2004.
|
||||
// Copyright 2005 Peter Dimov
|
||||
|
||||
// Use, modification and distribution is subject to
|
||||
// the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// Copyright Douglas Gregor 2004. Use, modification and
|
||||
// distribution is 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)
|
||||
|
||||
// For more information, see http://www.boost.org
|
||||
@ -12,16 +9,15 @@
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<typename F, typename G>
|
||||
bool function_equal_impl(const F& f, const G& g, long)
|
||||
{ return f == g; }
|
||||
|
||||
// function_equal_impl needs to be unqualified to pick
|
||||
// user overloads on two-phase compilers
|
||||
namespace detail {
|
||||
template<typename F, typename G>
|
||||
bool function_equal_impl(const F& f, const G& g, long)
|
||||
{ return f == g; }
|
||||
} // end namespace boost::function
|
||||
|
||||
template<typename F, typename G>
|
||||
bool function_equal(const F& f, const G& g)
|
||||
{ return function_equal_impl(f, g, 0); }
|
||||
{ return ::boost::detail::function_equal_impl(f, g, 0); }
|
||||
|
||||
} // end namespace boost
|
||||
|
||||
|
@ -62,7 +62,6 @@ DEPENDS all : test ;
|
||||
[ run libs/function/test/function_ref_portable.cpp : : : : ]
|
||||
|
||||
[ run libs/function/test/contains_test.cpp : : : : ]
|
||||
|
||||
[ run libs/function/test/contains2_test.cpp : : : : ]
|
||||
;
|
||||
}
|
||||
|
@ -56,8 +56,6 @@ import testing ;
|
||||
|
||||
[ run libs/function/test/contains_test.cpp : : : : ]
|
||||
|
||||
[ run libs/function/test/contains2_test.cpp : : : : ]
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -41,20 +41,11 @@ struct counting_allocator : public std::allocator<T>
|
||||
}
|
||||
};
|
||||
|
||||
struct plus_int
|
||||
{
|
||||
int operator()(int x, int y) const { return x + y; }
|
||||
|
||||
int unused_state_data;
|
||||
};
|
||||
|
||||
static int do_minus(int x, int y) { return x-y; }
|
||||
|
||||
struct DoNothing
|
||||
{
|
||||
void operator()() const {}
|
||||
|
||||
int unused_state_data;
|
||||
};
|
||||
|
||||
static void do_nothing() {}
|
||||
@ -63,32 +54,28 @@ int
|
||||
test_main(int, char*[])
|
||||
{
|
||||
function2<int, int, int, counting_allocator<int> > f;
|
||||
f = plus_int();
|
||||
f = plus<int>();
|
||||
f.clear();
|
||||
BOOST_CHECK(alloc_count == 1);
|
||||
BOOST_CHECK(dealloc_count == 1);
|
||||
BOOST_TEST(alloc_count == 1);
|
||||
BOOST_TEST(dealloc_count == 1);
|
||||
|
||||
alloc_count = 0;
|
||||
dealloc_count = 0;
|
||||
f = &do_minus;
|
||||
f.clear();
|
||||
BOOST_CHECK(alloc_count == 0);
|
||||
BOOST_CHECK(dealloc_count == 0);
|
||||
|
||||
function0<void, counting_allocator<int> > fv;
|
||||
alloc_count = 0;
|
||||
dealloc_count = 0;
|
||||
fv = DoNothing();
|
||||
fv.clear();
|
||||
BOOST_CHECK(alloc_count == 1);
|
||||
BOOST_CHECK(dealloc_count == 1);
|
||||
BOOST_TEST(alloc_count == 1);
|
||||
BOOST_TEST(dealloc_count == 1);
|
||||
|
||||
alloc_count = 0;
|
||||
dealloc_count = 0;
|
||||
fv = &do_nothing;
|
||||
fv.clear();
|
||||
BOOST_CHECK(alloc_count == 0);
|
||||
BOOST_CHECK(dealloc_count == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,88 +0,0 @@
|
||||
// Boost.Function library
|
||||
|
||||
// Copyright Douglas Gregor 2004.
|
||||
// Copyright 2005 Peter Dimov
|
||||
|
||||
// Use, modification and distribution is 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/function.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
static int forty_two()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
struct Seventeen
|
||||
{
|
||||
int operator()() const
|
||||
{
|
||||
return 17;
|
||||
}
|
||||
};
|
||||
|
||||
bool operator==(const Seventeen&, const Seventeen&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
struct ReturnInt
|
||||
{
|
||||
explicit ReturnInt(int value) : value(value)
|
||||
{
|
||||
}
|
||||
|
||||
int operator()() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
int value;
|
||||
};
|
||||
|
||||
bool operator==(const ReturnInt& x, const ReturnInt& y)
|
||||
{
|
||||
return x.value == y.value;
|
||||
}
|
||||
|
||||
bool operator!=(const ReturnInt& x, const ReturnInt& y)
|
||||
{
|
||||
return x.value != y.value;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::function0<int> fn;
|
||||
|
||||
fn = &forty_two;
|
||||
|
||||
BOOST_TEST( fn() == 42 );
|
||||
|
||||
BOOST_TEST( fn.contains(&forty_two) );
|
||||
BOOST_TEST( !fn.contains( Seventeen() ) );
|
||||
BOOST_TEST( !fn.contains( ReturnInt(0) ) );
|
||||
BOOST_TEST( !fn.contains( ReturnInt(12) ) );
|
||||
|
||||
fn = Seventeen();
|
||||
|
||||
BOOST_TEST( fn() == 17 );
|
||||
|
||||
BOOST_TEST( !fn.contains( &forty_two ) );
|
||||
BOOST_TEST( fn.contains( Seventeen() ) );
|
||||
BOOST_TEST( !fn.contains( ReturnInt(0) ) );
|
||||
BOOST_TEST( !fn.contains( ReturnInt(12) ) );
|
||||
|
||||
fn = ReturnInt(12);
|
||||
|
||||
BOOST_TEST( fn() == 12 );
|
||||
|
||||
BOOST_TEST( !fn.contains( &forty_two ) );
|
||||
BOOST_TEST( !fn.contains( Seventeen() ) );
|
||||
BOOST_TEST( !fn.contains( ReturnInt(0) ) );
|
||||
BOOST_TEST( fn.contains( ReturnInt(12) ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -31,63 +31,23 @@ bool operator==(const ReturnInt& x, const ReturnInt& y)
|
||||
bool operator!=(const ReturnInt& x, const ReturnInt& y)
|
||||
{ return x.value != y.value; }
|
||||
|
||||
namespace contain_test {
|
||||
|
||||
struct ReturnIntFE
|
||||
{
|
||||
explicit ReturnIntFE(int value) : value(value) {}
|
||||
|
||||
int operator()() const { return value; }
|
||||
|
||||
int value;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
|
||||
|
||||
namespace contain_test {
|
||||
# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
bool function_equal(const ReturnIntFE& x, const ReturnIntFE& y)
|
||||
{ return x.value == y.value; }
|
||||
# else
|
||||
bool function_equal_impl(const ReturnIntFE& x, const ReturnIntFE& y, int)
|
||||
{ return x.value == y.value; }
|
||||
# endif // #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
}
|
||||
#else // BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
|
||||
namespace boost {
|
||||
# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
bool
|
||||
function_equal(const contain_test::ReturnIntFE& x,
|
||||
const contain_test::ReturnIntFE& y)
|
||||
{ return x.value == y.value; }
|
||||
# else
|
||||
bool
|
||||
function_equal_impl(const contain_test::ReturnIntFE& x,
|
||||
const contain_test::ReturnIntFE& y, int)
|
||||
{ return x.value == y.value; }
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void target_test()
|
||||
{
|
||||
boost::function0<int> f;
|
||||
|
||||
f = &forty_two;
|
||||
BOOST_CHECK(*f.target<int (*)()>() == &forty_two);
|
||||
BOOST_CHECK(!f.target<Seventeen>());
|
||||
BOOST_TEST(*f.target<int (*)()>() == &forty_two);
|
||||
BOOST_TEST(!f.target<Seventeen>());
|
||||
|
||||
f = Seventeen();
|
||||
BOOST_CHECK(!f.target<int (*)()>());
|
||||
BOOST_CHECK(f.target<Seventeen>());
|
||||
BOOST_TEST(!f.target<int (*)()>());
|
||||
BOOST_TEST(f.target<Seventeen>());
|
||||
|
||||
Seventeen this_seventeen;
|
||||
f = boost::ref(this_seventeen);
|
||||
BOOST_CHECK(!f.target<int (*)()>());
|
||||
BOOST_CHECK(f.target<Seventeen>());
|
||||
BOOST_CHECK(f.target<Seventeen>() == &this_seventeen);
|
||||
BOOST_TEST(!f.target<int (*)()>());
|
||||
BOOST_TEST(f.target<Seventeen>());
|
||||
BOOST_TEST(f.target<Seventeen>() == &this_seventeen);
|
||||
}
|
||||
|
||||
static void equal_test()
|
||||
@ -95,58 +55,46 @@ static void equal_test()
|
||||
boost::function0<int> f;
|
||||
|
||||
f = &forty_two;
|
||||
BOOST_CHECK(f == &forty_two);
|
||||
BOOST_CHECK(f != ReturnInt(17));
|
||||
BOOST_TEST(f == &forty_two);
|
||||
BOOST_TEST(f != ReturnInt(17));
|
||||
#if !(defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ <= 3)
|
||||
BOOST_CHECK(&forty_two == f);
|
||||
BOOST_CHECK(ReturnInt(17) != f);
|
||||
BOOST_TEST(&forty_two == f);
|
||||
BOOST_TEST(ReturnInt(17) != f);
|
||||
#endif
|
||||
|
||||
BOOST_CHECK(f.contains(&forty_two));
|
||||
BOOST_TEST(f.contains(&forty_two));
|
||||
|
||||
f = ReturnInt(17);
|
||||
BOOST_CHECK(f != &forty_two);
|
||||
BOOST_CHECK(f == ReturnInt(17));
|
||||
BOOST_CHECK(f != ReturnInt(16));
|
||||
BOOST_TEST(f != &forty_two);
|
||||
BOOST_TEST(f == ReturnInt(17));
|
||||
BOOST_TEST(f != ReturnInt(16));
|
||||
#if !(defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ <= 3)
|
||||
BOOST_CHECK(&forty_two != f);
|
||||
BOOST_CHECK(ReturnInt(17) == f);
|
||||
BOOST_CHECK(ReturnInt(16) != f);
|
||||
BOOST_TEST(&forty_two != f);
|
||||
BOOST_TEST(ReturnInt(17) == f);
|
||||
BOOST_TEST(ReturnInt(16) != f);
|
||||
#endif
|
||||
|
||||
BOOST_CHECK(f.contains(ReturnInt(17)));
|
||||
|
||||
f = contain_test::ReturnIntFE(17);
|
||||
BOOST_CHECK(f != &forty_two);
|
||||
BOOST_CHECK(f == contain_test::ReturnIntFE(17));
|
||||
BOOST_CHECK(f != contain_test::ReturnIntFE(16));
|
||||
#if !(defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ <= 3)
|
||||
BOOST_CHECK(&forty_two != f);
|
||||
BOOST_CHECK(contain_test::ReturnIntFE(17) == f);
|
||||
BOOST_CHECK(contain_test::ReturnIntFE(16) != f);
|
||||
#endif
|
||||
|
||||
BOOST_CHECK(f.contains(contain_test::ReturnIntFE(17)));
|
||||
BOOST_TEST(f.contains(ReturnInt(17)));
|
||||
|
||||
#if !defined(BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX)
|
||||
boost::function<int(void)> g;
|
||||
|
||||
g = &forty_two;
|
||||
BOOST_CHECK(g == &forty_two);
|
||||
BOOST_CHECK(g != ReturnInt(17));
|
||||
BOOST_TEST(g == &forty_two);
|
||||
BOOST_TEST(g != ReturnInt(17));
|
||||
# if !(defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ <= 3)
|
||||
BOOST_CHECK(&forty_two == g);
|
||||
BOOST_CHECK(ReturnInt(17) != g);
|
||||
BOOST_TEST(&forty_two == g);
|
||||
BOOST_TEST(ReturnInt(17) != g);
|
||||
# endif
|
||||
|
||||
g = ReturnInt(17);
|
||||
BOOST_CHECK(g != &forty_two);
|
||||
BOOST_CHECK(g == ReturnInt(17));
|
||||
BOOST_CHECK(g != ReturnInt(16));
|
||||
BOOST_TEST(g != &forty_two);
|
||||
BOOST_TEST(g == ReturnInt(17));
|
||||
BOOST_TEST(g != ReturnInt(16));
|
||||
# if !(defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ <= 3)
|
||||
BOOST_CHECK(&forty_two != g);
|
||||
BOOST_CHECK(ReturnInt(17) == g);
|
||||
BOOST_CHECK(ReturnInt(16) != g);
|
||||
BOOST_TEST(&forty_two != g);
|
||||
BOOST_TEST(ReturnInt(17) == g);
|
||||
BOOST_TEST(ReturnInt(16) != g);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
@ -158,28 +106,28 @@ static void ref_equal_test()
|
||||
boost::function0<int> f = boost::ref(ri);
|
||||
|
||||
// References and values are equal
|
||||
BOOST_CHECK(f == boost::ref(ri));
|
||||
BOOST_CHECK(f == ri);
|
||||
BOOST_CHECK(boost::ref(ri) == f);
|
||||
BOOST_CHECK(!(f != boost::ref(ri)));
|
||||
BOOST_CHECK(!(f != ri));
|
||||
BOOST_CHECK(!(boost::ref(ri) != f));
|
||||
BOOST_TEST(f == boost::ref(ri));
|
||||
BOOST_TEST(f == ri);
|
||||
BOOST_TEST(boost::ref(ri) == f);
|
||||
BOOST_TEST(!(f != boost::ref(ri)));
|
||||
BOOST_TEST(!(f != ri));
|
||||
BOOST_TEST(!(boost::ref(ri) != f));
|
||||
#if !(defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ <= 3)
|
||||
BOOST_CHECK(ri == f);
|
||||
BOOST_CHECK(!(ri != f));
|
||||
BOOST_TEST(ri == f);
|
||||
BOOST_TEST(!(ri != f));
|
||||
#endif
|
||||
|
||||
// Values equal, references inequal
|
||||
ReturnInt ri2(17);
|
||||
BOOST_CHECK(f == ri2);
|
||||
BOOST_CHECK(f != boost::ref(ri2));
|
||||
BOOST_CHECK(boost::ref(ri2) != f);
|
||||
BOOST_CHECK(!(f != ri2));
|
||||
BOOST_CHECK(!(f == boost::ref(ri2)));
|
||||
BOOST_CHECK(!(boost::ref(ri2) == f));
|
||||
BOOST_TEST(f == ri2);
|
||||
BOOST_TEST(f != boost::ref(ri2));
|
||||
BOOST_TEST(boost::ref(ri2) != f);
|
||||
BOOST_TEST(!(f != ri2));
|
||||
BOOST_TEST(!(f == boost::ref(ri2)));
|
||||
BOOST_TEST(!(boost::ref(ri2) == f));
|
||||
#if !(defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ <= 3)
|
||||
BOOST_CHECK(ri2 == f);
|
||||
BOOST_CHECK(!(ri2 != f));
|
||||
BOOST_TEST(ri2 == f);
|
||||
BOOST_TEST(!(ri2 != f));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -189,28 +137,28 @@ static void ref_equal_test()
|
||||
boost::function<int(void)> f = boost::ref(ri);
|
||||
|
||||
// References and values are equal
|
||||
BOOST_CHECK(f == boost::ref(ri));
|
||||
BOOST_CHECK(f == ri);
|
||||
BOOST_CHECK(boost::ref(ri) == f);
|
||||
BOOST_CHECK(!(f != boost::ref(ri)));
|
||||
BOOST_CHECK(!(f != ri));
|
||||
BOOST_CHECK(!(boost::ref(ri) != f));
|
||||
BOOST_TEST(f == boost::ref(ri));
|
||||
BOOST_TEST(f == ri);
|
||||
BOOST_TEST(boost::ref(ri) == f);
|
||||
BOOST_TEST(!(f != boost::ref(ri)));
|
||||
BOOST_TEST(!(f != ri));
|
||||
BOOST_TEST(!(boost::ref(ri) != f));
|
||||
# if !(defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ <= 3)
|
||||
BOOST_CHECK(ri == f);
|
||||
BOOST_CHECK(!(ri != f));
|
||||
BOOST_TEST(ri == f);
|
||||
BOOST_TEST(!(ri != f));
|
||||
# endif
|
||||
|
||||
// Values equal, references inequal
|
||||
ReturnInt ri2(17);
|
||||
BOOST_CHECK(f == ri2);
|
||||
BOOST_CHECK(f != boost::ref(ri2));
|
||||
BOOST_CHECK(boost::ref(ri2) != f);
|
||||
BOOST_CHECK(!(f != ri2));
|
||||
BOOST_CHECK(!(f == boost::ref(ri2)));
|
||||
BOOST_CHECK(!(boost::ref(ri2) == f));
|
||||
BOOST_TEST(f == ri2);
|
||||
BOOST_TEST(f != boost::ref(ri2));
|
||||
BOOST_TEST(boost::ref(ri2) != f);
|
||||
BOOST_TEST(!(f != ri2));
|
||||
BOOST_TEST(!(f == boost::ref(ri2)));
|
||||
BOOST_TEST(!(boost::ref(ri2) == f));
|
||||
# if !(defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ <= 3)
|
||||
BOOST_CHECK(ri2 == f);
|
||||
BOOST_CHECK(!(ri2 != f));
|
||||
BOOST_TEST(ri2 == f);
|
||||
BOOST_TEST(!(ri2 != f));
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
@ -56,30 +56,30 @@ test_zero_args()
|
||||
|
||||
// Default construction
|
||||
func_void_type v1;
|
||||
BOOST_CHECK(v1.empty());
|
||||
BOOST_TEST(v1.empty());
|
||||
|
||||
// Assignment to an empty function
|
||||
v1 = five;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation of a function
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear() method
|
||||
v1.clear();
|
||||
BOOST_CHECK(!v1);
|
||||
BOOST_TEST(!v1);
|
||||
|
||||
// Assignment to an empty function
|
||||
v1 = three;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation and self-assignment
|
||||
global_int = 0;
|
||||
v1 = v1;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v1 = five;
|
||||
@ -88,61 +88,61 @@ test_zero_args()
|
||||
global_int = 0;
|
||||
v1 = (v1);
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear
|
||||
v1 = 0;
|
||||
BOOST_CHECK(v1.empty());
|
||||
BOOST_TEST(v1.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v1 = &write_five;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v1 = &write_three;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment
|
||||
v1 = five;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v1 = write_three;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Construction from another function (that is empty)
|
||||
v1.clear();
|
||||
func_void_type v2(v1);
|
||||
BOOST_CHECK(!v2? true : false);
|
||||
BOOST_TEST(!v2? true : false);
|
||||
|
||||
// Assignment to an empty function
|
||||
v2 = three;
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v2 = (five);
|
||||
@ -150,86 +150,86 @@ test_zero_args()
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
v2.clear();
|
||||
BOOST_CHECK(v2.empty());
|
||||
BOOST_TEST(v2.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v2 = (&write_five);
|
||||
BOOST_CHECK(v2? true : false);
|
||||
BOOST_TEST(v2? true : false);
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v2 = &write_three;
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Swapping
|
||||
v1 = five;
|
||||
swap(v1, v2);
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
swap(v1, v2);
|
||||
v1.clear();
|
||||
|
||||
// Assignment
|
||||
v2 = five;
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v2 = &write_three;
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a function from an empty function
|
||||
v2 = v1;
|
||||
BOOST_CHECK(v2.empty());
|
||||
BOOST_TEST(v2.empty());
|
||||
|
||||
// Assignment to a function from a function with a functor
|
||||
v1 = three;
|
||||
v2 = v1;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assign to a function from a function with a function
|
||||
v2 = &write_five;
|
||||
v1 = v2;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Construct a function given another function containing a function
|
||||
func_void_type v3(v1);
|
||||
@ -237,20 +237,20 @@ test_zero_args()
|
||||
// Invocation of a function
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear() method
|
||||
v3.clear();
|
||||
BOOST_CHECK(!v3? true : false);
|
||||
BOOST_TEST(!v3? true : false);
|
||||
|
||||
// Assignment to an empty function
|
||||
v3 = three;
|
||||
BOOST_CHECK(!v3.empty());
|
||||
BOOST_TEST(!v3.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v3 = five;
|
||||
@ -258,38 +258,38 @@ test_zero_args()
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear()
|
||||
v3.clear();
|
||||
BOOST_CHECK(v3.empty());
|
||||
BOOST_TEST(v3.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v3 = &write_five;
|
||||
BOOST_CHECK(!v3.empty());
|
||||
BOOST_TEST(!v3.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v3 = &write_three;
|
||||
BOOST_CHECK(!v3.empty());
|
||||
BOOST_TEST(!v3.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment
|
||||
v3 = five;
|
||||
BOOST_CHECK(!v3.empty());
|
||||
BOOST_TEST(!v3.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Construction of a function from a function containing a functor
|
||||
func_void_type v4(v3);
|
||||
@ -297,20 +297,20 @@ test_zero_args()
|
||||
// Invocation of a function
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear() method
|
||||
v4.clear();
|
||||
BOOST_CHECK(v4.empty());
|
||||
BOOST_TEST(v4.empty());
|
||||
|
||||
// Assignment to an empty function
|
||||
v4 = three;
|
||||
BOOST_CHECK(!v4.empty());
|
||||
BOOST_TEST(!v4.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v4 = five;
|
||||
@ -318,38 +318,38 @@ test_zero_args()
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear()
|
||||
v4.clear();
|
||||
BOOST_CHECK(v4.empty());
|
||||
BOOST_TEST(v4.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v4 = &write_five;
|
||||
BOOST_CHECK(!v4.empty());
|
||||
BOOST_TEST(!v4.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v4 = &write_three;
|
||||
BOOST_CHECK(!v4.empty());
|
||||
BOOST_TEST(!v4.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment
|
||||
v4 = five;
|
||||
BOOST_CHECK(!v4.empty());
|
||||
BOOST_TEST(!v4.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Construction of a function from a functor
|
||||
func_void_type v5(five);
|
||||
@ -357,20 +357,20 @@ test_zero_args()
|
||||
// Invocation of a function
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear() method
|
||||
v5.clear();
|
||||
BOOST_CHECK(v5.empty());
|
||||
BOOST_TEST(v5.empty());
|
||||
|
||||
// Assignment to an empty function
|
||||
v5 = three;
|
||||
BOOST_CHECK(!v5.empty());
|
||||
BOOST_TEST(!v5.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v5 = five;
|
||||
@ -378,38 +378,38 @@ test_zero_args()
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear()
|
||||
v5.clear();
|
||||
BOOST_CHECK(v5.empty());
|
||||
BOOST_TEST(v5.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v5 = &write_five;
|
||||
BOOST_CHECK(!v5.empty());
|
||||
BOOST_TEST(!v5.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v5 = &write_three;
|
||||
BOOST_CHECK(!v5.empty());
|
||||
BOOST_TEST(!v5.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment
|
||||
v5 = five;
|
||||
BOOST_CHECK(!v5.empty());
|
||||
BOOST_TEST(!v5.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Construction of a function from a function
|
||||
func_void_type v6(&write_five);
|
||||
@ -417,20 +417,20 @@ test_zero_args()
|
||||
// Invocation of a function
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear() method
|
||||
v6.clear();
|
||||
BOOST_CHECK(v6.empty());
|
||||
BOOST_TEST(v6.empty());
|
||||
|
||||
// Assignment to an empty function
|
||||
v6 = three;
|
||||
BOOST_CHECK(!v6.empty());
|
||||
BOOST_TEST(!v6.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v6 = five;
|
||||
@ -438,38 +438,38 @@ test_zero_args()
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear()
|
||||
v6.clear();
|
||||
BOOST_CHECK(v6.empty());
|
||||
BOOST_TEST(v6.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v6 = &write_five;
|
||||
BOOST_CHECK(!v6.empty());
|
||||
BOOST_TEST(!v6.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v6 = &write_three;
|
||||
BOOST_CHECK(!v6.empty());
|
||||
BOOST_TEST(!v6.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment
|
||||
v6 = five;
|
||||
BOOST_CHECK(!v6.empty());
|
||||
BOOST_TEST(!v6.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Const vs. non-const
|
||||
// Initialization for Borland C++ 5.5
|
||||
@ -479,19 +479,19 @@ test_zero_args()
|
||||
|
||||
global_int = 0;
|
||||
v7();
|
||||
BOOST_CHECK(global_int == 2);
|
||||
BOOST_TEST(global_int == 2);
|
||||
|
||||
global_int = 0;
|
||||
v8();
|
||||
BOOST_CHECK(global_int == 2);
|
||||
BOOST_TEST(global_int == 2);
|
||||
|
||||
// Test construction from 0 and comparison to 0
|
||||
func_void_type v9(0);
|
||||
BOOST_CHECK(v9 == 0);
|
||||
BOOST_TEST(v9 == 0);
|
||||
# if !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x540 || defined(BOOST_STRICT_CONFIG)
|
||||
BOOST_CHECK(0 == v9);
|
||||
BOOST_TEST(0 == v9);
|
||||
#else
|
||||
BOOST_CHECK(v9.empty());
|
||||
BOOST_TEST(v9.empty());
|
||||
#endif
|
||||
|
||||
// Test return values
|
||||
@ -501,31 +501,31 @@ test_zero_args()
|
||||
generate_three_obj gen_three = generate_three_obj();
|
||||
func_int_type i0(gen_five);
|
||||
|
||||
BOOST_CHECK(i0() == 5);
|
||||
BOOST_TEST(i0() == 5);
|
||||
i0 = gen_three;
|
||||
BOOST_CHECK(i0() == 3);
|
||||
BOOST_TEST(i0() == 3);
|
||||
i0 = &generate_five;
|
||||
BOOST_CHECK(i0() == 5);
|
||||
BOOST_TEST(i0() == 5);
|
||||
i0 = &generate_three;
|
||||
BOOST_CHECK(i0() == 3);
|
||||
BOOST_CHECK(i0? true : false);
|
||||
BOOST_TEST(i0() == 3);
|
||||
BOOST_TEST(i0? true : false);
|
||||
i0.clear();
|
||||
BOOST_CHECK(!i0? true : false);
|
||||
BOOST_TEST(!i0? true : false);
|
||||
|
||||
// Test return values with compatible types
|
||||
typedef function0<long> func_long_type;
|
||||
func_long_type i1(gen_five);
|
||||
|
||||
BOOST_CHECK(i1() == 5);
|
||||
BOOST_TEST(i1() == 5);
|
||||
i1 = gen_three;
|
||||
BOOST_CHECK(i1() == 3);
|
||||
BOOST_TEST(i1() == 3);
|
||||
i1 = &generate_five;
|
||||
BOOST_CHECK(i1() == 5);
|
||||
BOOST_TEST(i1() == 5);
|
||||
i1 = &generate_three;
|
||||
BOOST_CHECK(i1() == 3);
|
||||
BOOST_CHECK(i1? true : false);
|
||||
BOOST_TEST(i1() == 3);
|
||||
BOOST_TEST(i1? true : false);
|
||||
i1.clear();
|
||||
BOOST_CHECK(!i1? true : false);
|
||||
BOOST_TEST(!i1? true : false);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -534,45 +534,45 @@ test_one_arg()
|
||||
negate<int> neg = negate<int>(); // Initialization for Borland C++ 5.5
|
||||
|
||||
function1<int, int> f1(neg);
|
||||
BOOST_CHECK(f1(5) == -5);
|
||||
BOOST_TEST(f1(5) == -5);
|
||||
|
||||
function1<string, string> id(&identity_str);
|
||||
BOOST_CHECK(id("str") == "str");
|
||||
BOOST_TEST(id("str") == "str");
|
||||
|
||||
function1<std::string, const char*> id2(&identity_str);
|
||||
BOOST_CHECK(id2("foo") == "foo");
|
||||
BOOST_TEST(id2("foo") == "foo");
|
||||
|
||||
add_to_obj add_to(5);
|
||||
function1<int, int> f2(add_to);
|
||||
BOOST_CHECK(f2(3) == 8);
|
||||
BOOST_TEST(f2(3) == 8);
|
||||
|
||||
const function1<int, int> cf2(add_to);
|
||||
BOOST_CHECK(cf2(3) == 8);
|
||||
BOOST_TEST(cf2(3) == 8);
|
||||
}
|
||||
|
||||
static void
|
||||
test_two_args()
|
||||
{
|
||||
function2<string, const string&, const string&> cat(&string_cat);
|
||||
BOOST_CHECK(cat("str", "ing") == "string");
|
||||
BOOST_TEST(cat("str", "ing") == "string");
|
||||
|
||||
function2<int, short, short> sum(&sum_ints);
|
||||
BOOST_CHECK(sum(2, 3) == 5);
|
||||
BOOST_TEST(sum(2, 3) == 5);
|
||||
}
|
||||
|
||||
static void
|
||||
test_emptiness()
|
||||
{
|
||||
function0<float> f1;
|
||||
BOOST_CHECK(f1.empty());
|
||||
BOOST_TEST(f1.empty());
|
||||
|
||||
function0<float> f2;
|
||||
f2 = f1;
|
||||
BOOST_CHECK(f2.empty());
|
||||
BOOST_TEST(f2.empty());
|
||||
|
||||
function0<double> f3;
|
||||
f3 = f2;
|
||||
BOOST_CHECK(f3.empty());
|
||||
BOOST_TEST(f3.empty());
|
||||
}
|
||||
|
||||
struct X {
|
||||
@ -593,18 +593,18 @@ test_member_functions()
|
||||
X one(1);
|
||||
X five(5);
|
||||
|
||||
BOOST_CHECK(f1(&one) == 2);
|
||||
BOOST_CHECK(f1(&five) == 10);
|
||||
BOOST_TEST(f1(&one) == 2);
|
||||
BOOST_TEST(f1(&five) == 10);
|
||||
|
||||
boost::function1<int, X*> f1_2;
|
||||
f1_2 = &X::twice;
|
||||
|
||||
BOOST_CHECK(f1_2(&one) == 2);
|
||||
BOOST_CHECK(f1_2(&five) == 10);
|
||||
BOOST_TEST(f1_2(&one) == 2);
|
||||
BOOST_TEST(f1_2(&five) == 10);
|
||||
|
||||
boost::function2<int, X&, int> f2(&X::plus);
|
||||
BOOST_CHECK(f2(one, 3) == 4);
|
||||
BOOST_CHECK(f2(five, 4) == 9);
|
||||
BOOST_TEST(f2(one, 3) == 4);
|
||||
BOOST_TEST(f2(five, 4) == 9);
|
||||
}
|
||||
|
||||
struct add_with_throw_on_copy {
|
||||
@ -629,7 +629,7 @@ test_ref()
|
||||
add_with_throw_on_copy atc;
|
||||
try {
|
||||
boost::function2<int, int, int> f(ref(atc));
|
||||
BOOST_CHECK(f(1, 3) == 4);
|
||||
BOOST_TEST(f(1, 3) == 4);
|
||||
}
|
||||
catch(std::runtime_error e) {
|
||||
BOOST_ERROR("Nonthrowing constructor threw an exception");
|
||||
|
@ -56,30 +56,30 @@ test_zero_args()
|
||||
|
||||
// Default construction
|
||||
func_void_type v1;
|
||||
BOOST_CHECK(v1.empty());
|
||||
BOOST_TEST(v1.empty());
|
||||
|
||||
// Assignment to an empty function
|
||||
v1 = five;
|
||||
BOOST_CHECK(v1 != 0);
|
||||
BOOST_TEST(v1 != 0);
|
||||
|
||||
// Invocation of a function
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear() method
|
||||
v1.clear();
|
||||
BOOST_CHECK(v1 == 0);
|
||||
BOOST_TEST(v1 == 0);
|
||||
|
||||
// Assignment to an empty function
|
||||
v1 = three;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation and self-assignment
|
||||
global_int = 0;
|
||||
v1 = v1;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v1 = five;
|
||||
@ -88,61 +88,61 @@ test_zero_args()
|
||||
global_int = 0;
|
||||
v1 = (v1);
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear
|
||||
v1 = 0;
|
||||
BOOST_CHECK(0 == v1);
|
||||
BOOST_TEST(0 == v1);
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v1 = BOOST_FUNCTION_TARGET_FIX(&) write_five;
|
||||
BOOST_CHECK(0 != v1);
|
||||
BOOST_TEST(0 != v1);
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v1 = BOOST_FUNCTION_TARGET_FIX(&) write_three;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment
|
||||
v1 = five;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v1 = &write_three;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Construction from another function (that is empty)
|
||||
v1.clear();
|
||||
func_void_type v2(v1);
|
||||
BOOST_CHECK(!v2? true : false);
|
||||
BOOST_TEST(!v2? true : false);
|
||||
|
||||
// Assignment to an empty function
|
||||
v2 = three;
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v2 = (five);
|
||||
@ -150,86 +150,86 @@ test_zero_args()
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
v2.clear();
|
||||
BOOST_CHECK(v2.empty());
|
||||
BOOST_TEST(v2.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v2 = (BOOST_FUNCTION_TARGET_FIX(&) write_five);
|
||||
BOOST_CHECK(v2? true : false);
|
||||
BOOST_TEST(v2? true : false);
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v2 = BOOST_FUNCTION_TARGET_FIX(&) write_three;
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Swapping
|
||||
v1 = five;
|
||||
swap(v1, v2);
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
swap(v1, v2);
|
||||
v1.clear();
|
||||
|
||||
// Assignment
|
||||
v2 = five;
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v2 = &write_three;
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a function from an empty function
|
||||
v2 = v1;
|
||||
BOOST_CHECK(v2.empty());
|
||||
BOOST_TEST(v2.empty());
|
||||
|
||||
// Assignment to a function from a function with a functor
|
||||
v1 = three;
|
||||
v2 = v1;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assign to a function from a function with a function
|
||||
v2 = BOOST_FUNCTION_TARGET_FIX(&) write_five;
|
||||
v1 = v2;
|
||||
BOOST_CHECK(!v1.empty());
|
||||
BOOST_CHECK(!v2.empty());
|
||||
BOOST_TEST(!v1.empty());
|
||||
BOOST_TEST(!v2.empty());
|
||||
global_int = 0;
|
||||
v1();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
global_int = 0;
|
||||
v2();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Construct a function given another function containing a function
|
||||
func_void_type v3(v1);
|
||||
@ -237,20 +237,20 @@ test_zero_args()
|
||||
// Invocation of a function
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear() method
|
||||
v3.clear();
|
||||
BOOST_CHECK(!v3? true : false);
|
||||
BOOST_TEST(!v3? true : false);
|
||||
|
||||
// Assignment to an empty function
|
||||
v3 = three;
|
||||
BOOST_CHECK(!v3.empty());
|
||||
BOOST_TEST(!v3.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v3 = five;
|
||||
@ -258,38 +258,38 @@ test_zero_args()
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear()
|
||||
v3.clear();
|
||||
BOOST_CHECK(v3.empty());
|
||||
BOOST_TEST(v3.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v3 = &write_five;
|
||||
BOOST_CHECK(!v3.empty());
|
||||
BOOST_TEST(!v3.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v3 = &write_three;
|
||||
BOOST_CHECK(!v3.empty());
|
||||
BOOST_TEST(!v3.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment
|
||||
v3 = five;
|
||||
BOOST_CHECK(!v3.empty());
|
||||
BOOST_TEST(!v3.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v3();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Construction of a function from a function containing a functor
|
||||
func_void_type v4(v3);
|
||||
@ -297,20 +297,20 @@ test_zero_args()
|
||||
// Invocation of a function
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear() method
|
||||
v4.clear();
|
||||
BOOST_CHECK(v4.empty());
|
||||
BOOST_TEST(v4.empty());
|
||||
|
||||
// Assignment to an empty function
|
||||
v4 = three;
|
||||
BOOST_CHECK(!v4.empty());
|
||||
BOOST_TEST(!v4.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v4 = five;
|
||||
@ -318,38 +318,38 @@ test_zero_args()
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear()
|
||||
v4.clear();
|
||||
BOOST_CHECK(v4.empty());
|
||||
BOOST_TEST(v4.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v4 = &write_five;
|
||||
BOOST_CHECK(!v4.empty());
|
||||
BOOST_TEST(!v4.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v4 = &write_three;
|
||||
BOOST_CHECK(!v4.empty());
|
||||
BOOST_TEST(!v4.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment
|
||||
v4 = five;
|
||||
BOOST_CHECK(!v4.empty());
|
||||
BOOST_TEST(!v4.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v4();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Construction of a function from a functor
|
||||
func_void_type v5(five);
|
||||
@ -357,20 +357,20 @@ test_zero_args()
|
||||
// Invocation of a function
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear() method
|
||||
v5.clear();
|
||||
BOOST_CHECK(v5.empty());
|
||||
BOOST_TEST(v5.empty());
|
||||
|
||||
// Assignment to an empty function
|
||||
v5 = three;
|
||||
BOOST_CHECK(!v5.empty());
|
||||
BOOST_TEST(!v5.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v5 = five;
|
||||
@ -378,38 +378,38 @@ test_zero_args()
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear()
|
||||
v5.clear();
|
||||
BOOST_CHECK(v5.empty());
|
||||
BOOST_TEST(v5.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v5 = &write_five;
|
||||
BOOST_CHECK(!v5.empty());
|
||||
BOOST_TEST(!v5.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v5 = &write_three;
|
||||
BOOST_CHECK(!v5.empty());
|
||||
BOOST_TEST(!v5.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment
|
||||
v5 = five;
|
||||
BOOST_CHECK(!v5.empty());
|
||||
BOOST_TEST(!v5.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v5();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Construction of a function from a function
|
||||
func_void_type v6(&write_five);
|
||||
@ -417,20 +417,20 @@ test_zero_args()
|
||||
// Invocation of a function
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear() method
|
||||
v6.clear();
|
||||
BOOST_CHECK(v6.empty());
|
||||
BOOST_TEST(v6.empty());
|
||||
|
||||
// Assignment to an empty function
|
||||
v6 = three;
|
||||
BOOST_CHECK(!v6.empty());
|
||||
BOOST_TEST(!v6.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment to a non-empty function
|
||||
v6 = five;
|
||||
@ -438,38 +438,38 @@ test_zero_args()
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// clear()
|
||||
v6.clear();
|
||||
BOOST_CHECK(v6.empty());
|
||||
BOOST_TEST(v6.empty());
|
||||
|
||||
// Assignment to an empty function from a free function
|
||||
v6 = &write_five;
|
||||
BOOST_CHECK(!v6.empty());
|
||||
BOOST_TEST(!v6.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Assignment to a non-empty function from a free function
|
||||
v6 = &write_three;
|
||||
BOOST_CHECK(!v6.empty());
|
||||
BOOST_TEST(!v6.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 3);
|
||||
BOOST_TEST(global_int == 3);
|
||||
|
||||
// Assignment
|
||||
v6 = five;
|
||||
BOOST_CHECK(!v6.empty());
|
||||
BOOST_TEST(!v6.empty());
|
||||
|
||||
// Invocation
|
||||
global_int = 0;
|
||||
v6();
|
||||
BOOST_CHECK(global_int == 5);
|
||||
BOOST_TEST(global_int == 5);
|
||||
|
||||
// Const vs. non-const
|
||||
write_const_1_nonconst_2 one_or_two;
|
||||
@ -478,16 +478,16 @@ test_zero_args()
|
||||
|
||||
global_int = 0;
|
||||
v7();
|
||||
BOOST_CHECK(global_int == 2);
|
||||
BOOST_TEST(global_int == 2);
|
||||
|
||||
global_int = 0;
|
||||
v8();
|
||||
BOOST_CHECK(global_int == 2);
|
||||
BOOST_TEST(global_int == 2);
|
||||
|
||||
// Test construction from 0 and comparison to 0
|
||||
func_void_type v9(0);
|
||||
BOOST_CHECK(v9 == 0);
|
||||
BOOST_CHECK(0 == v9);
|
||||
BOOST_TEST(v9 == 0);
|
||||
BOOST_TEST(0 == v9);
|
||||
|
||||
// Test return values
|
||||
typedef function<int ()> func_int_type;
|
||||
@ -496,31 +496,31 @@ test_zero_args()
|
||||
|
||||
func_int_type i0(gen_five);
|
||||
|
||||
BOOST_CHECK(i0() == 5);
|
||||
BOOST_TEST(i0() == 5);
|
||||
i0 = gen_three;
|
||||
BOOST_CHECK(i0() == 3);
|
||||
BOOST_TEST(i0() == 3);
|
||||
i0 = &generate_five;
|
||||
BOOST_CHECK(i0() == 5);
|
||||
BOOST_TEST(i0() == 5);
|
||||
i0 = &generate_three;
|
||||
BOOST_CHECK(i0() == 3);
|
||||
BOOST_CHECK(i0? true : false);
|
||||
BOOST_TEST(i0() == 3);
|
||||
BOOST_TEST(i0? true : false);
|
||||
i0.clear();
|
||||
BOOST_CHECK(!i0? true : false);
|
||||
BOOST_TEST(!i0? true : false);
|
||||
|
||||
// Test return values with compatible types
|
||||
typedef function<long ()> func_long_type;
|
||||
func_long_type i1(gen_five);
|
||||
|
||||
BOOST_CHECK(i1() == 5);
|
||||
BOOST_TEST(i1() == 5);
|
||||
i1 = gen_three;
|
||||
BOOST_CHECK(i1() == 3);
|
||||
BOOST_TEST(i1() == 3);
|
||||
i1 = &generate_five;
|
||||
BOOST_CHECK(i1() == 5);
|
||||
BOOST_TEST(i1() == 5);
|
||||
i1 = &generate_three;
|
||||
BOOST_CHECK(i1() == 3);
|
||||
BOOST_CHECK(i1? true : false);
|
||||
BOOST_TEST(i1() == 3);
|
||||
BOOST_TEST(i1? true : false);
|
||||
i1.clear();
|
||||
BOOST_CHECK(!i1? true : false);
|
||||
BOOST_TEST(!i1? true : false);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -529,45 +529,45 @@ test_one_arg()
|
||||
negate<int> neg;
|
||||
|
||||
function<int (int)> f1(neg);
|
||||
BOOST_CHECK(f1(5) == -5);
|
||||
BOOST_TEST(f1(5) == -5);
|
||||
|
||||
function<string (string)> id(&identity_str);
|
||||
BOOST_CHECK(id("str") == "str");
|
||||
BOOST_TEST(id("str") == "str");
|
||||
|
||||
function<string (const char*)> id2(&identity_str);
|
||||
BOOST_CHECK(id2("foo") == "foo");
|
||||
BOOST_TEST(id2("foo") == "foo");
|
||||
|
||||
add_to_obj add_to(5);
|
||||
function<int (int)> f2(add_to);
|
||||
BOOST_CHECK(f2(3) == 8);
|
||||
BOOST_TEST(f2(3) == 8);
|
||||
|
||||
const function<int (int)> cf2(add_to);
|
||||
BOOST_CHECK(cf2(3) == 8);
|
||||
BOOST_TEST(cf2(3) == 8);
|
||||
}
|
||||
|
||||
static void
|
||||
test_two_args()
|
||||
{
|
||||
function<string (const string&, const string&)> cat(&string_cat);
|
||||
BOOST_CHECK(cat("str", "ing") == "string");
|
||||
BOOST_TEST(cat("str", "ing") == "string");
|
||||
|
||||
function<int (short, short)> sum(&sum_ints);
|
||||
BOOST_CHECK(sum(2, 3) == 5);
|
||||
BOOST_TEST(sum(2, 3) == 5);
|
||||
}
|
||||
|
||||
static void
|
||||
test_emptiness()
|
||||
{
|
||||
function<float ()> f1;
|
||||
BOOST_CHECK(f1.empty());
|
||||
BOOST_TEST(f1.empty());
|
||||
|
||||
function<float ()> f2;
|
||||
f2 = f1;
|
||||
BOOST_CHECK(f2.empty());
|
||||
BOOST_TEST(f2.empty());
|
||||
|
||||
function<double ()> f3;
|
||||
f3 = f2;
|
||||
BOOST_CHECK(f3.empty());
|
||||
BOOST_TEST(f3.empty());
|
||||
}
|
||||
|
||||
struct X {
|
||||
@ -587,18 +587,18 @@ test_member_functions()
|
||||
X one(1);
|
||||
X five(5);
|
||||
|
||||
BOOST_CHECK(f1(&one) == 2);
|
||||
BOOST_CHECK(f1(&five) == 10);
|
||||
BOOST_TEST(f1(&one) == 2);
|
||||
BOOST_TEST(f1(&five) == 10);
|
||||
|
||||
boost::function<int (X*)> f1_2;
|
||||
f1_2 = &X::twice;
|
||||
|
||||
BOOST_CHECK(f1_2(&one) == 2);
|
||||
BOOST_CHECK(f1_2(&five) == 10);
|
||||
BOOST_TEST(f1_2(&one) == 2);
|
||||
BOOST_TEST(f1_2(&five) == 10);
|
||||
|
||||
boost::function<int (X&, int)> f2(&X::plus);
|
||||
BOOST_CHECK(f2(one, 3) == 4);
|
||||
BOOST_CHECK(f2(five, 4) == 9);
|
||||
BOOST_TEST(f2(one, 3) == 4);
|
||||
BOOST_TEST(f2(five, 4) == 9);
|
||||
}
|
||||
|
||||
struct add_with_throw_on_copy {
|
||||
@ -623,19 +623,83 @@ test_ref()
|
||||
add_with_throw_on_copy atc;
|
||||
try {
|
||||
boost::function<int (int, int)> f(ref(atc));
|
||||
BOOST_CHECK(f(1, 3) == 4);
|
||||
BOOST_TEST(f(1, 3) == 4);
|
||||
}
|
||||
catch(runtime_error e) {
|
||||
BOOST_ERROR("Nonthrowing constructor threw an exception");
|
||||
}
|
||||
}
|
||||
|
||||
static int alloc_count = 0;
|
||||
static int dealloc_count = 0;
|
||||
|
||||
template<typename T>
|
||||
struct counting_allocator : public allocator<T>
|
||||
{
|
||||
template<typename U>
|
||||
struct rebind
|
||||
{
|
||||
typedef counting_allocator<U> other;
|
||||
};
|
||||
|
||||
|
||||
T* allocate(size_t n)
|
||||
{
|
||||
alloc_count++;
|
||||
return allocator<T>::allocate(n);
|
||||
}
|
||||
|
||||
void deallocate(T* p, size_t n)
|
||||
{
|
||||
dealloc_count++;
|
||||
allocator<T>::deallocate(p, n);
|
||||
}
|
||||
};
|
||||
|
||||
static int do_minus(int x, int y) { return x-y; }
|
||||
|
||||
struct DoNothing
|
||||
{
|
||||
void operator()() const {}
|
||||
};
|
||||
|
||||
static void do_nothing() {}
|
||||
|
||||
static void test_allocator()
|
||||
{
|
||||
#ifndef BOOST_NO_STD_ALLOCATOR
|
||||
boost::function<int (int, int), counting_allocator<int> > f;
|
||||
f = plus<int>();
|
||||
f.clear();
|
||||
BOOST_TEST(alloc_count == 1);
|
||||
BOOST_TEST(dealloc_count == 1);
|
||||
|
||||
alloc_count = 0;
|
||||
dealloc_count = 0;
|
||||
f = &do_minus;
|
||||
f.clear();
|
||||
|
||||
boost::function<void (), counting_allocator<int> > fv;
|
||||
alloc_count = 0;
|
||||
dealloc_count = 0;
|
||||
fv = DoNothing();
|
||||
fv.clear();
|
||||
BOOST_TEST(alloc_count == 1);
|
||||
BOOST_TEST(dealloc_count == 1);
|
||||
|
||||
alloc_count = 0;
|
||||
dealloc_count = 0;
|
||||
fv = &do_nothing;
|
||||
fv.clear();
|
||||
#endif // ndef BOOST_NO_STD_ALLOCATOR
|
||||
}
|
||||
|
||||
static void test_exception()
|
||||
{
|
||||
boost::function<int (int, int)> f;
|
||||
try {
|
||||
f(5, 4);
|
||||
BOOST_CHECK(false);
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(boost::bad_function_call) {
|
||||
// okay
|
||||
@ -675,6 +739,7 @@ int test_main(int, char* [])
|
||||
test_emptiness();
|
||||
test_member_functions();
|
||||
test_ref();
|
||||
test_allocator();
|
||||
test_exception();
|
||||
test_implicit();
|
||||
test_call();
|
||||
|
Reference in New Issue
Block a user