result_of and polymorphic function obj compatibility

[SVN r37962]
This commit is contained in:
Dan Marsden
2007-06-11 07:01:05 +00:00
parent 414b87dbdb
commit 0fcbc5b467
42 changed files with 477 additions and 410 deletions

View File

@ -11,6 +11,7 @@
#include <boost/fusion/iterator/value_of.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/distance.hpp>
#include <boost/utility/result_of.hpp>
namespace boost { namespace fusion {
namespace result_of
@ -25,14 +26,13 @@ namespace detail
{
template <typename Value, typename State>
struct apply
{
typedef typename F::template result<Value, State>::type type;
};
: boost::result_of<F(Value,State)>
{};
};
template <typename Iterator, typename State, typename F>
struct fold_apply
: mpl::apply<apply_fold_result<F>, typename result_of::value_of<Iterator>::type, State>
: boost::result_of<F(typename result_of::value_of<Iterator>::type, State)>
{};
template <typename First, typename Last, typename State, typename F>

View File

@ -43,16 +43,19 @@ namespace boost { namespace fusion { namespace detail
replacer(T const& old_value, T const& new_value)
: old_value(old_value), new_value(new_value) {}
template <typename U>
struct result
template<typename Params>
struct result;
template <typename U1, typename U2>
struct result<replacer<U1>(U2)>
{
typedef typename
mpl::if_<is_convertible<T, U>, U, U const&>::type
mpl::if_<is_convertible<T, U2>, U2, U2 const&>::type
type;
};
template <typename U>
typename result<U>::type
typename result<replacer(U)>::type
operator()(U const& x) const
{
return replacer_helper<is_convertible<T, U>::value>::

View File

@ -43,8 +43,11 @@ namespace boost { namespace fusion { namespace detail
replacer_if(F f, T const& new_value)
: f(f), new_value(new_value) {}
template <typename U>
struct result
template<typename Params>
struct result;
template <typename F1, typename T1, typename U>
struct result<replacer_if<F1, T1>(U)>
{
typedef typename
mpl::if_<is_convertible<T, U>, U, U const&>::type
@ -52,7 +55,7 @@ namespace boost { namespace fusion { namespace detail
};
template <typename U>
typename result<U>::type
typename result<replacer_if(U)>::type
operator()(U const& x) const
{
return replacer_if_helper<is_convertible<T, U>::value>::

View File

@ -1,102 +0,0 @@
/*=============================================================================
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).
==============================================================================*/
// No include guard - this file is included multiple times intentionally.
#if !defined(BOOST_PP_IS_ITERATING)
# if !defined(BOOST_FUSION_FUNCTIONAL_ADAPTER_DETAIL_GEN_RESULT_OF_SPEC_HPP_INCLUDED)
# include <boost/preprocessor/iteration/iterate.hpp>
# include <boost/preprocessor/repetition/enum_params.hpp>
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
# include <boost/preprocessor/facilities/intercept.hpp>
# include <boost/utility/result_of.hpp>
# include <boost/fusion/functional/adapter/detail/access.hpp>
# define BOOST_FUSION_FUNCTIONAL_ADAPTER_DETAIL_GEN_RESULT_OF_SPEC_HPP_INCLUDED
# endif
# if !defined(BOOST_FUSION_CLASS_TPL_PARAMS)
# error "BOOST_FUSION_CLASS_TPL_PARAMS undefined"
# endif
# if !defined(BOOST_FUSION_CLASS_TPL_SPEC)
# error "BOOST_FUSION_CLASS_TPL_SPEC undefined"
# endif
# if !defined(BOOST_FUSION_FUNC_OBJ_ARITY)
# define BOOST_PP_ITERATION_LIMITS (1,1)
# else
# define BOOST_PP_ITERATION_LIMITS (0,BOOST_FUSION_FUNC_OBJ_ARITY)
# endif
# define BOOST_PP_FILENAME_1 \
<boost/fusion/functional/adapter/detail/gen_result_of_spec.hpp>
namespace boost
{
#include BOOST_PP_ITERATE()
}
# undef BOOST_FUSION_CLASS_TPL_PARAMS
# undef BOOST_FUSION_CLASS_TPL_SPEC
# if defined(BOOST_FUSION_FUNC_OBJ_ARITY)
# undef BOOST_FUSION_FUNC_OBJ_ARITY
# endif
#else // defined(BOOST_PP_IS_ITERATING)
///////////////////////////////////////////////////////////////////////////////
//
// Preprocessor vertical repetition code
//
///////////////////////////////////////////////////////////////////////////////
# define N BOOST_PP_ITERATION()
template< BOOST_FUSION_CLASS_TPL_PARAMS
BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A) >
struct result_of< BOOST_FUSION_CLASS_TPL_SPEC (BOOST_PP_ENUM_PARAMS(N,A)) >
{
typedef typename BOOST_FUSION_CLASS_TPL_SPEC ::template result
<BOOST_PP_ENUM_BINARY_PARAMS(N, typename fusion::detail::r2fp<A,
>::type BOOST_PP_INTERCEPT)>::type type;
};
template< BOOST_FUSION_CLASS_TPL_PARAMS
BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A) >
struct result_of< BOOST_FUSION_CLASS_TPL_SPEC & (BOOST_PP_ENUM_PARAMS(N,A)) >
{
typedef typename BOOST_FUSION_CLASS_TPL_SPEC ::template result
<BOOST_PP_ENUM_BINARY_PARAMS(N, typename fusion::detail::r2fp<A,
>::type BOOST_PP_INTERCEPT)>::type type;
};
template< BOOST_FUSION_CLASS_TPL_PARAMS
BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A) >
struct result_of< BOOST_FUSION_CLASS_TPL_SPEC const (BOOST_PP_ENUM_PARAMS(N,A)) >
{
typedef typename BOOST_FUSION_CLASS_TPL_SPEC ::template result
<BOOST_PP_ENUM_BINARY_PARAMS(N, typename fusion::detail::r2fp<A,
>::type BOOST_PP_INTERCEPT)>::type type;
};
template< BOOST_FUSION_CLASS_TPL_PARAMS
BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A) >
struct result_of< BOOST_FUSION_CLASS_TPL_SPEC const & (BOOST_PP_ENUM_PARAMS(N,A)) >
{
typedef typename BOOST_FUSION_CLASS_TPL_SPEC ::template result
<BOOST_PP_ENUM_BINARY_PARAMS(N, typename fusion::detail::r2fp<A,
>::type BOOST_PP_INTERCEPT)>::type type;
};
# undef N
#endif

View File

@ -12,17 +12,21 @@
#include <boost/blank.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/fusion/sequence/container/vector/vector10.hpp>
#include <boost/fusion/functional/adapter/detail/has_type.hpp>
#include <boost/utility/result_of.hpp>
namespace boost { namespace fusion { namespace detail
{
struct reserved { };
template <class Derived, class Function, bool Enable = detail::has_type<
typename remove_reference<Function>::type
::template result<fusion::vector0> >::value>
::template result<
typename remove_const<typename remove_reference<Function>::type>::type(fusion::vector0)> >::value>
struct nullary_call_base
{
template <typename T> inline void operator()(T reserved::*) const { }
@ -34,19 +38,19 @@ namespace boost { namespace fusion { namespace detail
struct nullary_call_base<Derived,Function,true>
{
private:
typedef typename remove_reference<Function>::type function;
typedef typename remove_const<typename remove_reference<Function>::type>::type function;
protected:
typedef typename function::template result<fusion::vector0> r0;
typedef typename function::template result<function(vector0)> r0;
public:
inline typename function::template result<fusion::vector0>::type
inline typename r0::type
operator()() const
{
fusion::vector0 arg;
return static_cast<Derived const *>(this)->fnc_transformed(arg);
}
inline typename function::template result<fusion::vector0>::type
inline typename r0::type
operator()()
{
fusion::vector0 arg;

View File

@ -12,17 +12,21 @@
#include <boost/blank.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/fusion/sequence/container/vector/vector10.hpp>
#include <boost/fusion/functional/adapter/detail/has_type.hpp>
#include <boost/utility/result_of.hpp>
namespace boost { namespace fusion { namespace detail
{
struct reserved { };
template <class Derived, class Function, bool Enable = detail::has_type<
typename remove_reference<Function>::type
::template result<fusion::vector0> >::value>
::template result<
typename remove_const<typename remove_reference<Function>::type>::type(fusion::vector0)> >::value>
struct nullary_call_base
{
template <typename T> inline void operator()(T reserved::*) const { }
@ -34,19 +38,19 @@ namespace boost { namespace fusion { namespace detail
struct nullary_call_base<Derived,Function,true>
{
private:
typedef typename remove_reference<Function>::type function;
typedef typename remove_const<typename remove_reference<Function>::type>::type function;
protected:
typedef typename function::template result<fusion::vector0> r0;
typedef typename function::template result<function(vector0)> r0;
public:
inline typename function::template result<fusion::vector0>::type
inline typename r0::type
operator()() const
{
fusion::vector0 arg;
return static_cast<Derived const *>(this)->fnc_transformed(arg);
}
inline typename function::template result<fusion::vector0>::type
inline typename r0::type
operator()()
{
fusion::vector0 arg;

View File

@ -62,17 +62,16 @@ namespace boost { namespace fusion
return fusion::invoke<func_fwd_t>(this->fnc_transformed,s);
}
template <class Seq>
struct result
template<typename T>
struct result;
template <typename Func, class Seq>
struct result<fused<Func>(Seq)>
: result_of::invoke<Function,Seq>
{ };
};
}}
#define BOOST_FUSION_CLASS_TPL_PARAMS typename F
#define BOOST_FUSION_CLASS_TPL_SPEC fusion::fused<F>
#include <boost/fusion/functional/adapter/detail/gen_result_of_spec.hpp>
#endif

View File

@ -67,17 +67,16 @@ namespace boost { namespace fusion
func_fwd_t >(this->fnc_transformed,s);
}
template <class Seq>
struct result
template<typename T>
struct result;
template <typename Seq>
struct result<fused_function_object(Seq)>
: result_of::invoke_function_object<Function, Seq>
{ };
};
}}
#define BOOST_FUSION_CLASS_TPL_PARAMS typename F
#define BOOST_FUSION_CLASS_TPL_SPEC fusion::fused_function_object<F>
#include <boost/fusion/functional/adapter/detail/gen_result_of_spec.hpp>
#endif

View File

@ -33,7 +33,8 @@ namespace boost { namespace fusion
struct void_;
template <class Function> class unfused_generic
template <class Function>
class unfused_generic
: public detail::nullary_call_base<unfused_generic<Function>, Function>
{
Function fnc_transformed;
@ -44,7 +45,7 @@ namespace boost { namespace fusion
typedef detail::nullary_call_base<
fusion::unfused_generic<Function>, Function > base;
typedef typename boost::remove_reference<Function>::type function;
typedef typename remove_const<typename boost::remove_reference<Function>::type>::type function;
typedef typename detail::call_param<Function>::type func_const_fwd_t;
public:
@ -55,32 +56,26 @@ namespace boost { namespace fusion
using base::operator();
template <
BOOST_PP_ENUM_BINARY_PARAMS(BOOST_FUSION_UNFUSED_GENERIC_MAX_ARITY,
typename T, = fusion::void_ BOOST_PP_INTERCEPT),
class _ = fusion::void_
>
template <typename T>
struct result;
template <class _>
struct result<
BOOST_PP_ENUM_PARAMS(BOOST_FUSION_UNFUSED_GENERIC_MAX_ARITY,
fusion::void_ BOOST_PP_INTERCEPT),_>
template <typename Func>
struct result<unfused_generic<Func>()>
: base::r0
{ };
#define BOOST_FUSION_CODE(tpl_params,arg_types,params,args) \
template <tpl_params> \
inline typename function::template result< \
BOOST_PP_CAT(fusion::vector,N)<arg_types> >::type \
inline typename function::template result<function( \
BOOST_PP_CAT(fusion::vector,N)<arg_types>)>::type \
operator()(params) const \
{ \
BOOST_PP_CAT(fusion::vector,N)<arg_types> arg(args); \
return this->fnc_transformed(arg); \
} \
template <tpl_params> \
inline typename function::template result< \
BOOST_PP_CAT(fusion::vector,N)<arg_types> >::type \
inline typename function::template result<function( \
BOOST_PP_CAT(fusion::vector,N)<arg_types>)>::type \
operator()(params) \
{ \
BOOST_PP_CAT(fusion::vector,N)<arg_types> arg(args); \
@ -100,10 +95,14 @@ namespace boost { namespace fusion
};
}}
#define BOOST_FUSION_CLASS_TPL_PARAMS class F
#define BOOST_FUSION_CLASS_TPL_SPEC fusion::unfused_generic<F>
#define BOOST_FUSION_FUNC_OBJ_ARITY BOOST_FUSION_UNFUSED_GENERIC_MAX_ARITY
#include <boost/fusion/functional/adapter/detail/gen_result_of_spec.hpp>
namespace boost {
template<typename Func>
struct result_of<boost::fusion::unfused_generic<Func>()>
{
typedef boost::fusion::unfused_generic<Func> function;
typedef typename function::template result<function()>::type type;
};
}
#define BOOST_FUSION_FUNCTIONAL_ADAPTER_UNFUSED_GENERIC_HPP_INCLUDED
#else // defined(BOOST_PP_IS_ITERATING)
@ -116,17 +115,12 @@ namespace boost { namespace fusion
#include <boost/fusion/functional/adapter/detail/pt_def.hpp>
#if BOOST_PP_SLOT_1() == 0
template <BOOST_PP_ENUM_PARAMS(N,typename T), class _>
template <typename Func, BOOST_PP_ENUM_PARAMS(N,typename T)>
struct result
#if N < BOOST_FUSION_UNFUSED_GENERIC_MAX_ARITY
< BOOST_PP_ENUM_PARAMS(N,T),
BOOST_PP_ENUM_PARAMS(
BOOST_PP_SUB(BOOST_FUSION_UNFUSED_GENERIC_MAX_ARITY,N),
fusion::void_ BOOST_PP_INTERCEPT), _ >
#endif
: function::template result< BOOST_PP_CAT(fusion::vector,N)<
<unfused_generic<Func>(BOOST_PP_ENUM_PARAMS(N,T))>
: function::template result<function(BOOST_PP_CAT(fusion::vector,N)<
BOOST_PP_ENUM_BINARY_PARAMS(N,typename detail::gref<T,>::type
BOOST_PP_INTERCEPT) > >
BOOST_PP_INTERCEPT) >)>
{ };
#endif

View File

@ -16,6 +16,7 @@
#include <boost/preprocessor/facilities/intercept.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
@ -43,7 +44,7 @@ namespace boost { namespace fusion
typedef detail::nullary_call_base<
fusion::unfused_lvalue_args<Function>, Function > base;
typedef typename boost::remove_reference<Function>::type function;
typedef typename remove_const<typename boost::remove_reference<Function>::type>::type function;
typedef typename detail::call_param<Function>::type func_const_fwd_t;
public:
@ -54,17 +55,11 @@ namespace boost { namespace fusion
using base::operator();
template <
BOOST_PP_ENUM_BINARY_PARAMS(
BOOST_FUSION_UNFUSED_LVALUE_ARGS_MAX_ARITY,
typename T, = fusion::void_ BOOST_PP_INTERCEPT ),
class _ = fusion::void_ >
template <typename T>
struct result;
template <typename _>
struct result<BOOST_PP_ENUM_PARAMS(
BOOST_FUSION_UNFUSED_LVALUE_ARGS_MAX_ARITY,
fusion::void_ BOOST_PP_INTERCEPT ), _ >
template <typename Func>
struct result<unfused_lvalue_args<Func>()>
: base::r0
{ };
@ -76,10 +71,14 @@ namespace boost { namespace fusion
};
}}
#define BOOST_FUSION_CLASS_TPL_PARAMS class F
#define BOOST_FUSION_CLASS_TPL_SPEC fusion::unfused_lvalue_args<F>
#define BOOST_FUSION_FUNC_OBJ_ARITY BOOST_FUSION_UNFUSED_LVALUE_ARGS_MAX_ARITY
#include <boost/fusion/functional/adapter/detail/gen_result_of_spec.hpp>
namespace boost {
template<typename Func>
struct result_of<boost::fusion::unfused_lvalue_args<Func>()>
{
typedef boost::fusion::unfused_lvalue_args<Func> function;
typedef typename function::template result<function()>::type type;
};
}
#define BOOST_FUSION_FUNCTIONAL_ADAPTER_UNFUSED_LVALUE_ARGS_HPP_INCLUDED
#else // defined(BOOST_PP_IS_ITERATING)
@ -90,22 +89,17 @@ namespace boost { namespace fusion
////////////////////////////////////////////////////////////////////////////////
#define N BOOST_PP_ITERATION()
template <BOOST_PP_ENUM_PARAMS(N,typename T), class _>
template <typename Func, BOOST_PP_ENUM_PARAMS(N,typename T)>
struct result
#if N < BOOST_FUSION_UNFUSED_LVALUE_ARGS_MAX_ARITY
< BOOST_PP_ENUM_PARAMS(N,T),
BOOST_PP_ENUM_PARAMS(
BOOST_PP_SUB(BOOST_FUSION_UNFUSED_LVALUE_ARGS_MAX_ARITY,N),
fusion::void_ BOOST_PP_INTERCEPT), _ >
#endif
: function::template result< BOOST_PP_CAT(fusion::vector,N)<
<Func(BOOST_PP_ENUM_PARAMS(N,T))>
: function::template result< function(BOOST_PP_CAT(fusion::vector,N)<
BOOST_PP_ENUM_BINARY_PARAMS(N,typename detail::mref<T,>::type
BOOST_PP_INTERCEPT) > >
BOOST_PP_INTERCEPT) >)>
{ };
template <BOOST_PP_ENUM_PARAMS(N,typename T)>
inline typename function::template result<BOOST_PP_CAT(fusion::vector,N)
<BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT)> >::type
inline typename function::template result<function(BOOST_PP_CAT(fusion::vector,N)
<BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT)>)>::type
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a)) const
{
BOOST_PP_CAT(fusion::vector,N)<
@ -115,8 +109,8 @@ namespace boost { namespace fusion
}
template <BOOST_PP_ENUM_PARAMS(N,typename T)>
inline typename function::template result<BOOST_PP_CAT(fusion::vector,N)
<BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT)> >::type
inline typename function::template result<function(BOOST_PP_CAT(fusion::vector,N)
<BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT)>)>::type
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a))
{
BOOST_PP_CAT(fusion::vector,N)<

View File

@ -16,6 +16,7 @@
#include <boost/preprocessor/facilities/intercept.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
@ -43,7 +44,7 @@ namespace boost { namespace fusion
typedef detail::nullary_call_base<
fusion::unfused_rvalue_args<Function>, Function > base;
typedef typename boost::remove_reference<Function>::type function;
typedef typename remove_const<typename boost::remove_reference<Function>::type>::type function;
typedef typename detail::call_param<Function>::type func_const_fwd_t;
public:
@ -54,17 +55,11 @@ namespace boost { namespace fusion
using base::operator();
template <
BOOST_PP_ENUM_BINARY_PARAMS(
BOOST_FUSION_UNFUSED_RVALUE_ARGS_MAX_ARITY,
typename T, = fusion::void_ BOOST_PP_INTERCEPT ),
class _ = fusion::void_ >
template <typename T>
struct result;
template <typename _>
struct result<BOOST_PP_ENUM_PARAMS(
BOOST_FUSION_UNFUSED_RVALUE_ARGS_MAX_ARITY,
fusion::void_ BOOST_PP_INTERCEPT),_>
template <typename Func>
struct result<unfused_rvalue_args<Func>()>
: base::r0
{ };
@ -76,10 +71,14 @@ namespace boost { namespace fusion
};
}}
#define BOOST_FUSION_CLASS_TPL_PARAMS class F
#define BOOST_FUSION_CLASS_TPL_SPEC fusion::unfused_rvalue_args<F>
#define BOOST_FUSION_FUNC_OBJ_ARITY BOOST_FUSION_UNFUSED_RVALUE_ARG_MAX_ARITY
#include <boost/fusion/functional/adapter/detail/gen_result_of_spec.hpp>
namespace boost {
template<typename Func>
struct result_of<boost::fusion::unfused_rvalue_args<Func>()>
{
typedef boost::fusion::unfused_rvalue_args<Func> function;
typedef typename function::template result<function()>::type type;
};
}
#define BOOST_FUSION_FUNCTIONAL_ADAPTER_UNFUSED_RVALUE_ARGS_HPP_INCLUDED
#else // defined(BOOST_PP_IS_ITERATING)
@ -90,22 +89,16 @@ namespace boost { namespace fusion
////////////////////////////////////////////////////////////////////////////////
#define N BOOST_PP_ITERATION()
template <BOOST_PP_ENUM_PARAMS(N,typename T), class _>
struct result
#if N < BOOST_FUSION_UNFUSED_RVALUE_ARGS_MAX_ARITY
< BOOST_PP_ENUM_PARAMS(N,T),
BOOST_PP_ENUM_PARAMS(
BOOST_PP_SUB(BOOST_FUSION_UNFUSED_RVALUE_ARGS_MAX_ARITY,N),
fusion::void_ BOOST_PP_INTERCEPT), _ >
#endif
: function::template result< BOOST_PP_CAT(fusion::vector,N)<
template <typename Func, BOOST_PP_ENUM_PARAMS(N,typename T)>
struct result<Func(BOOST_PP_ENUM_PARAMS(N,T))>
: function::template result<function( BOOST_PP_CAT(fusion::vector,N)<
BOOST_PP_ENUM_BINARY_PARAMS(N,typename detail::cref<T,>::type
BOOST_PP_INTERCEPT) > >
BOOST_PP_INTERCEPT) >)>
{ };
template <BOOST_PP_ENUM_PARAMS(N,typename T)>
inline typename function::template result<BOOST_PP_CAT(fusion::vector,N)
<BOOST_PP_ENUM_BINARY_PARAMS(N,T,const& BOOST_PP_INTERCEPT)> >::type
inline typename function::template result<function(BOOST_PP_CAT(fusion::vector,N)
<BOOST_PP_ENUM_BINARY_PARAMS(N,T,const& BOOST_PP_INTERCEPT)>)>::type
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,const& a)) const
{
BOOST_PP_CAT(fusion::vector,N)<
@ -115,8 +108,8 @@ namespace boost { namespace fusion
}
template <BOOST_PP_ENUM_PARAMS(N,typename T)>
inline typename function::template result<BOOST_PP_CAT(fusion::vector,N)
<BOOST_PP_ENUM_BINARY_PARAMS(N,T,const& BOOST_PP_INTERCEPT)> >::type
inline typename function::template result<function(BOOST_PP_CAT(fusion::vector,N)
<BOOST_PP_ENUM_BINARY_PARAMS(N,T,const& BOOST_PP_INTERCEPT)>)>::type
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,const& a))
{
BOOST_PP_CAT(fusion::vector,N)<

View File

@ -20,6 +20,7 @@
#include <boost/detail/workaround.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/fusion/support/detail/access.hpp>
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
@ -53,8 +54,8 @@ namespace boost { namespace fusion
// type of the next base class
typedef unfused_typed_impl
< Derived, Function, NextSeq, result_of::size<NextSeq>::value,
has_type< typename Function::template result<
typename result_of::as_vector<NextSeq>::type > >::value
has_type< typename Function::template result<Function(
typename result_of::as_vector<NextSeq>::type)> >::value
>
type;
};
@ -80,7 +81,7 @@ namespace boost { namespace fusion
class unfused_typed
: public detail::unfused_typed_next_base
< unfused_typed<Function,Sequence>,
typename remove_reference<Function>::type, Sequence, Sequence
typename remove_const<typename remove_reference<Function>::type>::type, Sequence, Sequence
>::type
{
Function fnc_transformed;
@ -91,11 +92,11 @@ namespace boost { namespace fusion
template <class D, class F, bool E>
friend struct detail::nullary_call_base;
typedef typename boost::remove_reference<Function>::type function;
typedef typename remove_const<typename boost::remove_reference<Function>::type>::type function;
typedef typename detail::call_param<Function>::type func_const_fwd_t;
typedef typename detail::unfused_typed_next_base<unfused_typed<
Function,Sequence>,function,Sequence,Sequence>::type base;
function, Sequence>,function,Sequence,Sequence>::type base;
public:
@ -103,17 +104,11 @@ namespace boost { namespace fusion
: fnc_transformed(f)
{ }
template <
BOOST_PP_ENUM_BINARY_PARAMS(BOOST_FUSION_UNFUSED_TYPED_MAX_ARITY,
typename T, = fusion::void_ BOOST_PP_INTERCEPT),
class _ = fusion::void_
>
template <typename T>
struct result;
template <typename _>
struct result<
BOOST_PP_ENUM_PARAMS(BOOST_FUSION_UNFUSED_TYPED_MAX_ARITY,
fusion::void_ BOOST_PP_INTERCEPT),_>
template <typename Func, typename Seq>
struct result<unfused_typed<Func, Seq>()>
: base::r0
{ };
};
@ -124,10 +119,14 @@ namespace boost { namespace fusion
}}
#define BOOST_FUSION_CLASS_TPL_PARAMS class F, class S
#define BOOST_FUSION_CLASS_TPL_SPEC fusion::unfused_typed<F,S>
#define BOOST_FUSION_FUNC_OBJ_ARITY BOOST_FUSION_UNFUSED_TYPED_MAX_ARITY
#include <boost/fusion/functional/adapter/detail/gen_result_of_spec.hpp>
namespace boost {
template<typename Func, typename Seq>
struct result_of<boost::fusion::unfused_typed<Func, Seq>()>
{
typedef boost::fusion::unfused_typed<Func, Seq> function;
typedef typename function::template result<function()>::type type;
};
}
#define BOOST_FUSION_FUNCTIONAL_ADAPTER_UNFUSED_TYPED_HPP_INCLUDED
#else // defined(BOOST_PP_IS_ITERATING)
@ -149,6 +148,8 @@ namespace boost { namespace fusion
typedef typename unfused_typed_next_base<
Derived,Function,Sequence>::type base;
typedef typename remove_const<typename remove_reference<Function>::type>::type function;
// Notes:
// - conversion to fusion::vector might not be perfect (there is
// currently no "inrinsic converting ctor" that would allow us
@ -161,13 +162,13 @@ namespace boost { namespace fusion
using base::operator();
typedef typename Function::
template result<arg_vector_t> BOOST_PP_CAT(r,N);
typedef typename function::
template result<function(arg_vector_t)> BOOST_PP_CAT(r,N);
#define M(z,i,s) \
typename call_param<typename result_of::value_at_c<s,i>::type>::type a##i
inline typename Function::template result<arg_vector_t>::type
inline typename function::template result<function(arg_vector_t)>::type
operator()(BOOST_PP_ENUM(N,M,arg_vector_t)) const
{
arg_vector_t arg(BOOST_PP_ENUM_PARAMS(N,a));
@ -175,7 +176,7 @@ namespace boost { namespace fusion
}
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1400)
inline typename Function::template result<arg_vector_t>::type
inline typename function::template result<function(arg_vector_t)>::type
operator()(BOOST_PP_ENUM(N,M,arg_vector_t))
{
arg_vector_t arg(BOOST_PP_ENUM_PARAMS(N,a));
@ -189,14 +190,9 @@ namespace boost { namespace fusion
} // namespace detail
template <class Function, class Sequence>
template <BOOST_PP_ENUM_PARAMS(N,typename T), class _>
template <typename Func, BOOST_PP_ENUM_PARAMS(N,typename T)>
struct unfused_typed<Function,Sequence>::result
#if N < BOOST_FUSION_UNFUSED_TYPED_MAX_ARITY
< BOOST_PP_ENUM_PARAMS(N,T),
BOOST_PP_ENUM_PARAMS(
BOOST_PP_SUB(BOOST_FUSION_UNFUSED_TYPED_MAX_ARITY,N),
fusion::void_ BOOST_PP_INTERCEPT), _ >
#endif
<Func(BOOST_PP_ENUM_PARAMS(N,T))>
: BOOST_PP_CAT(base::r,N)
{ };

View File

@ -17,9 +17,14 @@
#include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/utility/result_of.hpp>
#include <boost/blank.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/utility/result_of.hpp>
#include <boost/fusion/support/category_of.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
@ -114,11 +119,11 @@ namespace boost { namespace fusion
template <typename _ = void>
struct result
: Function::template result <
#define M(z,j,data) \
typename boost::remove_reference< \
typename result_of::value_at_c<Sequence,j>::type >::type
BOOST_PP_ENUM(N,M,~) >
: boost::result_of<
typename remove_const<Function>::type (BOOST_PP_ENUM(N,M,~))>
#undef M
{ };
@ -138,12 +143,14 @@ namespace boost { namespace fusion
private:
typedef invoke_function_object_param_types<Sequence,N> seq;
public:
template <typename _ = void>
struct result
: Function::template result <
BOOST_PP_ENUM_PARAMS(N,typename seq::T) >
{ };
{
typedef typename
boost::result_of<
typename remove_const<Function>::type (BOOST_PP_ENUM_PARAMS(N,typename seq::T))>::type type;
};
template <class F>
static inline typename result<F>::type

View File

@ -1,11 +1,14 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2007 Dan Marsden
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(FUSION_APPLY_TRANSFORM_RESULT_02092006_1936)
#define FUSION_APPLY_TRANSFORM_RESULT_02092006_1936
#if !defined(BOOST_FUSION_APPLY_TRANSFORM_RESULT_02092006_1936)
#define BOOST_FUSION_APPLY_TRANSFORM_RESULT_02092006_1936
#include <boost/utility/result_of.hpp>
namespace boost { namespace fusion
{
@ -18,15 +21,13 @@ namespace boost { namespace fusion
{
template <typename T0, typename T1 = void_>
struct apply
{
typedef typename F::template result<T0, T1>::type type;
};
: boost::result_of<F(T0, T1)>
{};
template <typename T0>
struct apply<T0, void_>
{
typedef typename F::template result<T0>::type type;
};
: boost::result_of<F(T0)>
{};
};
}
}}

View File

@ -21,13 +21,16 @@ namespace boost { namespace fusion {
template<typename N>
struct poly_advance
{
template<typename It>
struct result
template<typename T>
struct result;
template<typename N1, typename It>
struct result<poly_advance<N1>(It)>
: result_of::advance<It,N>
{};
template<typename It>
typename result<It>::type
typename result<poly_advance(It)>::type
operator()(const It& it) const
{
return fusion::advance<N>(it);

View File

@ -30,8 +30,11 @@ namespace boost { namespace fusion
template<typename N>
struct poly_at
{
template<typename SeqRef>
struct result
template<typename T>
struct result;
template<typename N1, typename SeqRef>
struct result<poly_at<N1>(SeqRef)>
: mpl::eval_if<is_same<SeqRef, unused_type const&>,
mpl::identity<unused_type>,
result_of::at<typename remove_reference<SeqRef>::type, N> >
@ -40,14 +43,14 @@ namespace boost { namespace fusion
};
template<typename Seq>
typename result<Seq&>::type
typename result<poly_at(Seq&)>::type
operator()(Seq& seq) const
{
return fusion::at<N>(seq);
}
template<typename Seq>
typename result<Seq const&>::type
typename result<poly_at(Seq const&)>::type
operator()(Seq const& seq) const
{
return fusion::at<N>(seq);

View File

@ -27,8 +27,11 @@ namespace boost { namespace fusion {
{
struct poly_begin
{
template<typename T>
struct result;
template<typename SeqRef>
struct result
struct result<poly_begin(SeqRef)>
: mpl::eval_if<is_same<SeqRef, unused_type const&>,
mpl::identity<unused_type>,
result_of::begin<typename remove_reference<SeqRef>::type> >
@ -37,14 +40,14 @@ namespace boost { namespace fusion {
};
template<typename Seq>
typename result<Seq&>::type
typename result<poly_begin(Seq&)>::type
operator()(Seq& seq) const
{
return fusion::begin(seq);
}
template<typename Seq>
typename result<Seq const&>::type
typename result<poly_begin(Seq const&)>::type
operator()(Seq const& seq) const
{
return fusion::begin(seq);

View File

@ -25,15 +25,18 @@ namespace boost { namespace fusion {
{
struct poly_deref
{
template<typename T>
struct result;
template<typename It>
struct result
struct result<poly_deref(It)>
: mpl::eval_if<is_same<It, unused_type>,
mpl::identity<unused_type>,
result_of::deref<It> >
{};
template<typename It>
typename result<It>::type
typename result<poly_deref(It)>::type
operator()(const It& it) const
{
return fusion::deref(it);

View File

@ -41,8 +41,11 @@ namespace boost { namespace fusion {
template<typename M>
struct endpoints
{
template<typename SeqRef>
struct result
template<typename T>
struct result;
template<typename M1, typename SeqRef>
struct result<endpoints<M1>(SeqRef)>
: mpl::eval_if<is_same<SeqRef, unused_type const&>,
mpl::identity<unused_type>,
get_endpoint<SeqRef, M> >
@ -51,14 +54,14 @@ namespace boost { namespace fusion {
};
template<typename Seq>
typename result<Seq&>::type
typename result<endpoints(Seq&)>::type
operator()(Seq& seq) const
{
return fusion::advance<M>(fusion::begin(seq));
}
template<typename Seq>
typename result<Seq const&>::type
typename result<endpoints(Seq const&)>::type
operator()(Seq const& seq)
{
return fusion::advance<M>(fusion::begin(seq));

View File

@ -24,15 +24,18 @@ namespace boost { namespace fusion {
{
struct poly_next
{
template<typename T>
struct result;
template<typename It>
struct result
struct result<poly_next(It)>
: mpl::eval_if<is_same<It, unused_type>,
mpl::identity<unused_type>,
result_of::next<It> >
{};
template<typename It>
typename result<It>::type
typename result<poly_next(It)>::type
operator()(const It& it) const
{
return fusion::next(it);

View File

@ -24,15 +24,18 @@ namespace boost { namespace fusion {
{
struct poly_prior
{
template<typename T>
struct result;
template<typename It>
struct result
struct result<poly_prior(It)>
: mpl::eval_if<is_same<It, unused_type>,
mpl::identity<unused_type>,
result_of::prior<It> >
{};
template<typename It>
typename result<It>::type
typename result<poly_prior(It)>::type
operator()(const It& it) const
{
return fusion::prior(it);

View File

@ -10,7 +10,6 @@
#include <boost/mpl/or.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/fusion/support/category_of.hpp>
#include <boost/fusion/sequence/intrinsic/mpl.hpp>
#include <boost/fusion/algorithm/iteration/fold.hpp>
@ -38,8 +37,13 @@ namespace boost { namespace fusion {
typedef Tag2 type;
};
template<typename Next, typename StrictestSoFar>
struct strictest_traversal_impl
{
template<typename T>
struct result;
template<typename Next, typename StrictestSoFar>
struct result<strictest_traversal_impl(Next, StrictestSoFar)>
{
typedef StrictestSoFar tag1;
typedef typename traits::category_of<
@ -47,12 +51,13 @@ namespace boost { namespace fusion {
typedef typename stricter_traversal<tag1,tag2>::type type;
};
};
template<typename Sequence>
struct strictest_traversal
: result_of::fold<
Sequence, fusion::random_access_traversal_tag,
strictest_traversal_impl<boost::mpl::_,boost::mpl::_> >
strictest_traversal_impl>
{};
}

View File

@ -26,8 +26,11 @@ namespace boost { namespace fusion {
template<typename N>
struct poly_value_at
{
template<typename Seq>
struct result
template<typename T>
struct result;
template<typename N1, typename Seq>
struct result<poly_value_at<N1>(Seq)>
: mpl::eval_if<is_same<Seq, unused_type const&>,
mpl::identity<unused_type>,
result_of::value_at<typename remove_reference<Seq>::type, N> >

View File

@ -25,8 +25,11 @@ namespace boost { namespace fusion {
{
struct poly_value_of
{
template<typename T>
struct result;
template<typename It>
struct result
struct result<poly_value_of(It)>
: mpl::eval_if<is_same<It, unused_type>,
mpl::identity<unused_type>,
result_of::value_of<It> >

View File

@ -32,6 +32,7 @@
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/is_reference.hpp>
@ -47,27 +48,31 @@ namespace boost { namespace fusion {
struct seq_ref_size
{
template<typename Seq,
typename SeqClass = typename remove_reference<Seq>::type,
bool HasSize = traits::is_forward<SeqClass>::value
>
struct result
: result_of::size<SeqClass>
{};
template<typename Params>
struct result;
template<typename Seq>
struct result<seq_ref_size(Seq)>
{
static int const int_max = static_cast<int>(
static_cast<unsigned>(~0) >> 1);
template<typename Seq, typename SeqClass>
struct result<Seq, SeqClass, false>
: mpl::int_<int_max>
{};
typedef typename remove_reference<Seq>::type SeqClass;
typedef typename mpl::eval_if<
traits::is_forward<SeqClass>,
result_of::size<SeqClass>,
mpl::int_<int_max> >::type type;
};
};
struct poly_min
{
template<typename T>
struct result;
template<typename Lhs, typename Rhs>
struct result
struct result<poly_min(Lhs, Rhs)>
: mpl::min<Lhs, Rhs>
{};
};

View File

@ -11,30 +11,30 @@
#include <boost/fusion/support/deduce.hpp>
#include <boost/fusion/sequence/conversion/as_vector.hpp>
#include <boost/fusion/sequence/view/transform_view.hpp>
#include <boost/fusion/sequence/intrinsic/mpl.hpp>
#include <boost/mpl/transform.hpp>
namespace boost { namespace fusion { namespace traits
{
template <class Sequence> struct deduce_sequence;
//----- ---- --- -- - - - -
namespace detail
{
struct deducer
{
template <typename T>
struct result
struct apply
: fusion::traits::deduce<T>
{ };
};
}
// We cannot use fusion::transform_view here as result_of looses cv qualifiers
// on built in types
template <class Sequence>
struct deduce_sequence
: result_of::as_vector<
fusion::transform_view<Sequence, detail::deducer> >
typename mpl::transform<Sequence, detail::deducer>::type>
{ };
}}}

View File

@ -5,7 +5,6 @@
# License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#==============================================================================
# bring in rules for testing
import testing ;

View File

@ -1,5 +1,6 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2007 Dan Marsden
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@ -23,8 +24,11 @@ using boost::is_same;
struct add_ints_only
{
template<typename T>
struct result;
template <typename T, typename State>
struct result
struct result<add_ints_only(T,State)>
{
typedef State type;
};
@ -45,8 +49,11 @@ struct add_ints_only
struct count_ints
{
template<typename T>
struct result;
template <typename T, typename CountT>
struct result
struct result<count_ints(T,CountT)>
{
typedef typename
if_<
@ -58,10 +65,10 @@ struct count_ints
};
template <typename T, typename CountT>
typename result<T, CountT>::type
typename result<count_ints(T, CountT)>::type
operator()(T const&, CountT const&) const
{
typedef typename result<T, CountT>::type result;
typedef typename result<count_ints(T, CountT)>::type result;
return result();
}
};

View File

@ -1,5 +1,6 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2007 Dan Marsden
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@ -19,7 +20,10 @@
struct square
{
template<typename T>
struct result
struct result;
template <typename T>
struct result<square(T)>
{
BOOST_STATIC_ASSERT(!boost::is_reference<T>::value);
typedef int type;
@ -34,8 +38,11 @@ struct square
struct add
{
template<typename T>
struct result;
template <typename A, typename B>
struct result
struct result<add(A, B)>
{
typedef int type;
};

View File

@ -15,6 +15,9 @@
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/container/vector.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/assert.hpp>
namespace fusion = boost::fusion;
using boost::noncopyable;
@ -52,17 +55,33 @@ struct test_func
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');
typedef fusion::fused< test_func<> > ff;
ff fused_func;
typedef fusion::fused< test_func<noncopyable> & > ffr;
ffr fused_func_ref(f);
typedef fusion::fused< test_func<> const > ffc;
ffc fused_func_c;
typedef fusion::fused< test_func<> > const ffc2;
ffc2 fused_func_c2;
typedef fusion::fused< test_func<noncopyable> const & > ffcr;
ffcr fused_func_c_ref(f);
typedef fusion::vector<int,char> vec;
vec lv_vec(1,'\004');
BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ff(vec)>::type, int>));
BOOST_TEST(fused_func(lv_vec) == 1);
BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ffr(vec)>::type, int>));
BOOST_TEST(fused_func_c(lv_vec) == 0);
BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ffc(vec)>::type, int>));
BOOST_TEST(fused_func_c2(lv_vec) == 0);
BOOST_TEST(fused_func_ref(lv_vec) == 1);
BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ffcr(vec)>::type, int>));
BOOST_TEST(fused_func_c_ref(lv_vec) == 0);
BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1);

View File

@ -22,8 +22,11 @@ template <class Base = boost::blank>
struct test_func
: Base
{
template <typename T0, typename T1>
struct result
template<typename T>
struct result;
template<typename B, typename T0, typename T1>
struct result<test_func<B>(T0, T1)>
{
typedef int type;
};

View File

@ -40,10 +40,27 @@ struct object_nc : boost::noncopyable {};
struct fobj
{
typedef int result_type;
// Handle nullary separately to exercise result_of support
template<typename T>
struct result;
int operator()() { return 0; }
int operator()() const { return 1; }
template<typename T0>
struct result<fobj(T0)>
{
typedef int type;
};
template<typename T0, typename T1>
struct result<fobj(T0, T1)>
{
typedef int type;
};
template<typename T0, typename T1, typename T2>
struct result<fobj(T0, T1, T2)>
{
typedef int type;
};
int operator()(int i) { return 2 + i; }
int operator()(int i) const { return 3 + i; }
@ -57,16 +74,38 @@ struct fobj
int operator()(int i, object &, object_nc &) const { return 11 + i; }
};
struct nullary_fobj
{
typedef int result_type;
int operator()() { return 0; }
int operator()() const { return 1; }
};
struct fobj_nc
: boost::noncopyable
{
// Handle nullary separately to exercise result_of support
template<typename T>
struct result;
template<typename T0>
struct result<fobj_nc(T0)>
{
typedef int type;
};
int operator()(int i) { return 14 + i; }
int operator()(int i) const { return 15 + i; }
};
struct nullary_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; }
@ -147,7 +186,7 @@ void test_sequence_n(Sequence & seq, mpl::int_<0>)
{
// Function Objects
fobj f;
nullary_fobj f;
BOOST_TEST(f () == fusion::invoke(f , seq ));
BOOST_TEST(f () == fusion::invoke(f , const_(seq)));
@ -155,16 +194,16 @@ void test_sequence_n(Sequence & seq, mpl::int_<0>)
// 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)));
BOOST_TEST(const_(f)() == fusion::invoke<nullary_fobj const >(const_(f), seq ));
BOOST_TEST(const_(f)() == fusion::invoke<nullary_fobj const &>(const_(f), const_(seq)));
fobj_nc nc_f;
nullary_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)));
BOOST_TEST(nc_f () == fusion::invoke<nullary_fobj_nc &>(nc_f , seq ));
BOOST_TEST(nc_f () == fusion::invoke<nullary_fobj_nc &>(nc_f , const_(seq)));
BOOST_TEST(const_(nc_f)() == fusion::invoke<nullary_fobj_nc const &>(const_(nc_f), seq ));
BOOST_TEST(const_(nc_f)() == fusion::invoke<nullary_fobj_nc const &>(const_(nc_f), const_(seq)));
// Builtin Functions

View File

@ -40,8 +40,24 @@ struct object_nc : boost::noncopyable {};
struct fobj
{
template <typename T0 = void, typename T1 = void, typename T2 = void>
struct result
// Handle nullary separately to exercise result_of support
template<typename T>
struct result;
template<typename T0>
struct result<fobj(T0)>
{
typedef int type;
};
template<typename T0, typename T1>
struct result<fobj(T0, T1)>
{
typedef int type;
};
template<typename T0, typename T1, typename T2>
struct result<fobj(T0, T1, T2)>
{
typedef int type;
};
@ -61,22 +77,41 @@ struct fobj
int operator()(int i, object &, object_nc &) const { return 11 + i; }
};
struct nullary_fobj
{
typedef int result_type;
int operator()() { return 0; }
int operator()() const { return 1; }
};
struct fobj_nc
: boost::noncopyable
{
template <typename T0 = void>
struct result
// Handle nullary separately to exercise result_of support
template <typename T>
struct result;
template<typename T0>
struct result<fobj_nc(T0)>
{
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; }
};
struct nullary_fobj_nc
: boost::noncopyable
{
typedef int result_type;
int operator()() { return 12; }
int operator()() const { return 13; }
};
typedef int element1_type;
typedef object element2_type;
typedef object_nc & element3_type;
@ -90,23 +125,23 @@ void test_sequence_n(Sequence & seq, mpl::int_<0>)
{
// Function Objects
fobj f;
nullary_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)));
BOOST_TEST(const_(f)() == fusion::invoke_function_object<nullary_fobj const >(const_(f), seq ));
BOOST_TEST(const_(f)() == fusion::invoke_function_object<nullary_fobj const &>(const_(f), const_(seq)));
fobj_nc nc_f;
nullary_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)));
BOOST_TEST(nc_f () == fusion::invoke_function_object<nullary_fobj_nc &>(nc_f , seq ));
BOOST_TEST(nc_f () == fusion::invoke_function_object<nullary_fobj_nc &>(nc_f , const_(seq)));
BOOST_TEST(const_(nc_f)() == fusion::invoke_function_object<nullary_fobj_nc const &>(const_(nc_f), seq ));
BOOST_TEST(const_(nc_f)() == fusion::invoke_function_object<nullary_fobj_nc const &>(const_(nc_f), const_(seq)));
}
template <class Sequence>
@ -154,7 +189,7 @@ 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< nullary_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 ));
}

View File

@ -24,8 +24,14 @@ template <class Base = boost::blank>
struct test_func
: Base
{
template <typename T0, typename T1>
template<typename T>
struct result
{
};
template<typename B, typename T0, typename T1>
struct result<test_func<B>(T0, T1)>
{
typedef int type;
};

View File

@ -38,7 +38,11 @@ template <class Base = boost::blank, class RemoveNullary = mpl::false_>
struct test_func
: Base
{
template <class Seq> struct result
template<typename Params>
struct result;
template <typename B, typename RM, class Seq>
struct result<test_func<B, RM>(Seq)>
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
boost::blank, mpl::identity<long> >::type
{ };
@ -61,6 +65,8 @@ struct test_func
struct fold_op
{
typedef long result_type;
template <typename T>
long operator()(T const & elem, long value) const
{
@ -73,10 +79,6 @@ struct test_func
elem += sizeof(T);
return value;
}
template <typename T0, typename T1> struct result
: mpl::identity<long>
{ };
};
};

View File

@ -37,7 +37,11 @@ template <class Base = boost::blank, class RemoveNullary = mpl::false_>
struct test_func
: Base
{
template <class Seq> struct result
template<typename Params>
struct result;
template <typename B, typename RN, class Seq>
struct result<test_func<B, RN>(Seq)>
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
boost::blank, mpl::identity<long> >::type
{ };
@ -60,16 +64,14 @@ struct test_func
struct fold_op
{
typedef long result_type;
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>
{ };
};
};

View File

@ -35,7 +35,11 @@ template <class Base = boost::blank, class RemoveNullary = mpl::false_>
struct test_func
: Base
{
template <class Seq> struct result
template<typename Params>
struct result;
template <typename B, typename RN, class Seq>
struct result<test_func<B, RN>(Seq)>
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
boost::blank, mpl::identity<long> >::type
{ };
@ -58,15 +62,13 @@ struct test_func
struct fold_op
{
typedef long result_type;
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>
{ };
};
};

View File

@ -35,7 +35,11 @@ template <class Base = boost::blank, class RemoveNullary = mpl::false_>
struct test_func
: Base
{
template <class Seq> struct result
template<typename T>
struct result;
template <typename B, typename RN, class Seq>
struct result<test_func<B,RN>(Seq)>
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
boost::blank, mpl::identity<long> >::type
{};
@ -58,6 +62,8 @@ struct test_func
struct fold_op
{
typedef long result_type;
template <typename T>
long operator()(T const & elem, long value) const
{
@ -70,10 +76,6 @@ struct test_func
elem += sizeof(T);
return value;
}
template <typename T0, typename T1> struct result
: mpl::identity<long>
{ };
};
};
@ -85,9 +87,9 @@ void result_type_tests()
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(( has_type< test_func_0::result<test_func_0()> >::value ));
BOOST_TEST(( has_type< test_func_1::result<test_func_1(int)> >::value ));
BOOST_TEST(( ! has_type< test_func_1::result<test_func_1()> >::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 ));
}

View File

@ -32,7 +32,11 @@ template <class Base = boost::blank, class RemoveNullary = mpl::false_>
struct test_func
: Base
{
template <class Seq> struct result
template<typename T>
struct result;
template <typename B, typename RM, class Seq>
struct result<test_func<B, RM>(Seq)>
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
boost::blank, mpl::identity<long> >::type
{ };
@ -55,16 +59,14 @@ struct test_func
struct fold_op
{
typedef long result_type;
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>
{ };
};
};
@ -76,9 +78,9 @@ void result_type_tests()
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(( has_type< test_func_0::result<test_func_0()> >::value ));
BOOST_TEST(( has_type< test_func_1::result<test_func_1(int)> >::value ));
BOOST_TEST(( ! has_type< test_func_1::result<test_func_1()> >::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 ));
}

View File

@ -32,7 +32,11 @@ template <class Base = boost::blank, class RemoveNullary = mpl::false_>
struct test_func
: Base
{
template <class Seq> struct result
template<typename T>
struct result;
template <typename B, typename RN, class Seq>
struct result<test_func<B, RN>(Seq)>
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
boost::blank, mpl::identity<long> >::type
{ };
@ -55,15 +59,13 @@ struct test_func
struct fold_op
{
typedef long result_type;
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>
{ };
};
};
@ -75,9 +77,9 @@ void result_type_tests()
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(( has_type< test_func_0::result<test_func_0()> >::value ));
BOOST_TEST(( has_type< test_func_1::result<test_func_1(int)> >::value ));
BOOST_TEST(( ! has_type< test_func_1::result<test_func_1()> >::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 ));
}

View File

@ -42,7 +42,11 @@ template <class Base = boost::blank, class Validation = unconstrained>
struct test_func
: Base
{
template <class Seq> struct result
template<typename T>
struct result;
template <typename B, typename V, class Seq>
struct result<test_func<B,V>(Seq)>
: mpl::if_< typename mpl::apply<Validation, Seq>::type,
mpl::identity<long>, boost::blank >::type
{ };
@ -65,6 +69,8 @@ struct test_func
struct fold_op
{
typedef long result_type;
template <typename T>
long operator()(T const & elem, long value) const
{
@ -77,10 +83,6 @@ struct test_func
elem += sizeof(T);
return value;
}
template <typename T0, typename T1> struct result
: mpl::identity<long>
{ };
};
};
@ -92,9 +94,9 @@ void result_type_tests()
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(( has_type< test_func_0::result<test_func_0()> >::value ));
BOOST_TEST(( has_type< test_func_3::result<test_func_3(long &, int, char)> >::value ));
BOOST_TEST(( ! has_type< test_func_3::result<test_func_3()> >::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 ));
}

View File

@ -27,7 +27,10 @@
struct square
{
template<typename T>
struct result
struct result;
template <typename T>
struct result<square(T)>
{
typedef int type;
};
@ -41,8 +44,11 @@ struct square
struct add
{
template<typename T>
struct result;
template <typename A, typename B>
struct result
struct result<add(A,B)>
{
typedef int type;
};