forked from boostorg/fusion
adds test suite for functional module
[SVN r36960]
This commit is contained in:
17
test/Jamfile
17
test/Jamfile
@ -104,6 +104,23 @@ import testing ;
|
|||||||
[ run sequence/zip_view.cpp : : : : ]
|
[ run sequence/zip_view.cpp : : : : ]
|
||||||
[ run sequence/zip_view2.cpp : : : : ]
|
[ run sequence/zip_view2.cpp : : : : ]
|
||||||
[ run sequence/deduce_sequence.cpp : : : : ]
|
[ run sequence/deduce_sequence.cpp : : : : ]
|
||||||
|
[ run functional/fused.cpp : : : : ]
|
||||||
|
[ run functional/fused_function_object.cpp : : : : ]
|
||||||
|
[ run functional/fused_procedure.cpp : : : : ]
|
||||||
|
[ run functional/unfused_generic.cpp : : : : ]
|
||||||
|
[ run functional/unfused_lvalue_args.cpp : : : : ]
|
||||||
|
[ run functional/unfused_rvalue_args.cpp : : : : ]
|
||||||
|
[ run functional/unfused_typed.cpp : : : : ]
|
||||||
|
[ run functional/make_fused.cpp : : : : ]
|
||||||
|
[ run functional/make_fused_function_object.cpp : : : : ]
|
||||||
|
[ run functional/make_fused_procedure.cpp : : : : ]
|
||||||
|
[ run functional/make_unfused_generic.cpp : : : : ]
|
||||||
|
[ run functional/make_unfused_lvalue_args.cpp : : : : ]
|
||||||
|
[ run functional/make_unfused_rvalue_args.cpp : : : : ]
|
||||||
|
[ run functional/invoke.cpp : : : : ]
|
||||||
|
[ run functional/invoke_function_object.cpp : : : : ]
|
||||||
|
[ run functional/invoke_procedure.cpp : : : : ]
|
||||||
|
|
||||||
# [ compile-fail xxx.cpp : : : : ]
|
# [ compile-fail xxx.cpp : : : : ]
|
||||||
|
|
||||||
;
|
;
|
||||||
|
78
test/functional/fused.cpp
Normal file
78
test/functional/fused.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/adapter/fused.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/generation/make_vector.hpp>
|
||||||
|
#include <boost/fusion/sequence/container/vector.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
using boost::noncopyable;
|
||||||
|
|
||||||
|
template <class Base = boost::blank>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
typedef int result_type;
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y) const
|
||||||
|
{
|
||||||
|
return 1+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y)
|
||||||
|
{
|
||||||
|
return 2+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y) const
|
||||||
|
{
|
||||||
|
return 3+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y)
|
||||||
|
{
|
||||||
|
return 4+x-y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test_func<noncopyable> f;
|
||||||
|
fusion::fused< test_func<> > fused_func;
|
||||||
|
fusion::fused< test_func<noncopyable> & > fused_func_ref(f);
|
||||||
|
fusion::fused< test_func<> const > fused_func_c;
|
||||||
|
fusion::fused< test_func<> > const fused_func_c2;
|
||||||
|
fusion::fused< test_func<noncopyable> const & > fused_func_c_ref(f);
|
||||||
|
|
||||||
|
fusion::vector<int,char> lv_vec(1,'\004');
|
||||||
|
BOOST_TEST(fused_func(lv_vec) == 1);
|
||||||
|
BOOST_TEST(fused_func_c(lv_vec) == 0);
|
||||||
|
BOOST_TEST(fused_func_c2(lv_vec) == 0);
|
||||||
|
BOOST_TEST(fused_func_ref(lv_vec) == 1);
|
||||||
|
BOOST_TEST(fused_func_c_ref(lv_vec) == 0);
|
||||||
|
|
||||||
|
BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1);
|
||||||
|
BOOST_TEST(fused_func_c(fusion::make_vector(2,'\003')) == 0);
|
||||||
|
BOOST_TEST(fused_func_c2(fusion::make_vector(2,'\003')) == 0);
|
||||||
|
BOOST_TEST(fused_func_ref(fusion::make_vector(2,'\003')) == 1);
|
||||||
|
BOOST_TEST(fused_func_c_ref(fusion::make_vector(2,'\003')) == 0);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
80
test/functional/fused_function_object.cpp
Normal file
80
test/functional/fused_function_object.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/adapter/fused_function_object.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/generation/make_vector.hpp>
|
||||||
|
#include <boost/fusion/sequence/container/vector.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
using boost::noncopyable;
|
||||||
|
|
||||||
|
template <class Base = boost::blank>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
struct result
|
||||||
|
{
|
||||||
|
typedef int type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y) const
|
||||||
|
{
|
||||||
|
return 1+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y)
|
||||||
|
{
|
||||||
|
return 2+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y) const
|
||||||
|
{
|
||||||
|
return 3+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y)
|
||||||
|
{
|
||||||
|
return 4+x-y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test_func<noncopyable> f;
|
||||||
|
fusion::fused_function_object< test_func<> > fused_func;
|
||||||
|
fusion::fused_function_object< test_func<noncopyable> & > fused_func_ref(f);
|
||||||
|
fusion::fused_function_object< test_func<> const > fused_func_c;
|
||||||
|
fusion::fused_function_object< test_func<> > const fused_func_c2;
|
||||||
|
fusion::fused_function_object< test_func<noncopyable> const & > fused_func_c_ref(f);
|
||||||
|
|
||||||
|
fusion::vector<int,char> lv_vec(1,'\004');
|
||||||
|
BOOST_TEST(fused_func(lv_vec) == 1);
|
||||||
|
BOOST_TEST(fused_func_c(lv_vec) == 0);
|
||||||
|
BOOST_TEST(fused_func_c2(lv_vec) == 0);
|
||||||
|
BOOST_TEST(fused_func_ref(lv_vec) == 1);
|
||||||
|
BOOST_TEST(fused_func_c_ref(lv_vec) == 0);
|
||||||
|
|
||||||
|
BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1);
|
||||||
|
BOOST_TEST(fused_func_c(fusion::make_vector(2,'\003')) == 0);
|
||||||
|
BOOST_TEST(fused_func_c2(fusion::make_vector(2,'\003')) == 0);
|
||||||
|
BOOST_TEST(fused_func_ref(fusion::make_vector(2,'\003')) == 1);
|
||||||
|
BOOST_TEST(fused_func_c_ref(fusion::make_vector(2,'\003')) == 0);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
82
test/functional/fused_procedure.cpp
Normal file
82
test/functional/fused_procedure.cpp
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/adapter/fused_procedure.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/generation/make_vector.hpp>
|
||||||
|
#include <boost/fusion/sequence/container/vector.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
using boost::noncopyable;
|
||||||
|
|
||||||
|
int effect;
|
||||||
|
|
||||||
|
#define CHECK_EFFECT(t,e) \
|
||||||
|
{ \
|
||||||
|
effect = 1234567; t; \
|
||||||
|
BOOST_TEST(effect == e); \
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Base = boost::blank>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y) const
|
||||||
|
{
|
||||||
|
return effect = 1+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y)
|
||||||
|
{
|
||||||
|
return effect = 2+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y) const
|
||||||
|
{
|
||||||
|
return effect = 3+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y)
|
||||||
|
{
|
||||||
|
return effect = 4+x-y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test_func<noncopyable> f;
|
||||||
|
fusion::fused_procedure< test_func<> > fused_proc;
|
||||||
|
fusion::fused_procedure< test_func<noncopyable> & > fused_proc_ref(f);
|
||||||
|
fusion::fused_procedure< test_func<> const > fused_proc_c;
|
||||||
|
fusion::fused_procedure< test_func<> > const fused_proc_c2;
|
||||||
|
fusion::fused_procedure< test_func<noncopyable> const & > fused_proc_c_ref(f);
|
||||||
|
|
||||||
|
fusion::vector<int,char> lv_vec(1,'\004');
|
||||||
|
CHECK_EFFECT(fused_proc(lv_vec), 1);
|
||||||
|
CHECK_EFFECT(fused_proc_c(lv_vec), 0);
|
||||||
|
CHECK_EFFECT(fused_proc_c2(lv_vec), 0);
|
||||||
|
CHECK_EFFECT(fused_proc_ref(lv_vec), 1);
|
||||||
|
CHECK_EFFECT(fused_proc_c_ref(lv_vec), 0);
|
||||||
|
|
||||||
|
CHECK_EFFECT(fused_proc(fusion::make_vector(2,'\003')), 1);
|
||||||
|
CHECK_EFFECT(fused_proc_c(fusion::make_vector(2,'\003')), 0);
|
||||||
|
CHECK_EFFECT(fused_proc_c2(fusion::make_vector(2,'\003')), 0);
|
||||||
|
CHECK_EFFECT(fused_proc_ref(fusion::make_vector(2,'\003')), 1);
|
||||||
|
CHECK_EFFECT(fused_proc_c_ref(fusion::make_vector(2,'\003')), 0);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
359
test/functional/invoke.cpp
Normal file
359
test/functional/invoke.cpp
Normal file
@ -0,0 +1,359 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2005-2006 João Abecasis
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/invocation/invoke.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/functional/adapter/detail/has_type.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/int.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/container/vector.hpp>
|
||||||
|
#include <boost/fusion/sequence/container/list.hpp>
|
||||||
|
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||||
|
#include <boost/fusion/sequence/intrinsic/begin.hpp>
|
||||||
|
#include <boost/fusion/sequence/view/single_view.hpp>
|
||||||
|
#include <boost/fusion/sequence/view/iterator_range.hpp>
|
||||||
|
#include <boost/fusion/iterator/advance.hpp>
|
||||||
|
#include <boost/fusion/algorithm/transformation/join.hpp>
|
||||||
|
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline T const & const_(T const & t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct object {};
|
||||||
|
struct object_nc : boost::noncopyable {};
|
||||||
|
|
||||||
|
struct fobj
|
||||||
|
{
|
||||||
|
typedef int result_type;
|
||||||
|
|
||||||
|
int operator()() { return 0; }
|
||||||
|
int operator()() const { return 1; }
|
||||||
|
|
||||||
|
int operator()(int i) { return 2 + i; }
|
||||||
|
int operator()(int i) const { return 3 + i; }
|
||||||
|
|
||||||
|
int operator()(int i, object &) { return 4 + i; }
|
||||||
|
int operator()(int i, object &) const { return 5 + i; }
|
||||||
|
int operator()(int i, object const &) { return 6 + i; }
|
||||||
|
int operator()(int i, object const &) const { return 7 + i; }
|
||||||
|
|
||||||
|
int operator()(int i, object &, object_nc &) { return 10 + i; }
|
||||||
|
int operator()(int i, object &, object_nc &) const { return 11 + i; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fobj_nc
|
||||||
|
: boost::noncopyable
|
||||||
|
{
|
||||||
|
typedef int result_type;
|
||||||
|
|
||||||
|
int operator()() { return 12; }
|
||||||
|
int operator()() const { return 13; }
|
||||||
|
|
||||||
|
int operator()(int i) { return 14 + i; }
|
||||||
|
int operator()(int i) const { return 15 + i; }
|
||||||
|
};
|
||||||
|
|
||||||
|
int nullary() { return 16; }
|
||||||
|
int unary(int i) { return 17 + i; }
|
||||||
|
int binary1(int i, object &) { return 18 + i; }
|
||||||
|
int binary2(int i, object const &) { return 19 + i; }
|
||||||
|
|
||||||
|
typedef int (* func_ptr)(int);
|
||||||
|
typedef int (* const c_func_ptr)(int);
|
||||||
|
typedef int (* volatile v_func_ptr)(int);
|
||||||
|
typedef int (* const volatile cv_func_ptr)(int);
|
||||||
|
|
||||||
|
func_ptr func_ptr1 = &unary;
|
||||||
|
c_func_ptr func_ptr2 = &unary;
|
||||||
|
v_func_ptr func_ptr3 = &unary;
|
||||||
|
cv_func_ptr func_ptr4 = &unary;
|
||||||
|
|
||||||
|
class members
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int data;
|
||||||
|
|
||||||
|
members()
|
||||||
|
: data(20)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
int nullary() { return data + 1; }
|
||||||
|
int nullary_c() const { return data + 2; }
|
||||||
|
int unary(int i) { return data + 3 + i; }
|
||||||
|
int unary_c(int i) const { return data + 4 + i; }
|
||||||
|
int binary(int i, object) { return data + 5 + i; }
|
||||||
|
int binary_c(int i, object) const { return data + 6 + i; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct derived
|
||||||
|
: members
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef int element1_type;
|
||||||
|
typedef object element2_type;
|
||||||
|
typedef object_nc & element3_type;
|
||||||
|
|
||||||
|
int element1 = 100;
|
||||||
|
object element2 = object();
|
||||||
|
object_nc element3;
|
||||||
|
|
||||||
|
members that;
|
||||||
|
|
||||||
|
std::auto_ptr<members> spt_that(new members);
|
||||||
|
std::auto_ptr<members const> spt_that_c(new members);
|
||||||
|
|
||||||
|
fusion::single_view<members > sv_obj_ctx( that);
|
||||||
|
fusion::single_view<members &> sv_ref_ctx( that);
|
||||||
|
fusion::single_view<members *> sv_ptr_ctx(& that);
|
||||||
|
fusion::single_view<members const > sv_obj_c_ctx( that);
|
||||||
|
fusion::single_view<members const &> sv_ref_c_ctx( that);
|
||||||
|
fusion::single_view<members const *> sv_ptr_c_ctx(& that);
|
||||||
|
fusion::single_view<std::auto_ptr<members> const &> sv_spt_ctx(spt_that);
|
||||||
|
fusion::single_view< std::auto_ptr<members const> const &> sv_spt_c_ctx(spt_that_c);
|
||||||
|
|
||||||
|
derived derived_that;
|
||||||
|
|
||||||
|
std::auto_ptr<derived> spt_derived_that(new derived);
|
||||||
|
std::auto_ptr<derived const> spt_derived_that_c(new derived);
|
||||||
|
|
||||||
|
fusion::single_view<derived > sv_obj_d_ctx( derived_that);
|
||||||
|
fusion::single_view<derived &> sv_ref_d_ctx( derived_that);
|
||||||
|
fusion::single_view<derived *> sv_ptr_d_ctx(& derived_that);
|
||||||
|
fusion::single_view<derived const > sv_obj_c_d_ctx( derived_that);
|
||||||
|
fusion::single_view<derived const &> sv_ref_c_d_ctx( derived_that);
|
||||||
|
fusion::single_view<derived const *> sv_ptr_c_d_ctx(& derived_that);
|
||||||
|
fusion::single_view<std::auto_ptr<derived> const &> sv_spt_d_ctx(spt_derived_that);
|
||||||
|
fusion::single_view< std::auto_ptr<derived const> const &> sv_spt_c_d_ctx(spt_derived_that_c);
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<0>)
|
||||||
|
{
|
||||||
|
// Function Objects
|
||||||
|
|
||||||
|
fobj f;
|
||||||
|
|
||||||
|
BOOST_TEST(f () == fusion::invoke(f , seq ));
|
||||||
|
BOOST_TEST(f () == fusion::invoke(f , const_(seq)));
|
||||||
|
|
||||||
|
// Note: The function object is taken by value, so we request the copy
|
||||||
|
// to be const with an explicit template argument. We can also request
|
||||||
|
// the function object to be pased by reference...
|
||||||
|
BOOST_TEST(const_(f)() == fusion::invoke<fobj const >(const_(f), seq ));
|
||||||
|
BOOST_TEST(const_(f)() == fusion::invoke<fobj const &>(const_(f), const_(seq)));
|
||||||
|
|
||||||
|
fobj_nc nc_f;
|
||||||
|
// ...and we further ensure there is no copying in this case, using a
|
||||||
|
// noncopyable function object.
|
||||||
|
BOOST_TEST(nc_f () == fusion::invoke<fobj_nc &>(nc_f , seq ));
|
||||||
|
BOOST_TEST(nc_f () == fusion::invoke<fobj_nc &>(nc_f , const_(seq)));
|
||||||
|
BOOST_TEST(const_(nc_f)() == fusion::invoke<fobj_nc const &>(const_(nc_f), seq ));
|
||||||
|
BOOST_TEST(const_(nc_f)() == fusion::invoke<fobj_nc const &>(const_(nc_f), const_(seq)));
|
||||||
|
|
||||||
|
// Builtin Functions
|
||||||
|
|
||||||
|
// Call through ref/ptr to function
|
||||||
|
BOOST_TEST(nullary() == fusion::invoke<int (&)()>(nullary, seq));
|
||||||
|
BOOST_TEST(nullary() == fusion::invoke(& nullary, seq));
|
||||||
|
|
||||||
|
// Call through ptr to member function
|
||||||
|
// Note: The non-const function members::nullary can't be invoked with
|
||||||
|
// fusion::join(sv_obj_ctx,seq)), which is const and so is its first element
|
||||||
|
BOOST_TEST(that.nullary() == fusion::invoke(& members::nullary, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
BOOST_TEST(that.nullary() == fusion::invoke(& members::nullary, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
BOOST_TEST(that.nullary() == fusion::invoke(& members::nullary, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_obj_ctx,seq)));
|
||||||
|
BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_obj_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_ref_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_ptr_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_spt_c_ctx,seq)));
|
||||||
|
|
||||||
|
// Pointer to data member
|
||||||
|
|
||||||
|
BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_obj_ctx,seq)) = that.data));
|
||||||
|
BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_ref_ctx,seq)) = that.data));
|
||||||
|
BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_ptr_ctx,seq)) = that.data));
|
||||||
|
BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_spt_ctx,seq)) = that.data));
|
||||||
|
BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_obj_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_ref_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_ptr_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_spt_c_ctx,seq)));
|
||||||
|
|
||||||
|
BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_obj_d_ctx,seq)) = that.data));
|
||||||
|
BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_ref_d_ctx,seq)) = that.data));
|
||||||
|
BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_ptr_d_ctx,seq)) = that.data));
|
||||||
|
BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_spt_d_ctx,seq)) = that.data));
|
||||||
|
BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_obj_c_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_ref_c_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_ptr_c_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_spt_c_d_ctx,seq)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<1>)
|
||||||
|
{
|
||||||
|
fobj f;
|
||||||
|
BOOST_TEST(f(element1) == fusion::invoke(f , seq ));
|
||||||
|
BOOST_TEST(f(element1) == fusion::invoke(f , const_(seq)));
|
||||||
|
BOOST_TEST(const_(f)(element1) == fusion::invoke<fobj const >(const_(f), seq ));
|
||||||
|
BOOST_TEST(const_(f)(element1) == fusion::invoke<fobj const &>(const_(f), const_(seq)));
|
||||||
|
|
||||||
|
fobj_nc nc_f;
|
||||||
|
BOOST_TEST(nc_f(element1) == fusion::invoke<fobj_nc &>(nc_f, seq ));
|
||||||
|
BOOST_TEST(nc_f(element1) == fusion::invoke<fobj_nc &>(nc_f, const_(seq)));
|
||||||
|
BOOST_TEST(const_(nc_f)(element1) == fusion::invoke<fobj_nc const &>(const_(nc_f), seq ));
|
||||||
|
BOOST_TEST(const_(nc_f)(element1) == fusion::invoke<fobj_nc const &>(const_(nc_f), const_(seq)));
|
||||||
|
|
||||||
|
BOOST_TEST(unary(element1) == fusion::invoke<int (&)(int)>(unary, seq));
|
||||||
|
BOOST_TEST(func_ptr1(element1) == fusion::invoke(func_ptr1, seq));
|
||||||
|
BOOST_TEST(func_ptr2(element1) == fusion::invoke(func_ptr2, seq));
|
||||||
|
BOOST_TEST(func_ptr3(element1) == fusion::invoke(func_ptr3, seq));
|
||||||
|
BOOST_TEST(func_ptr4(element1) == fusion::invoke(func_ptr4, seq));
|
||||||
|
|
||||||
|
BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_obj_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_obj_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ref_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ptr_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_spt_c_ctx,seq)));
|
||||||
|
|
||||||
|
BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_ref_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_ptr_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_spt_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_obj_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ref_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ptr_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_spt_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_obj_c_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ref_c_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ptr_c_d_ctx,seq)));
|
||||||
|
BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_spt_c_d_ctx,seq)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<2>)
|
||||||
|
{
|
||||||
|
fobj f;
|
||||||
|
BOOST_TEST(f (element1, element2) == fusion::invoke(f , seq));
|
||||||
|
BOOST_TEST(f (element1, const_(element2)) == fusion::invoke(f , const_(seq)));
|
||||||
|
BOOST_TEST(const_(f)(element1, element2) == fusion::invoke<fobj const>(const_(f), seq));
|
||||||
|
BOOST_TEST(const_(f)(element1, const_(element2)) == fusion::invoke<fobj const>(const_(f), const_(seq)));
|
||||||
|
|
||||||
|
BOOST_TEST(binary1(element1, element2) == fusion::invoke(binary1, seq));
|
||||||
|
BOOST_TEST(binary2(element1, element2) == fusion::invoke(binary2, seq));
|
||||||
|
|
||||||
|
BOOST_TEST(that.binary(element1,element2) == fusion::invoke(& members::binary, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
BOOST_TEST(that.binary(element1,element2) == fusion::invoke(& members::binary, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
BOOST_TEST(that.binary(element1,element2) == fusion::invoke(& members::binary, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_obj_ctx,seq)));
|
||||||
|
BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_obj_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_ref_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_ptr_c_ctx,seq)));
|
||||||
|
BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_spt_c_ctx,seq)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<3>)
|
||||||
|
{
|
||||||
|
fobj f;
|
||||||
|
|
||||||
|
BOOST_TEST(f(element1, element2, element3) == fusion::invoke(f, seq));
|
||||||
|
BOOST_TEST(const_(f)(element1, element2, element3) == fusion::invoke<fobj const>(const_(f), seq));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence(Sequence & seq)
|
||||||
|
{
|
||||||
|
test_sequence_n(seq, mpl::int_<fusion::result_of::size<Sequence>::value>());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void result_type_tests()
|
||||||
|
{
|
||||||
|
using boost::fusion::detail::has_type;
|
||||||
|
|
||||||
|
BOOST_TEST(( has_type<
|
||||||
|
fusion::result_of::invoke<int (*)(), fusion::vector0 >
|
||||||
|
>::value ));
|
||||||
|
BOOST_TEST(( has_type<
|
||||||
|
fusion::result_of::invoke<int (*)(...), fusion::vector1<int> >
|
||||||
|
>::value ));
|
||||||
|
BOOST_TEST(( ! has_type<
|
||||||
|
fusion::result_of::invoke<int (*)(), fusion::vector1<int> >
|
||||||
|
>::value ));
|
||||||
|
BOOST_TEST(( has_type<
|
||||||
|
fusion::result_of::invoke<int (members::*)(), fusion::vector1<members*> >
|
||||||
|
>::value ));
|
||||||
|
BOOST_TEST(( has_type<
|
||||||
|
fusion::result_of::invoke<int (members::*)(...), fusion::vector2<members*,int> >
|
||||||
|
>::value ));
|
||||||
|
BOOST_TEST(( ! has_type<
|
||||||
|
fusion::result_of::invoke<int (members::*)(), fusion::vector2<members*,int> >
|
||||||
|
>::value ));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
result_type_tests();
|
||||||
|
|
||||||
|
typedef fusion::vector<> vector0;
|
||||||
|
typedef fusion::vector<element1_type> vector1;
|
||||||
|
typedef fusion::vector<element1_type, element2_type> vector2;
|
||||||
|
typedef fusion::vector<element1_type, element2_type, element3_type> vector3;
|
||||||
|
|
||||||
|
vector0 v0;
|
||||||
|
vector1 v1(element1);
|
||||||
|
vector2 v2(element1, element2);
|
||||||
|
vector3 v3(element1, element2, element3);
|
||||||
|
|
||||||
|
test_sequence(v0);
|
||||||
|
test_sequence(v1);
|
||||||
|
test_sequence(v2);
|
||||||
|
test_sequence(v3);
|
||||||
|
|
||||||
|
typedef fusion::list<> list0;
|
||||||
|
typedef fusion::list<element1_type> list1;
|
||||||
|
typedef fusion::list<element1_type, element2_type> list2;
|
||||||
|
typedef fusion::list<element1_type, element2_type, element3_type> list3;
|
||||||
|
|
||||||
|
list0 l0;
|
||||||
|
list1 l1(element1);
|
||||||
|
list2 l2(element1, element2);
|
||||||
|
list3 l3(element1, element2, element3);
|
||||||
|
|
||||||
|
test_sequence(l0);
|
||||||
|
test_sequence(l1);
|
||||||
|
test_sequence(l2);
|
||||||
|
test_sequence(l3);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
199
test/functional/invoke_function_object.cpp
Normal file
199
test/functional/invoke_function_object.cpp
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2005-2006 João Abecasis
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/invocation/invoke_function_object.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/type_traits/is_same.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/int.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/container/vector.hpp>
|
||||||
|
#include <boost/fusion/sequence/container/list.hpp>
|
||||||
|
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||||
|
#include <boost/fusion/sequence/intrinsic/begin.hpp>
|
||||||
|
#include <boost/fusion/sequence/view/single_view.hpp>
|
||||||
|
#include <boost/fusion/sequence/view/iterator_range.hpp>
|
||||||
|
#include <boost/fusion/iterator/advance.hpp>
|
||||||
|
#include <boost/fusion/algorithm/transformation/join.hpp>
|
||||||
|
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline T const & const_(T const & t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct object {};
|
||||||
|
struct object_nc : boost::noncopyable {};
|
||||||
|
|
||||||
|
struct fobj
|
||||||
|
{
|
||||||
|
template <typename T0 = void, typename T1 = void, typename T2 = void>
|
||||||
|
struct result
|
||||||
|
{
|
||||||
|
typedef int type;
|
||||||
|
};
|
||||||
|
|
||||||
|
int operator()() { return 0; }
|
||||||
|
int operator()() const { return 1; }
|
||||||
|
|
||||||
|
int operator()(int i) { return 2 + i; }
|
||||||
|
int operator()(int i) const { return 3 + i; }
|
||||||
|
|
||||||
|
int operator()(int i, object &) { return 4 + i; }
|
||||||
|
int operator()(int i, object &) const { return 5 + i; }
|
||||||
|
int operator()(int i, object const &) { return 6 + i; }
|
||||||
|
int operator()(int i, object const &) const { return 7 + i; }
|
||||||
|
|
||||||
|
int operator()(int i, object &, object_nc &) { return 10 + i; }
|
||||||
|
int operator()(int i, object &, object_nc &) const { return 11 + i; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fobj_nc
|
||||||
|
: boost::noncopyable
|
||||||
|
{
|
||||||
|
template <typename T0 = void>
|
||||||
|
struct result
|
||||||
|
{
|
||||||
|
typedef int type;
|
||||||
|
};
|
||||||
|
|
||||||
|
int operator()() { return 12; }
|
||||||
|
int operator()() const { return 13; }
|
||||||
|
|
||||||
|
int operator()(int i) { return 14 + i; }
|
||||||
|
int operator()(int i) const { return 15 + i; }
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef int element1_type;
|
||||||
|
typedef object element2_type;
|
||||||
|
typedef object_nc & element3_type;
|
||||||
|
|
||||||
|
int element1 = 100;
|
||||||
|
object element2 = object();
|
||||||
|
object_nc element3;
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<0>)
|
||||||
|
{
|
||||||
|
// Function Objects
|
||||||
|
|
||||||
|
fobj f;
|
||||||
|
BOOST_TEST(f () == fusion::invoke_function_object(f , seq ));
|
||||||
|
BOOST_TEST(f () == fusion::invoke_function_object(f , const_(seq)));
|
||||||
|
|
||||||
|
// Note: The function object is taken by value, so we request the copy
|
||||||
|
// to be const with an explicit template argument. We can also request
|
||||||
|
// the function object to be pased by reference...
|
||||||
|
BOOST_TEST(const_(f)() == fusion::invoke_function_object<fobj const >(const_(f), seq ));
|
||||||
|
BOOST_TEST(const_(f)() == fusion::invoke_function_object<fobj const &>(const_(f), const_(seq)));
|
||||||
|
|
||||||
|
fobj_nc nc_f;
|
||||||
|
// ...and we further ensure there is no copying in this case, using a
|
||||||
|
// noncopyable function object.
|
||||||
|
BOOST_TEST(nc_f () == fusion::invoke_function_object<fobj_nc &>(nc_f , seq ));
|
||||||
|
BOOST_TEST(nc_f () == fusion::invoke_function_object<fobj_nc &>(nc_f , const_(seq)));
|
||||||
|
BOOST_TEST(const_(nc_f)() == fusion::invoke_function_object<fobj_nc const &>(const_(nc_f), seq ));
|
||||||
|
BOOST_TEST(const_(nc_f)() == fusion::invoke_function_object<fobj_nc const &>(const_(nc_f), const_(seq)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<1>)
|
||||||
|
{
|
||||||
|
fobj f;
|
||||||
|
BOOST_TEST(f(element1) == fusion::invoke_function_object(f , seq ));
|
||||||
|
BOOST_TEST(f(element1) == fusion::invoke_function_object(f , const_(seq)));
|
||||||
|
BOOST_TEST(const_(f)(element1) == fusion::invoke_function_object<fobj const >(const_(f), seq ));
|
||||||
|
BOOST_TEST(const_(f)(element1) == fusion::invoke_function_object<fobj const &>(const_(f), const_(seq)));
|
||||||
|
|
||||||
|
fobj_nc nc_f;
|
||||||
|
BOOST_TEST(nc_f(element1) == fusion::invoke_function_object<fobj_nc &>(nc_f, seq ));
|
||||||
|
BOOST_TEST(nc_f(element1) == fusion::invoke_function_object<fobj_nc &>(nc_f, const_(seq)));
|
||||||
|
BOOST_TEST(const_(nc_f)(element1) == fusion::invoke_function_object<fobj_nc const &>(const_(nc_f), seq ));
|
||||||
|
BOOST_TEST(const_(nc_f)(element1) == fusion::invoke_function_object<fobj_nc const &>(const_(nc_f), const_(seq)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<2>)
|
||||||
|
{
|
||||||
|
fobj f;
|
||||||
|
BOOST_TEST(f (element1, element2) == fusion::invoke_function_object(f , seq));
|
||||||
|
BOOST_TEST(f (element1, const_(element2)) == fusion::invoke_function_object(f , const_(seq)));
|
||||||
|
BOOST_TEST(const_(f)(element1, element2) == fusion::invoke_function_object<fobj const>(const_(f), seq));
|
||||||
|
BOOST_TEST(const_(f)(element1, const_(element2)) == fusion::invoke_function_object<fobj const>(const_(f), const_(seq)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<3>)
|
||||||
|
{
|
||||||
|
fobj f;
|
||||||
|
|
||||||
|
BOOST_TEST(f(element1, element2, element3) == fusion::invoke_function_object(f, seq));
|
||||||
|
BOOST_TEST(const_(f)(element1, element2, element3) == fusion::invoke_function_object<fobj const>(const_(f), seq));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence(Sequence & seq)
|
||||||
|
{
|
||||||
|
test_sequence_n(seq, mpl::int_<fusion::result_of::size<Sequence>::value>());
|
||||||
|
}
|
||||||
|
|
||||||
|
void result_type_tests()
|
||||||
|
{
|
||||||
|
using boost::is_same;
|
||||||
|
|
||||||
|
BOOST_TEST(( is_same< fusion::result_of::invoke_function_object< fobj, fusion::vector<> >::type, int >::value ));
|
||||||
|
BOOST_TEST(( is_same< fusion::result_of::invoke_function_object< fobj, fusion::vector<element1_type> >::type, int >::value ));
|
||||||
|
BOOST_TEST(( is_same< fusion::result_of::invoke_function_object< fobj, fusion::vector<element1_type,element2_type> >::type, int >::value ));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
result_type_tests();
|
||||||
|
|
||||||
|
typedef fusion::vector<> vector0;
|
||||||
|
typedef fusion::vector<element1_type> vector1;
|
||||||
|
typedef fusion::vector<element1_type, element2_type> vector2;
|
||||||
|
typedef fusion::vector<element1_type, element2_type, element3_type> vector3;
|
||||||
|
|
||||||
|
vector0 v0;
|
||||||
|
vector1 v1(element1);
|
||||||
|
vector2 v2(element1, element2);
|
||||||
|
vector3 v3(element1, element2, element3);
|
||||||
|
|
||||||
|
test_sequence(v0);
|
||||||
|
test_sequence(v1);
|
||||||
|
test_sequence(v2);
|
||||||
|
test_sequence(v3);
|
||||||
|
|
||||||
|
typedef fusion::list<> list0;
|
||||||
|
typedef fusion::list<element1_type> list1;
|
||||||
|
typedef fusion::list<element1_type, element2_type> list2;
|
||||||
|
typedef fusion::list<element1_type, element2_type, element3_type> list3;
|
||||||
|
|
||||||
|
list0 l0;
|
||||||
|
list1 l1(element1);
|
||||||
|
list2 l2(element1, element2);
|
||||||
|
list3 l3(element1, element2, element3);
|
||||||
|
|
||||||
|
test_sequence(l0);
|
||||||
|
test_sequence(l1);
|
||||||
|
test_sequence(l2);
|
||||||
|
test_sequence(l3);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
313
test/functional/invoke_procedure.cpp
Normal file
313
test/functional/invoke_procedure.cpp
Normal file
@ -0,0 +1,313 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2005-2006 João Abecasis
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/invocation/invoke_procedure.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/functional/adapter/detail/has_type.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/int.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/container/vector.hpp>
|
||||||
|
#include <boost/fusion/sequence/container/list.hpp>
|
||||||
|
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||||
|
#include <boost/fusion/sequence/intrinsic/begin.hpp>
|
||||||
|
#include <boost/fusion/sequence/view/single_view.hpp>
|
||||||
|
#include <boost/fusion/sequence/view/iterator_range.hpp>
|
||||||
|
#include <boost/fusion/iterator/advance.hpp>
|
||||||
|
#include <boost/fusion/algorithm/transformation/join.hpp>
|
||||||
|
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline T const & const_(T const & t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct object {};
|
||||||
|
struct object_nc : boost::noncopyable {};
|
||||||
|
|
||||||
|
typedef int element1_type;
|
||||||
|
typedef object element2_type;
|
||||||
|
typedef object_nc & element3_type;
|
||||||
|
|
||||||
|
int element1 = 100;
|
||||||
|
object element2 = object();
|
||||||
|
object_nc element3;
|
||||||
|
|
||||||
|
class members
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int data;
|
||||||
|
|
||||||
|
members()
|
||||||
|
: data(20)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
int nullary() { return element1 = data + 1; }
|
||||||
|
int nullary_c() const { return element1 = data + 2; }
|
||||||
|
int unary(int & i) { return i = data + 3; }
|
||||||
|
int unary_c(int & i) const { return i = data + 4; }
|
||||||
|
int binary(int & i, object) { return i = data + 5; }
|
||||||
|
int binary_c(int & i, object) const { return i = data + 6; }
|
||||||
|
};
|
||||||
|
|
||||||
|
members that;
|
||||||
|
std::auto_ptr<members> spt_that(new members);
|
||||||
|
std::auto_ptr<members const> spt_that_c(new members);
|
||||||
|
|
||||||
|
fusion::single_view<members > sv_obj_ctx( that);
|
||||||
|
fusion::single_view<members &> sv_ref_ctx( that);
|
||||||
|
fusion::single_view<members *> sv_ptr_ctx(& that);
|
||||||
|
fusion::single_view<members const > sv_obj_c_ctx( that);
|
||||||
|
fusion::single_view<members const &> sv_ref_c_ctx( that);
|
||||||
|
fusion::single_view<members const *> sv_ptr_c_ctx(& that);
|
||||||
|
fusion::single_view<std::auto_ptr<members> const &> sv_spt_ctx(spt_that);
|
||||||
|
fusion::single_view< std::auto_ptr<members const> const &> sv_spt_c_ctx(spt_that_c);
|
||||||
|
|
||||||
|
struct fobj
|
||||||
|
{
|
||||||
|
int operator()() { return element1 = 0; }
|
||||||
|
int operator()() const { return element1 = 1; }
|
||||||
|
|
||||||
|
int operator()(int & i) { return i = 2 ; }
|
||||||
|
int operator()(int & i) const { return i = 3; }
|
||||||
|
|
||||||
|
int operator()(int & i, object &) { return i = 4; }
|
||||||
|
int operator()(int & i, object &) const { return i = 5; }
|
||||||
|
int operator()(int & i, object const &) { return i = 6; }
|
||||||
|
int operator()(int & i, object const &) const { return i = 7; }
|
||||||
|
|
||||||
|
int operator()(int & i, object &, object_nc &) { return i = 10; }
|
||||||
|
int operator()(int & i, object &, object_nc &) const { return i = 11; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fobj_nc
|
||||||
|
: boost::noncopyable
|
||||||
|
{
|
||||||
|
int operator()() { return element1 = 12; }
|
||||||
|
int operator()() const { return element1 = 13; }
|
||||||
|
|
||||||
|
int operator()(int & i) { return i = 14; }
|
||||||
|
int operator()(int & i) const { return i = 15; }
|
||||||
|
};
|
||||||
|
|
||||||
|
int nullary() { return element1 = 16; }
|
||||||
|
int unary(int & i) { return i = 17; }
|
||||||
|
int binary1(int & i, object &) { return i = 18; }
|
||||||
|
int binary2(int & i, object const &) { return i = 19; }
|
||||||
|
|
||||||
|
typedef int (* func_ptr)(int &);
|
||||||
|
typedef int (* const c_func_ptr)(int &);
|
||||||
|
typedef int (* volatile v_func_ptr)(int &);
|
||||||
|
typedef int (* const volatile cv_func_ptr)(int &);
|
||||||
|
|
||||||
|
func_ptr func_ptr1 = &unary;
|
||||||
|
c_func_ptr func_ptr2 = &unary;
|
||||||
|
v_func_ptr func_ptr3 = &unary;
|
||||||
|
cv_func_ptr func_ptr4 = &unary;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define COMPARE_EFFECT(e,t) \
|
||||||
|
{ \
|
||||||
|
element1 = 1234567; e; \
|
||||||
|
int expected = element1; \
|
||||||
|
element1 = 1234567; t; \
|
||||||
|
BOOST_TEST(expected == element1 ); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<0>)
|
||||||
|
{
|
||||||
|
// Function Objects
|
||||||
|
|
||||||
|
fobj f;
|
||||||
|
|
||||||
|
COMPARE_EFFECT(f (), fusion::invoke_procedure(f , seq ));
|
||||||
|
COMPARE_EFFECT(f (), fusion::invoke_procedure(f , const_(seq)));
|
||||||
|
|
||||||
|
// Note: The function object is taken by value, so we request the copy
|
||||||
|
// to be const with an explicit template argument. We can also request
|
||||||
|
// the function object to be pased by reference...
|
||||||
|
COMPARE_EFFECT(const_(f)(), fusion::invoke_procedure<fobj const >(const_(f), seq ));
|
||||||
|
COMPARE_EFFECT(const_(f)(), fusion::invoke_procedure<fobj const &>(const_(f), const_(seq)));
|
||||||
|
|
||||||
|
fobj_nc nc_f;
|
||||||
|
// ...and we further ensure there is no copying in this case, using a
|
||||||
|
// noncopyable function object.
|
||||||
|
COMPARE_EFFECT(nc_f (), fusion::invoke_procedure<fobj_nc &>(nc_f , seq ));
|
||||||
|
COMPARE_EFFECT(nc_f (), fusion::invoke_procedure<fobj_nc &>(nc_f , const_(seq)));
|
||||||
|
COMPARE_EFFECT(const_(nc_f)(), fusion::invoke_procedure<fobj_nc const &>(const_(nc_f), seq ));
|
||||||
|
COMPARE_EFFECT(const_(nc_f)(), fusion::invoke_procedure<fobj_nc const &>(const_(nc_f), const_(seq)));
|
||||||
|
|
||||||
|
// Builtin Functions
|
||||||
|
|
||||||
|
// Call through ref/ptr to function
|
||||||
|
COMPARE_EFFECT(nullary(), fusion::invoke_procedure<int (&)()>(nullary, seq));
|
||||||
|
COMPARE_EFFECT(nullary(), fusion::invoke_procedure(& nullary, seq));
|
||||||
|
|
||||||
|
// Call through ptr to member function
|
||||||
|
// Note: The non-const function members::nullary can't be invoked with
|
||||||
|
// fusion::join(sv_obj_ctx,seq)), which is const and so is its first element
|
||||||
|
COMPARE_EFFECT(that.nullary(), fusion::invoke_procedure(& members::nullary, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.nullary(), fusion::invoke_procedure(& members::nullary, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.nullary(), fusion::invoke_procedure(& members::nullary, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_obj_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_obj_c_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_ref_c_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_ptr_c_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_spt_c_ctx,seq)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<1>)
|
||||||
|
{
|
||||||
|
fobj f;
|
||||||
|
COMPARE_EFFECT(f(element1), fusion::invoke_procedure(f , seq ));
|
||||||
|
COMPARE_EFFECT(f(element1), fusion::invoke_procedure(f , const_(seq)));
|
||||||
|
COMPARE_EFFECT(const_(f)(element1), fusion::invoke_procedure<fobj const >(const_(f), seq ));
|
||||||
|
COMPARE_EFFECT(const_(f)(element1), fusion::invoke_procedure<fobj const &>(const_(f), const_(seq)));
|
||||||
|
|
||||||
|
fobj_nc nc_f;
|
||||||
|
COMPARE_EFFECT(nc_f(element1), fusion::invoke_procedure<fobj_nc &>(nc_f, seq ));
|
||||||
|
COMPARE_EFFECT(nc_f(element1), fusion::invoke_procedure<fobj_nc &>(nc_f, const_(seq)));
|
||||||
|
COMPARE_EFFECT(const_(nc_f)(element1), fusion::invoke_procedure<fobj_nc const &>(const_(nc_f), seq ));
|
||||||
|
COMPARE_EFFECT(const_(nc_f)(element1), fusion::invoke_procedure<fobj_nc const &>(const_(nc_f), const_(seq)));
|
||||||
|
|
||||||
|
COMPARE_EFFECT(unary(element1), fusion::invoke_procedure<int (&)(int &)>(unary, seq));
|
||||||
|
COMPARE_EFFECT(func_ptr1(element1), fusion::invoke_procedure(func_ptr1, seq));
|
||||||
|
COMPARE_EFFECT(func_ptr2(element1), fusion::invoke_procedure(func_ptr2, seq));
|
||||||
|
COMPARE_EFFECT(func_ptr3(element1), fusion::invoke_procedure(func_ptr3, seq));
|
||||||
|
COMPARE_EFFECT(func_ptr4(element1), fusion::invoke_procedure(func_ptr4, seq));
|
||||||
|
|
||||||
|
COMPARE_EFFECT(that.unary(element1), fusion::invoke_procedure(& members::unary, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.unary(element1), fusion::invoke_procedure(& members::unary, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.unary(element1), fusion::invoke_procedure(& members::unary, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_obj_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_obj_c_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_ref_c_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_ptr_c_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_spt_c_ctx,seq)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<2>)
|
||||||
|
{
|
||||||
|
fobj f;
|
||||||
|
COMPARE_EFFECT(f (element1, element2), fusion::invoke_procedure(f , seq));
|
||||||
|
COMPARE_EFFECT(f (element1, const_(element2)), fusion::invoke_procedure(f , const_(seq)));
|
||||||
|
COMPARE_EFFECT(const_(f)(element1, element2), fusion::invoke_procedure<fobj const>(const_(f), seq));
|
||||||
|
COMPARE_EFFECT(const_(f)(element1, const_(element2)), fusion::invoke_procedure<fobj const>(const_(f), const_(seq)));
|
||||||
|
|
||||||
|
COMPARE_EFFECT(binary1(element1, element2), fusion::invoke_procedure(binary1, seq));
|
||||||
|
COMPARE_EFFECT(binary2(element1, element2), fusion::invoke_procedure(binary2, seq));
|
||||||
|
|
||||||
|
COMPARE_EFFECT(that.binary(element1,element2), fusion::invoke_procedure(& members::binary, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.binary(element1,element2), fusion::invoke_procedure(& members::binary, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.binary(element1,element2), fusion::invoke_procedure(& members::binary, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_obj_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_ref_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_ptr_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_spt_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_obj_c_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_ref_c_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_ptr_c_ctx,seq)));
|
||||||
|
COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_spt_c_ctx,seq)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence_n(Sequence & seq, mpl::int_<3>)
|
||||||
|
{
|
||||||
|
fobj f;
|
||||||
|
|
||||||
|
COMPARE_EFFECT(f(element1, element2, element3), fusion::invoke_procedure(f, seq));
|
||||||
|
COMPARE_EFFECT(const_(f)(element1, element2, element3), fusion::invoke_procedure<fobj const>(const_(f), seq));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Sequence>
|
||||||
|
void test_sequence(Sequence & seq)
|
||||||
|
{
|
||||||
|
test_sequence_n(seq, mpl::int_<fusion::result_of::size<Sequence>::value>());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void result_type_tests()
|
||||||
|
{
|
||||||
|
using boost::fusion::detail::has_type;
|
||||||
|
|
||||||
|
BOOST_TEST(( has_type<
|
||||||
|
fusion::result_of::invoke_procedure<int (*)(), fusion::vector0 >
|
||||||
|
>::value ));
|
||||||
|
BOOST_TEST(( has_type<
|
||||||
|
fusion::result_of::invoke_procedure<int (*)(...), fusion::vector1<int> >
|
||||||
|
>::value ));
|
||||||
|
BOOST_TEST(( ! has_type<
|
||||||
|
fusion::result_of::invoke_procedure<int (*)(), fusion::vector1<int> >
|
||||||
|
>::value ));
|
||||||
|
BOOST_TEST(( has_type<
|
||||||
|
fusion::result_of::invoke_procedure<int (members::*)(), fusion::vector1<members*> >
|
||||||
|
>::value ));
|
||||||
|
BOOST_TEST(( has_type<
|
||||||
|
fusion::result_of::invoke_procedure<int (members::*)(...), fusion::vector2<members*,int> >
|
||||||
|
>::value ));
|
||||||
|
BOOST_TEST(( ! has_type<
|
||||||
|
fusion::result_of::invoke_procedure<int (members::*)(), fusion::vector2<members*,int> >
|
||||||
|
>::value ));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
result_type_tests();
|
||||||
|
|
||||||
|
typedef fusion::vector<> vector0;
|
||||||
|
typedef fusion::vector<element1_type &> vector1;
|
||||||
|
typedef fusion::vector<element1_type &, element2_type> vector2;
|
||||||
|
typedef fusion::vector<element1_type &, element2_type, element3_type> vector3;
|
||||||
|
|
||||||
|
vector0 v0;
|
||||||
|
vector1 v1(element1);
|
||||||
|
vector2 v2(element1, element2);
|
||||||
|
vector3 v3(element1, element2, element3);
|
||||||
|
|
||||||
|
test_sequence(v0);
|
||||||
|
test_sequence(v1);
|
||||||
|
test_sequence(v2);
|
||||||
|
test_sequence(v3);
|
||||||
|
|
||||||
|
typedef fusion::list<> list0;
|
||||||
|
typedef fusion::list<element1_type &> list1;
|
||||||
|
typedef fusion::list<element1_type &, element2_type> list2;
|
||||||
|
typedef fusion::list<element1_type &, element2_type, element3_type> list3;
|
||||||
|
|
||||||
|
list0 l0;
|
||||||
|
list1 l1(element1);
|
||||||
|
list2 l2(element1, element2);
|
||||||
|
list3 l3(element1, element2, element3);
|
||||||
|
|
||||||
|
test_sequence(l0);
|
||||||
|
test_sequence(l1);
|
||||||
|
test_sequence(l2);
|
||||||
|
test_sequence(l3);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
85
test/functional/make_fused.cpp
Normal file
85
test/functional/make_fused.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/generation/make_fused.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/generation/make_vector.hpp>
|
||||||
|
#include <boost/fusion/sequence/container/vector.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
using boost::noncopyable;
|
||||||
|
using boost::cref;
|
||||||
|
using boost::ref;
|
||||||
|
|
||||||
|
template <class Base = boost::blank>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
typedef int result_type;
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y) const
|
||||||
|
{
|
||||||
|
return 1+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y)
|
||||||
|
{
|
||||||
|
return 2+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y) const
|
||||||
|
{
|
||||||
|
return 3+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y)
|
||||||
|
{
|
||||||
|
return 4+x-y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline T const & const_(T const & t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
fusion::vector<int,char> lv_vec(1,'\004');
|
||||||
|
test_func<> f;
|
||||||
|
test_func<noncopyable> f_nc;
|
||||||
|
|
||||||
|
fusion::result_of::make_fused< test_func<> >::type fused_func
|
||||||
|
= fusion::make_fused(f);
|
||||||
|
|
||||||
|
BOOST_TEST(fused_func(lv_vec) == 1);
|
||||||
|
BOOST_TEST(const_(fused_func)(lv_vec) == 0);
|
||||||
|
BOOST_TEST(fusion::make_fused(const_(f))(lv_vec) == 1);
|
||||||
|
BOOST_TEST(fusion::make_fused(ref(f_nc))(lv_vec) == 1);
|
||||||
|
BOOST_TEST(fusion::make_fused(cref(f_nc))(lv_vec) == 0);
|
||||||
|
|
||||||
|
BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1);
|
||||||
|
BOOST_TEST(const_(fused_func)(fusion::make_vector(2,'\003')) == 0);
|
||||||
|
BOOST_TEST(fusion::make_fused(const_(f))(fusion::make_vector(2,'\003')) == 1);
|
||||||
|
BOOST_TEST(fusion::make_fused(ref(f_nc))(fusion::make_vector(2,'\003')) == 1);
|
||||||
|
BOOST_TEST(fusion::make_fused(cref(f_nc))(fusion::make_vector(2,'\003')) == 0);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
89
test/functional/make_fused_function_object.cpp
Normal file
89
test/functional/make_fused_function_object.cpp
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/generation/make_fused_function_object.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/generation/make_vector.hpp>
|
||||||
|
#include <boost/fusion/sequence/container/vector.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
using boost::noncopyable;
|
||||||
|
using boost::cref;
|
||||||
|
using boost::ref;
|
||||||
|
|
||||||
|
template <class Base = boost::blank>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
struct result
|
||||||
|
{
|
||||||
|
typedef int type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y) const
|
||||||
|
{
|
||||||
|
return 1+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y)
|
||||||
|
{
|
||||||
|
return 2+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y) const
|
||||||
|
{
|
||||||
|
return 3+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y)
|
||||||
|
{
|
||||||
|
return 4+x-y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline T const & const_(T const & t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
fusion::vector<int,char> lv_vec(1,'\004');
|
||||||
|
test_func<> f;
|
||||||
|
test_func<noncopyable> f_nc;
|
||||||
|
|
||||||
|
fusion::result_of::make_fused_function_object< test_func<> >::type fused_func
|
||||||
|
= fusion::make_fused_function_object(f);
|
||||||
|
|
||||||
|
BOOST_TEST(fused_func(lv_vec) == 1);
|
||||||
|
BOOST_TEST(const_(fused_func)(lv_vec) == 0);
|
||||||
|
BOOST_TEST(fusion::make_fused_function_object(const_(f))(lv_vec) == 1);
|
||||||
|
BOOST_TEST(fusion::make_fused_function_object(ref(f_nc))(lv_vec) == 1);
|
||||||
|
BOOST_TEST(fusion::make_fused_function_object(cref(f_nc))(lv_vec) == 0);
|
||||||
|
|
||||||
|
BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1);
|
||||||
|
BOOST_TEST(const_(fused_func)(fusion::make_vector(2,'\003')) == 0);
|
||||||
|
BOOST_TEST(fusion::make_fused_function_object(const_(f))(fusion::make_vector(2,'\003')) == 1);
|
||||||
|
BOOST_TEST(fusion::make_fused_function_object(ref(f_nc))(fusion::make_vector(2,'\003')) == 1);
|
||||||
|
BOOST_TEST(fusion::make_fused_function_object(cref(f_nc))(fusion::make_vector(2,'\003')) == 0);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
91
test/functional/make_fused_procedure.cpp
Normal file
91
test/functional/make_fused_procedure.cpp
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/generation/make_fused_procedure.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/generation/make_vector.hpp>
|
||||||
|
#include <boost/fusion/sequence/container/vector.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
using boost::noncopyable;
|
||||||
|
using boost::cref;
|
||||||
|
using boost::ref;
|
||||||
|
|
||||||
|
int effect;
|
||||||
|
|
||||||
|
#define CHECK_EFFECT(t,e) \
|
||||||
|
{ \
|
||||||
|
effect = 1234567; t; \
|
||||||
|
BOOST_TEST(effect == e); \
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Base = boost::blank>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y) const
|
||||||
|
{
|
||||||
|
return effect = 1+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 const & x, T1 const & y)
|
||||||
|
{
|
||||||
|
return effect = 2+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y) const
|
||||||
|
{
|
||||||
|
return effect = 3+x-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1>
|
||||||
|
int operator()(T0 & x, T1 & y)
|
||||||
|
{
|
||||||
|
return effect = 4+x-y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline T const & const_(T const & t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
fusion::vector<int,char> lv_vec(1,'\004');
|
||||||
|
test_func<> f;
|
||||||
|
test_func<noncopyable> f_nc;
|
||||||
|
|
||||||
|
fusion::result_of::make_fused_procedure< test_func<> >::type fused_func
|
||||||
|
= fusion::make_fused_procedure(f);
|
||||||
|
|
||||||
|
CHECK_EFFECT(fused_func(lv_vec), 1);
|
||||||
|
CHECK_EFFECT(const_(fused_func)(lv_vec), 0);
|
||||||
|
CHECK_EFFECT(fusion::make_fused_procedure(const_(f))(lv_vec), 1);
|
||||||
|
CHECK_EFFECT(fusion::make_fused_procedure(ref(f_nc))(lv_vec), 1);
|
||||||
|
CHECK_EFFECT(fusion::make_fused_procedure(cref(f_nc))(lv_vec), 0);
|
||||||
|
|
||||||
|
CHECK_EFFECT(fused_func(fusion::make_vector(2,'\003')), 1);
|
||||||
|
CHECK_EFFECT(const_(fused_func)(fusion::make_vector(2,'\003')), 0);
|
||||||
|
CHECK_EFFECT(fusion::make_fused_procedure(const_(f))(fusion::make_vector(2,'\003')), 1);
|
||||||
|
CHECK_EFFECT(fusion::make_fused_procedure(ref(f_nc))(fusion::make_vector(2,'\003')), 1);
|
||||||
|
CHECK_EFFECT(fusion::make_fused_procedure(cref(f_nc))(fusion::make_vector(2,'\003')), 0);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
123
test/functional/make_unfused_generic.cpp
Normal file
123
test/functional/make_unfused_generic.cpp
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/generation/make_unfused_generic.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/type_traits/is_same.hpp>
|
||||||
|
#include <boost/fusion/functional/adapter/detail/has_type.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/if.hpp>
|
||||||
|
#include <boost/mpl/and.hpp>
|
||||||
|
#include <boost/mpl/bool.hpp>
|
||||||
|
#include <boost/mpl/identity.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||||
|
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||||
|
|
||||||
|
#include <boost/ref.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
|
||||||
|
using boost::noncopyable;
|
||||||
|
typedef mpl::true_ no_nullary_call;
|
||||||
|
|
||||||
|
using boost::ref;
|
||||||
|
using boost::cref;
|
||||||
|
|
||||||
|
template <class Base = boost::blank, class RemoveNullary = mpl::false_>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
template <class Seq> struct result
|
||||||
|
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
|
||||||
|
boost::blank, mpl::identity<long> >::type
|
||||||
|
{ };
|
||||||
|
|
||||||
|
template <typename Seq>
|
||||||
|
long operator()(Seq const & seq) const
|
||||||
|
{
|
||||||
|
long state = 0;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Seq >
|
||||||
|
long operator()(Seq const & seq)
|
||||||
|
{
|
||||||
|
long state = 100;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct fold_op
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
long operator()(T const & elem, long value) const
|
||||||
|
{
|
||||||
|
return value + sizeof(T) * elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
long operator()(T & elem, long value) const
|
||||||
|
{
|
||||||
|
elem += sizeof(T);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1> struct result
|
||||||
|
: mpl::identity<long>
|
||||||
|
{ };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline T const & const_(T const & t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test_func<> f;
|
||||||
|
test_func<noncopyable> f_nc;
|
||||||
|
|
||||||
|
fusion::result_of::make_unfused_generic< test_func<> >::type unfused_func =
|
||||||
|
fusion::make_unfused_generic(f);
|
||||||
|
|
||||||
|
fusion::result_of::make_unfused_generic< boost::reference_wrapper<
|
||||||
|
test_func<noncopyable> > >::type unfused_func_ref =
|
||||||
|
fusion::make_unfused_generic(ref(f_nc));
|
||||||
|
|
||||||
|
fusion::result_of::make_unfused_generic< boost::reference_wrapper<
|
||||||
|
test_func<noncopyable> const> >::type unfused_func_c_ref =
|
||||||
|
fusion::make_unfused_generic(cref(f_nc));
|
||||||
|
|
||||||
|
BOOST_TEST(unfused_func() == 100);
|
||||||
|
BOOST_TEST(const_(unfused_func)() == 0);
|
||||||
|
BOOST_TEST(unfused_func_ref() == 100);
|
||||||
|
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||||
|
|
||||||
|
long lvalue = 12;
|
||||||
|
static const long expected = 1*sizeof(int) + 2*sizeof(long) + 7*sizeof(char);
|
||||||
|
BOOST_TEST(unfused_func(lvalue,lvalue,1,2l,'\007') == 100 + expected);
|
||||||
|
BOOST_TEST(lvalue == 12 + 2*sizeof(long));
|
||||||
|
BOOST_TEST(const_(unfused_func)(lvalue,lvalue,1,2l,'\007') == 0 + expected);
|
||||||
|
BOOST_TEST(lvalue == 12 + 4*sizeof(long));
|
||||||
|
BOOST_TEST(unfused_func_ref(lvalue,lvalue,1,2l,'\007') == 100 + expected);
|
||||||
|
BOOST_TEST(lvalue == 12 + 6*sizeof(long));
|
||||||
|
BOOST_TEST(unfused_func_c_ref(lvalue,lvalue,1,2l,'\007') == 0 + expected);
|
||||||
|
BOOST_TEST(lvalue == 12 + 8*sizeof(long));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
124
test/functional/make_unfused_lvalue_args.cpp
Normal file
124
test/functional/make_unfused_lvalue_args.cpp
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/generation/make_unfused_lvalue_args.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/if.hpp>
|
||||||
|
#include <boost/mpl/and.hpp>
|
||||||
|
#include <boost/mpl/bool.hpp>
|
||||||
|
#include <boost/mpl/identity.hpp>
|
||||||
|
|
||||||
|
#include <boost/utility/result_of.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||||
|
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||||
|
|
||||||
|
#include <boost/ref.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
|
||||||
|
using boost::noncopyable;
|
||||||
|
typedef mpl::true_ no_nullary_call;
|
||||||
|
|
||||||
|
using boost::ref;
|
||||||
|
using boost::cref;
|
||||||
|
|
||||||
|
template <class Base = boost::blank, class RemoveNullary = mpl::false_>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
template <class Seq> struct result
|
||||||
|
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
|
||||||
|
boost::blank, mpl::identity<long> >::type
|
||||||
|
{ };
|
||||||
|
|
||||||
|
template <typename Seq>
|
||||||
|
long operator()(Seq const & seq) const
|
||||||
|
{
|
||||||
|
long state = 0;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Seq >
|
||||||
|
long operator()(Seq const & seq)
|
||||||
|
{
|
||||||
|
long state = 100;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct fold_op
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
long operator()(T & elem, long value) const
|
||||||
|
{
|
||||||
|
elem += sizeof(T);
|
||||||
|
return value + elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1> struct result
|
||||||
|
: mpl::identity<long>
|
||||||
|
{ };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline T const & const_(T const & t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test_func<> f;
|
||||||
|
test_func<noncopyable> f_nc;
|
||||||
|
|
||||||
|
fusion::result_of::make_unfused_lvalue_args< test_func<> >::type unfused_func =
|
||||||
|
fusion::make_unfused_lvalue_args(f);
|
||||||
|
|
||||||
|
fusion::result_of::make_unfused_lvalue_args< boost::reference_wrapper<
|
||||||
|
test_func<noncopyable> > >::type unfused_func_ref =
|
||||||
|
fusion::make_unfused_lvalue_args(ref(f_nc));
|
||||||
|
|
||||||
|
fusion::result_of::make_unfused_lvalue_args< boost::reference_wrapper<
|
||||||
|
test_func<noncopyable> const> >::type unfused_func_c_ref =
|
||||||
|
fusion::make_unfused_lvalue_args(cref(f_nc));
|
||||||
|
|
||||||
|
BOOST_TEST(unfused_func() == 100);
|
||||||
|
BOOST_TEST(const_(unfused_func)() == 0);
|
||||||
|
BOOST_TEST(unfused_func_ref() == 100);
|
||||||
|
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||||
|
|
||||||
|
long lv1 = 2; int lv2 = 3l; char lv3 = '\007';
|
||||||
|
long expected;
|
||||||
|
|
||||||
|
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||||
|
BOOST_TEST(unfused_func(lv1,lv2,lv3) == 100 + expected);
|
||||||
|
BOOST_TEST(lv1 == 2+1*sizeof(lv1) && lv2 == 3+1*sizeof(lv2) && lv3 == 7+1*sizeof(lv3));
|
||||||
|
|
||||||
|
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||||
|
BOOST_TEST(const_(unfused_func)(lv1,lv2,lv3) == 0 + expected);
|
||||||
|
BOOST_TEST(lv1 == 2+2*sizeof(lv1) && lv2 == 3+2*sizeof(lv2) && lv3 == 7+2*sizeof(lv3));
|
||||||
|
|
||||||
|
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||||
|
BOOST_TEST(unfused_func_ref(lv1,lv2,lv3) == 100 + expected);
|
||||||
|
BOOST_TEST(lv1 == 2+3*sizeof(lv1) && lv2 == 3+3*sizeof(lv2) && lv3 == 7+3*sizeof(lv3));
|
||||||
|
|
||||||
|
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||||
|
BOOST_TEST(unfused_func_c_ref(lv1,lv2,lv3) == 0 + expected);
|
||||||
|
BOOST_TEST(lv1 == 2+4*sizeof(lv1) && lv2 == 3+4*sizeof(lv2) && lv3 == 7+4*sizeof(lv3));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
108
test/functional/make_unfused_rvalue_args.cpp
Normal file
108
test/functional/make_unfused_rvalue_args.cpp
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/generation/make_unfused_rvalue_args.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/if.hpp>
|
||||||
|
#include <boost/mpl/and.hpp>
|
||||||
|
#include <boost/mpl/bool.hpp>
|
||||||
|
#include <boost/mpl/identity.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||||
|
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||||
|
|
||||||
|
#include <boost/ref.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
|
||||||
|
using boost::noncopyable;
|
||||||
|
typedef mpl::true_ no_nullary_call;
|
||||||
|
|
||||||
|
using boost::ref;
|
||||||
|
using boost::cref;
|
||||||
|
|
||||||
|
template <class Base = boost::blank, class RemoveNullary = mpl::false_>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
template <class Seq> struct result
|
||||||
|
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
|
||||||
|
boost::blank, mpl::identity<long> >::type
|
||||||
|
{ };
|
||||||
|
|
||||||
|
template <typename Seq>
|
||||||
|
long operator()(Seq const & seq) const
|
||||||
|
{
|
||||||
|
long state = 0;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Seq >
|
||||||
|
long operator()(Seq const & seq)
|
||||||
|
{
|
||||||
|
long state = 100;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct fold_op
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
long operator()(T const & elem, long value) const
|
||||||
|
{
|
||||||
|
return value + sizeof(T) * elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1> struct result
|
||||||
|
: mpl::identity<long>
|
||||||
|
{ };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline T const & const_(T const & t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test_func<> f;
|
||||||
|
test_func<noncopyable> f_nc;
|
||||||
|
|
||||||
|
fusion::result_of::make_unfused_rvalue_args< test_func<> >::type unfused_func =
|
||||||
|
fusion::make_unfused_rvalue_args(f);
|
||||||
|
|
||||||
|
fusion::result_of::make_unfused_rvalue_args< boost::reference_wrapper<
|
||||||
|
test_func<noncopyable> > >::type unfused_func_ref =
|
||||||
|
fusion::make_unfused_rvalue_args(ref(f_nc));
|
||||||
|
|
||||||
|
fusion::result_of::make_unfused_rvalue_args< boost::reference_wrapper<
|
||||||
|
test_func<noncopyable> const> >::type unfused_func_c_ref =
|
||||||
|
fusion::make_unfused_rvalue_args(cref(f_nc));
|
||||||
|
|
||||||
|
BOOST_TEST(unfused_func() == 100);
|
||||||
|
BOOST_TEST(const_(unfused_func)() == 0);
|
||||||
|
BOOST_TEST(unfused_func_ref() == 100);
|
||||||
|
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||||
|
|
||||||
|
static const long expected = 1*sizeof(int) + 2*sizeof(long) + 7*sizeof(char);
|
||||||
|
BOOST_TEST(unfused_func(1,2l,'\007') == 100 + expected);
|
||||||
|
BOOST_TEST(const_(unfused_func)(1,2l,'\007') == 0 + expected);
|
||||||
|
BOOST_TEST(unfused_func_ref(1,2l,'\007') == 100 + expected);
|
||||||
|
BOOST_TEST(unfused_func_c_ref(1,2l,'\007') == 0 + expected);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
127
test/functional/unfused_generic.cpp
Normal file
127
test/functional/unfused_generic.cpp
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/adapter/unfused_generic.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/type_traits/is_same.hpp>
|
||||||
|
#include <boost/fusion/functional/adapter/detail/has_type.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/if.hpp>
|
||||||
|
#include <boost/mpl/and.hpp>
|
||||||
|
#include <boost/mpl/bool.hpp>
|
||||||
|
#include <boost/mpl/identity.hpp>
|
||||||
|
|
||||||
|
#include <boost/utility/result_of.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||||
|
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
|
||||||
|
using boost::noncopyable;
|
||||||
|
typedef mpl::true_ no_nullary_call;
|
||||||
|
|
||||||
|
template <class Base = boost::blank, class RemoveNullary = mpl::false_>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
template <class Seq> struct result
|
||||||
|
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
|
||||||
|
boost::blank, mpl::identity<long> >::type
|
||||||
|
{ };
|
||||||
|
|
||||||
|
template <typename Seq>
|
||||||
|
long operator()(Seq const & seq) const
|
||||||
|
{
|
||||||
|
long state = 0;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Seq >
|
||||||
|
long operator()(Seq const & seq)
|
||||||
|
{
|
||||||
|
long state = 100;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct fold_op
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
long operator()(T const & elem, long value) const
|
||||||
|
{
|
||||||
|
return value + sizeof(T) * elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
long operator()(T & elem, long value) const
|
||||||
|
{
|
||||||
|
elem += sizeof(T);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1> struct result
|
||||||
|
: mpl::identity<long>
|
||||||
|
{ };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
void result_type_tests()
|
||||||
|
{
|
||||||
|
using boost::is_same;
|
||||||
|
using boost::fusion::detail::has_type;
|
||||||
|
|
||||||
|
typedef fusion::unfused_generic< test_func<noncopyable, no_nullary_call> > test_func_1;
|
||||||
|
typedef fusion::unfused_generic< test_func<noncopyable> > test_func_0;
|
||||||
|
|
||||||
|
BOOST_TEST(( has_type< test_func_0::result<> >::value ));
|
||||||
|
BOOST_TEST(( has_type< test_func_1::result<int> >::value ));
|
||||||
|
BOOST_TEST(( ! has_type< test_func_1::result<> >::value ));
|
||||||
|
BOOST_TEST(( is_same< boost::result_of< test_func_0() >::type, long >::value ));
|
||||||
|
BOOST_TEST(( is_same< boost::result_of< test_func_1(int) >::type, long >::value ));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
result_type_tests();
|
||||||
|
|
||||||
|
test_func<noncopyable> f;
|
||||||
|
fusion::unfused_generic< test_func<> > unfused_func;
|
||||||
|
fusion::unfused_generic< test_func<noncopyable> & > unfused_func_ref(f);
|
||||||
|
fusion::unfused_generic< test_func<> const > unfused_func_c;
|
||||||
|
fusion::unfused_generic< test_func<> > const unfused_func_c2;
|
||||||
|
fusion::unfused_generic< test_func<noncopyable> const & > unfused_func_c_ref(f);
|
||||||
|
|
||||||
|
BOOST_TEST(unfused_func() == 100);
|
||||||
|
BOOST_TEST(unfused_func_ref() == 100);
|
||||||
|
BOOST_TEST(unfused_func_c() == 0);
|
||||||
|
BOOST_TEST(unfused_func_c2() == 0);
|
||||||
|
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||||
|
|
||||||
|
long lvalue = 12;
|
||||||
|
static const long expected = 1*sizeof(int) + 2*sizeof(long) + 7*sizeof(char);
|
||||||
|
BOOST_TEST(unfused_func(lvalue,lvalue,1,2l,'\007') == 100 + expected);
|
||||||
|
BOOST_TEST(lvalue == 12 + 2*sizeof(long));
|
||||||
|
BOOST_TEST(unfused_func_ref(lvalue,lvalue,1,2l,'\007') == 100 + expected);
|
||||||
|
BOOST_TEST(lvalue == 12 + 4*sizeof(long));
|
||||||
|
BOOST_TEST(unfused_func_c(lvalue,lvalue,1,2l,'\007') == 0 + expected);
|
||||||
|
BOOST_TEST(lvalue == 12 + 6*sizeof(long));
|
||||||
|
BOOST_TEST(unfused_func_c2(lvalue,lvalue,1,2l,'\007') == 0 + expected);
|
||||||
|
BOOST_TEST(lvalue == 12 + 8*sizeof(long));
|
||||||
|
BOOST_TEST(unfused_func_c_ref(lvalue,lvalue,1,2l,'\007') == 0 + expected);
|
||||||
|
BOOST_TEST(lvalue == 12 + 10*sizeof(long));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
128
test/functional/unfused_lvalue_args.cpp
Normal file
128
test/functional/unfused_lvalue_args.cpp
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/adapter/unfused_lvalue_args.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/if.hpp>
|
||||||
|
#include <boost/mpl/and.hpp>
|
||||||
|
#include <boost/mpl/bool.hpp>
|
||||||
|
#include <boost/mpl/identity.hpp>
|
||||||
|
|
||||||
|
#include <boost/utility/result_of.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||||
|
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
|
||||||
|
using boost::noncopyable;
|
||||||
|
typedef mpl::true_ no_nullary_call;
|
||||||
|
|
||||||
|
template <class Base = boost::blank, class RemoveNullary = mpl::false_>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
template <class Seq> struct result
|
||||||
|
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
|
||||||
|
boost::blank, mpl::identity<long> >::type
|
||||||
|
{ };
|
||||||
|
|
||||||
|
template <typename Seq>
|
||||||
|
long operator()(Seq const & seq) const
|
||||||
|
{
|
||||||
|
long state = 0;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Seq >
|
||||||
|
long operator()(Seq const & seq)
|
||||||
|
{
|
||||||
|
long state = 100;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct fold_op
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
long operator()(T & elem, long value) const
|
||||||
|
{
|
||||||
|
elem += sizeof(T);
|
||||||
|
return value + elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1> struct result
|
||||||
|
: mpl::identity<long>
|
||||||
|
{ };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
void result_type_tests()
|
||||||
|
{
|
||||||
|
using boost::is_same;
|
||||||
|
using boost::fusion::detail::has_type;
|
||||||
|
|
||||||
|
typedef fusion::unfused_lvalue_args< test_func<noncopyable, no_nullary_call> > test_func_1;
|
||||||
|
typedef fusion::unfused_lvalue_args< test_func<noncopyable> > test_func_0;
|
||||||
|
|
||||||
|
BOOST_TEST(( has_type< test_func_0::result<> >::value ));
|
||||||
|
BOOST_TEST(( has_type< test_func_1::result<int> >::value ));
|
||||||
|
BOOST_TEST(( ! has_type< test_func_1::result<> >::value ));
|
||||||
|
BOOST_TEST(( is_same< boost::result_of< test_func_0() >::type, long >::value ));
|
||||||
|
BOOST_TEST(( is_same< boost::result_of< test_func_1(int) >::type, long >::value ));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
result_type_tests();
|
||||||
|
|
||||||
|
test_func<noncopyable> f;
|
||||||
|
fusion::unfused_lvalue_args< test_func<> > unfused_func;
|
||||||
|
fusion::unfused_lvalue_args< test_func<noncopyable> & > unfused_func_ref(f);
|
||||||
|
fusion::unfused_lvalue_args< test_func<> const > unfused_func_c;
|
||||||
|
fusion::unfused_lvalue_args< test_func<> > const unfused_func_c2;
|
||||||
|
fusion::unfused_lvalue_args< test_func<noncopyable> const & > unfused_func_c_ref(f);
|
||||||
|
|
||||||
|
BOOST_TEST(unfused_func() == 100);
|
||||||
|
BOOST_TEST(unfused_func_ref() == 100);
|
||||||
|
BOOST_TEST(unfused_func_c() == 0);
|
||||||
|
BOOST_TEST(unfused_func_c2() == 0);
|
||||||
|
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||||
|
|
||||||
|
long lv1 = 2; int lv2 = 3l; char lv3 = '\007';
|
||||||
|
long expected;
|
||||||
|
|
||||||
|
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||||
|
BOOST_TEST(unfused_func(lv1,lv2,lv3) == 100 + expected);
|
||||||
|
BOOST_TEST(lv1 == 2+1*sizeof(lv1) && lv2 == 3+1*sizeof(lv2) && lv3 == 7+1*sizeof(lv3));
|
||||||
|
|
||||||
|
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||||
|
BOOST_TEST(unfused_func_ref(lv1,lv2,lv3) == 100 + expected);
|
||||||
|
BOOST_TEST(lv1 == 2+2*sizeof(lv1) && lv2 == 3+2*sizeof(lv2) && lv3 == 7+2*sizeof(lv3));
|
||||||
|
|
||||||
|
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||||
|
BOOST_TEST(unfused_func_c(lv1,lv2,lv3) == 0 + expected);
|
||||||
|
BOOST_TEST(lv1 == 2+3*sizeof(lv1) && lv2 == 3+3*sizeof(lv2) && lv3 == 7+3*sizeof(lv3));
|
||||||
|
|
||||||
|
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||||
|
BOOST_TEST(unfused_func_c2(lv1,lv2,lv3) == 0 + expected);
|
||||||
|
BOOST_TEST(lv1 == 2+4*sizeof(lv1) && lv2 == 3+4*sizeof(lv2) && lv3 == 7+4*sizeof(lv3));
|
||||||
|
|
||||||
|
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||||
|
BOOST_TEST(unfused_func_c_ref(lv1,lv2,lv3) == 0 + expected);
|
||||||
|
BOOST_TEST(lv1 == 2+5*sizeof(lv1) && lv2 == 3+5*sizeof(lv2) && lv3 == 7+5*sizeof(lv3));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
111
test/functional/unfused_rvalue_args.cpp
Normal file
111
test/functional/unfused_rvalue_args.cpp
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/adapter/unfused_rvalue_args.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/if.hpp>
|
||||||
|
#include <boost/mpl/and.hpp>
|
||||||
|
#include <boost/mpl/bool.hpp>
|
||||||
|
#include <boost/mpl/identity.hpp>
|
||||||
|
|
||||||
|
#include <boost/utility/result_of.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||||
|
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
|
||||||
|
using boost::noncopyable;
|
||||||
|
typedef mpl::true_ no_nullary_call;
|
||||||
|
|
||||||
|
template <class Base = boost::blank, class RemoveNullary = mpl::false_>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
template <class Seq> struct result
|
||||||
|
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
|
||||||
|
boost::blank, mpl::identity<long> >::type
|
||||||
|
{ };
|
||||||
|
|
||||||
|
template <typename Seq>
|
||||||
|
long operator()(Seq const & seq) const
|
||||||
|
{
|
||||||
|
long state = 0;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Seq >
|
||||||
|
long operator()(Seq const & seq)
|
||||||
|
{
|
||||||
|
long state = 100;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct fold_op
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
long operator()(T const & elem, long value) const
|
||||||
|
{
|
||||||
|
return value + sizeof(T) * elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1> struct result
|
||||||
|
: mpl::identity<long>
|
||||||
|
{ };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
void result_type_tests()
|
||||||
|
{
|
||||||
|
using boost::is_same;
|
||||||
|
using boost::fusion::detail::has_type;
|
||||||
|
|
||||||
|
typedef fusion::unfused_rvalue_args< test_func<noncopyable, no_nullary_call> > test_func_1;
|
||||||
|
typedef fusion::unfused_rvalue_args< test_func<noncopyable> > test_func_0;
|
||||||
|
|
||||||
|
BOOST_TEST(( has_type< test_func_0::result<> >::value ));
|
||||||
|
BOOST_TEST(( has_type< test_func_1::result<int> >::value ));
|
||||||
|
BOOST_TEST(( ! has_type< test_func_1::result<> >::value ));
|
||||||
|
BOOST_TEST(( is_same< boost::result_of< test_func_0() >::type, long >::value ));
|
||||||
|
BOOST_TEST(( is_same< boost::result_of< test_func_1(int) >::type, long >::value ));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
result_type_tests();
|
||||||
|
|
||||||
|
test_func<noncopyable> f;
|
||||||
|
fusion::unfused_rvalue_args< test_func<> > unfused_func;
|
||||||
|
fusion::unfused_rvalue_args< test_func<noncopyable> & > unfused_func_ref(f);
|
||||||
|
fusion::unfused_rvalue_args< test_func<> const > unfused_func_c;
|
||||||
|
fusion::unfused_rvalue_args< test_func<> > const unfused_func_c2;
|
||||||
|
fusion::unfused_rvalue_args< test_func<noncopyable> const & > unfused_func_c_ref(f);
|
||||||
|
|
||||||
|
BOOST_TEST(unfused_func() == 100);
|
||||||
|
BOOST_TEST(unfused_func_ref() == 100);
|
||||||
|
BOOST_TEST(unfused_func_c() == 0);
|
||||||
|
BOOST_TEST(unfused_func_c2() == 0);
|
||||||
|
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||||
|
|
||||||
|
static const long expected = 1*sizeof(int) + 2*sizeof(long) + 7*sizeof(char);
|
||||||
|
BOOST_TEST(unfused_func(1,2l,'\007') == 100 + expected);
|
||||||
|
BOOST_TEST(unfused_func_ref(1,2l,'\007') == 100 + expected);
|
||||||
|
BOOST_TEST(unfused_func_c(1,2l,'\007') == 0 + expected);
|
||||||
|
BOOST_TEST(unfused_func_c2(1,2l,'\007') == 0 + expected);
|
||||||
|
BOOST_TEST(unfused_func_c_ref(1,2l,'\007') == 0 + expected);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
145
test/functional/unfused_typed.cpp
Normal file
145
test/functional/unfused_typed.cpp
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2006-2007 Tobias Schwinger
|
||||||
|
|
||||||
|
Use modification and distribution are 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/fusion/functional/adapter/unfused_typed.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/blank.hpp>
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
|
#include <boost/utility/result_of.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/if.hpp>
|
||||||
|
#include <boost/mpl/apply.hpp>
|
||||||
|
#include <boost/mpl/vector.hpp>
|
||||||
|
#include <boost/mpl/identity.hpp>
|
||||||
|
#include <boost/mpl/equal_to.hpp>
|
||||||
|
|
||||||
|
#include <boost/utility/result_of.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||||
|
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||||
|
|
||||||
|
namespace fusion = boost::fusion;
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
using mpl::placeholders::_;
|
||||||
|
|
||||||
|
using boost::noncopyable;
|
||||||
|
|
||||||
|
typedef fusion::vector<long &,int,char> types;
|
||||||
|
|
||||||
|
typedef mpl::always< mpl::true_ > unconstrained;
|
||||||
|
|
||||||
|
typedef mpl::equal_to< fusion::result_of::size<_>,
|
||||||
|
fusion::result_of::size<types> > non_variadic;
|
||||||
|
|
||||||
|
template <class Base = boost::blank, class Validation = unconstrained>
|
||||||
|
struct test_func
|
||||||
|
: Base
|
||||||
|
{
|
||||||
|
template <class Seq> struct result
|
||||||
|
: mpl::if_< typename mpl::apply<Validation, Seq>::type,
|
||||||
|
mpl::identity<long>, boost::blank >::type
|
||||||
|
{ };
|
||||||
|
|
||||||
|
template <typename Seq>
|
||||||
|
long operator()(Seq const & seq) const
|
||||||
|
{
|
||||||
|
long state = 0;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Seq >
|
||||||
|
long operator()(Seq const & seq)
|
||||||
|
{
|
||||||
|
long state = 100;
|
||||||
|
return fusion::fold(seq, state, fold_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct fold_op
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
long operator()(T const & elem, long value) const
|
||||||
|
{
|
||||||
|
return value + sizeof(T) * elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
long operator()(T & elem, long value) const
|
||||||
|
{
|
||||||
|
elem += sizeof(T);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T0, typename T1> struct result
|
||||||
|
: mpl::identity<long>
|
||||||
|
{ };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
void result_type_tests()
|
||||||
|
{
|
||||||
|
using boost::is_same;
|
||||||
|
using boost::fusion::detail::has_type;
|
||||||
|
|
||||||
|
typedef fusion::unfused_typed< test_func<noncopyable, non_variadic>, types > test_func_3;
|
||||||
|
typedef fusion::unfused_typed< test_func<noncopyable>, types > test_func_0;
|
||||||
|
|
||||||
|
BOOST_TEST(( has_type< test_func_0::result<> >::value ));
|
||||||
|
BOOST_TEST(( has_type< test_func_3::result<long &, int, char> >::value ));
|
||||||
|
BOOST_TEST(( ! has_type< test_func_3::result<> >::value ));
|
||||||
|
BOOST_TEST(( is_same< boost::result_of< test_func_0() >::type, long >::value ));
|
||||||
|
BOOST_TEST(( is_same< boost::result_of< test_func_3(long &, int, char) >::type, long >::value ));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
result_type_tests();
|
||||||
|
|
||||||
|
test_func<noncopyable> f;
|
||||||
|
fusion::unfused_typed< test_func<>, types > unfused_func;
|
||||||
|
fusion::unfused_typed< test_func<noncopyable> &, types > unfused_func_ref(f);
|
||||||
|
fusion::unfused_typed< test_func<> const, types > unfused_func_c;
|
||||||
|
fusion::unfused_typed< test_func<>, types > const unfused_func_c2;
|
||||||
|
fusion::unfused_typed< test_func<noncopyable> const &, types > unfused_func_c_ref(f);
|
||||||
|
|
||||||
|
BOOST_TEST(unfused_func() == 100);
|
||||||
|
BOOST_TEST(unfused_func_ref() == 100);
|
||||||
|
BOOST_TEST(unfused_func_c() == 0);
|
||||||
|
BOOST_TEST(unfused_func_c2() == 0);
|
||||||
|
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||||
|
|
||||||
|
long lvalue = 1;
|
||||||
|
BOOST_TEST(unfused_func(lvalue) == 100);
|
||||||
|
BOOST_TEST(lvalue == 1 + 1*sizeof(lvalue));
|
||||||
|
BOOST_TEST(unfused_func_ref(lvalue) == 100);
|
||||||
|
BOOST_TEST(lvalue == 1 + 2*sizeof(lvalue));
|
||||||
|
BOOST_TEST(unfused_func_c(lvalue) == 0);
|
||||||
|
BOOST_TEST(lvalue == 1 + 3*sizeof(lvalue));
|
||||||
|
BOOST_TEST(unfused_func_c2(lvalue) == 0);
|
||||||
|
BOOST_TEST(lvalue == 1 + 4*sizeof(lvalue));
|
||||||
|
BOOST_TEST(unfused_func_c_ref(lvalue) == 0);
|
||||||
|
BOOST_TEST(lvalue == 1 + 5*sizeof(lvalue));
|
||||||
|
|
||||||
|
static const long expected = 2*sizeof(int) + 7*sizeof(char);
|
||||||
|
BOOST_TEST(unfused_func(lvalue,2,'\007') == 100 + expected);
|
||||||
|
BOOST_TEST(lvalue == 1 + 6*sizeof(lvalue));
|
||||||
|
BOOST_TEST(unfused_func_ref(lvalue,2,'\007') == 100 + expected);
|
||||||
|
BOOST_TEST(lvalue == 1 + 7*sizeof(lvalue));
|
||||||
|
BOOST_TEST(unfused_func_c(lvalue,2,'\007') == 0 + expected);
|
||||||
|
BOOST_TEST(lvalue == 1 + 8*sizeof(lvalue));
|
||||||
|
BOOST_TEST(unfused_func_c2(lvalue,2,'\007') == 0 + expected);
|
||||||
|
BOOST_TEST(lvalue == 1 + 9*sizeof(lvalue));
|
||||||
|
BOOST_TEST(unfused_func_c_ref(lvalue,2,'\007') == 0 + expected);
|
||||||
|
BOOST_TEST(lvalue == 1 + 10*sizeof(lvalue));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user