Files

355 lines
8.6 KiB
C++
Raw Permalink Normal View History

2003-08-04 02:03:46 +00:00
#if !defined(BOOST_PP_IS_ITERATING)
///// header body
#ifndef BOOST_MPL_AUX_FULL_LAMBDA_HPP_INCLUDED
#define BOOST_MPL_AUX_FULL_LAMBDA_HPP_INCLUDED
2004-09-02 15:41:37 +00:00
// Copyright Aleksey Gurtovoy 2001-2004
2002-09-15 22:13:24 +00:00
//
2004-09-02 15:41:37 +00:00
// 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)
2003-08-04 02:03:46 +00:00
//
// See http://www.boost.org/libs/mpl for documentation.
2002-09-15 22:13:24 +00:00
2008-10-10 09:10:26 +00:00
// $Id$
2004-09-02 15:41:37 +00:00
// $Date$
// $Revision$
2002-09-15 22:13:24 +00:00
#if !defined(BOOST_MPL_PREPROCESSING_MODE)
2004-09-02 15:41:37 +00:00
# include <boost/mpl/lambda_fwd.hpp>
# include <boost/mpl/bind_fwd.hpp>
# include <boost/mpl/protect.hpp>
# include <boost/mpl/quote.hpp>
# include <boost/mpl/arg.hpp>
# include <boost/mpl/bool.hpp>
# include <boost/mpl/int_fwd.hpp>
# include <boost/mpl/aux_/template_arity.hpp>
# include <boost/mpl/aux_/na_spec.hpp>
# include <boost/mpl/aux_/config/ttp.hpp>
# if defined(BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
# include <boost/mpl/if.hpp>
# endif
2002-09-15 22:13:24 +00:00
#endif
2004-09-02 15:41:37 +00:00
#include <boost/mpl/aux_/lambda_arity_param.hpp>
#include <boost/mpl/aux_/config/use_preprocessed.hpp>
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
#if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
&& !defined(BOOST_MPL_PREPROCESSING_MODE)
2002-09-15 22:13:24 +00:00
# define BOOST_MPL_PREPROCESSED_HEADER full_lambda.hpp
2004-09-02 15:41:37 +00:00
# include <boost/mpl/aux_/include_preprocessed.hpp>
2002-09-15 22:13:24 +00:00
#else
2004-09-02 15:41:37 +00:00
# include <boost/mpl/limits/arity.hpp>
# include <boost/mpl/aux_/preprocessor/default_params.hpp>
# include <boost/mpl/aux_/preprocessor/params.hpp>
# include <boost/mpl/aux_/preprocessor/enum.hpp>
# include <boost/mpl/aux_/preprocessor/repeat.hpp>
# include <boost/mpl/aux_/config/dmc_ambiguous_ctps.hpp>
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
# include <boost/preprocessor/iterate.hpp>
# include <boost/preprocessor/comma_if.hpp>
# include <boost/preprocessor/inc.hpp>
# include <boost/preprocessor/cat.hpp>
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
namespace boost { namespace mpl {
2002-09-15 22:13:24 +00:00
// local macros, #undef-ined at the end of the header
2004-09-02 15:41:37 +00:00
# define AUX778076_LAMBDA_PARAMS(i_, param) \
BOOST_MPL_PP_PARAMS(i_, param) \
2002-09-15 22:13:24 +00:00
/**/
2004-09-02 15:41:37 +00:00
# define AUX778076_BIND_PARAMS(param) \
2002-09-15 22:13:24 +00:00
BOOST_MPL_PP_PARAMS( \
2004-09-02 15:41:37 +00:00
BOOST_MPL_LIMIT_METAFUNCTION_ARITY \
2002-09-15 22:13:24 +00:00
, param \
) \
/**/
2004-09-02 15:41:37 +00:00
# define AUX778076_BIND_N_PARAMS(i_, param) \
BOOST_PP_COMMA_IF(i_) \
BOOST_MPL_PP_PARAMS(i_, param) \
2002-09-15 22:13:24 +00:00
/**/
2004-09-02 15:41:37 +00:00
# define AUX778076_ARITY_PARAM(param) \
2002-09-15 22:13:24 +00:00
BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(param) \
/**/
2004-09-02 15:41:37 +00:00
#define n_ BOOST_MPL_LIMIT_METAFUNCTION_ARITY
2002-09-15 22:13:24 +00:00
namespace aux {
template<
2004-09-02 15:41:37 +00:00
BOOST_MPL_PP_DEFAULT_PARAMS(n_,bool C,false)
2002-09-15 22:13:24 +00:00
>
struct lambda_or
2003-02-25 23:11:41 +00:00
: true_
2002-09-15 22:13:24 +00:00
{
};
template<>
2004-09-02 15:41:37 +00:00
struct lambda_or< BOOST_MPL_PP_ENUM(n_,false) >
2003-02-25 23:11:41 +00:00
: false_
2002-09-15 22:13:24 +00:00
{
};
} // namespace aux
2004-09-02 15:41:37 +00:00
#undef n_
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
template<
typename T
, typename Tag
AUX778076_ARITY_PARAM(typename Arity)
>
struct lambda
2002-09-15 22:13:24 +00:00
{
2004-09-02 15:41:37 +00:00
typedef false_ is_le;
typedef T result_;
typedef T type;
2002-09-15 22:13:24 +00:00
};
2004-09-02 15:41:37 +00:00
template<
typename T
>
struct is_lambda_expression
: lambda<T>::is_le
{
};
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
template< int N, typename Tag >
struct lambda< arg<N>,Tag AUX778076_ARITY_PARAM(int_<-1>) >
{
typedef true_ is_le;
typedef mpl::arg<N> result_; // qualified for the sake of MIPSpro 7.41
2004-09-04 01:10:23 +00:00
typedef mpl::protect<result_> type;
2004-09-02 15:41:37 +00:00
};
#define BOOST_PP_ITERATION_PARAMS_1 \
(3,(0, BOOST_MPL_LIMIT_METAFUNCTION_ARITY, <boost/mpl/aux_/full_lambda.hpp>))
2002-09-15 22:13:24 +00:00
#include BOOST_PP_ITERATE()
2004-09-02 15:41:37 +00:00
/// special case for 'protect'
template< typename T, typename Tag >
2004-09-04 01:10:23 +00:00
struct lambda< mpl::protect<T>,Tag AUX778076_ARITY_PARAM(int_<1>) >
2002-09-15 22:13:24 +00:00
{
2004-09-02 15:41:37 +00:00
typedef false_ is_le;
2004-09-04 01:10:23 +00:00
typedef mpl::protect<T> result_;
2004-09-02 15:41:37 +00:00
typedef result_ type;
2002-09-15 22:13:24 +00:00
};
2004-09-02 15:41:37 +00:00
/// specializations for the main 'bind' form
2002-09-15 22:13:24 +00:00
template<
2004-09-02 15:41:37 +00:00
typename F, AUX778076_BIND_PARAMS(typename T)
2003-08-04 02:03:46 +00:00
, typename Tag
2003-01-05 08:49:46 +00:00
>
2004-09-02 15:41:37 +00:00
struct lambda<
bind<F,AUX778076_BIND_PARAMS(T)>
, Tag
AUX778076_ARITY_PARAM(int_<BOOST_PP_INC(BOOST_MPL_LIMIT_METAFUNCTION_ARITY)>)
>
2002-09-15 22:13:24 +00:00
{
2004-09-02 15:41:37 +00:00
typedef false_ is_le;
typedef bind<F, AUX778076_BIND_PARAMS(T)> result_;
typedef result_ type;
2002-09-15 22:13:24 +00:00
};
2004-09-02 15:41:37 +00:00
#if defined(BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
2002-09-15 22:13:24 +00:00
template<
2004-09-02 15:41:37 +00:00
typename F
, typename Tag1
, typename Tag2
, typename Arity
2002-09-15 22:13:24 +00:00
>
2004-09-02 15:41:37 +00:00
struct lambda<
lambda<F,Tag1,Arity>
, Tag2
, int_<3>
>
2002-09-15 22:13:24 +00:00
{
2004-09-02 15:41:37 +00:00
typedef lambda< F,Tag2 > l1;
typedef lambda< Tag1,Tag2 > l2;
typedef typename l1::is_le is_le;
typedef bind1< quote1<aux::template_arity>, typename l1::result_ > arity_;
typedef lambda< typename if_<is_le,arity_,Arity>::type,Tag2 > l3;
typedef aux::le_result3<is_le, Tag2, mpl::lambda, l1, l2, l3> le_result_;
typedef typename le_result_::result_ result_;
typedef typename le_result_::type type;
2002-09-15 22:13:24 +00:00
};
2004-09-02 15:41:37 +00:00
#elif !defined(BOOST_MPL_CFG_DMC_AMBIGUOUS_CTPS)
/// workaround for MWCW 8.3+/EDG < 303, leads to ambiguity on Digital Mars
2002-09-15 22:13:24 +00:00
template<
2004-09-02 15:41:37 +00:00
typename F, typename Tag1, typename Tag2
2002-09-15 22:13:24 +00:00
>
2004-09-02 15:41:37 +00:00
struct lambda<
lambda< F,Tag1 >
, Tag2
>
2002-09-15 22:13:24 +00:00
{
2004-09-02 15:41:37 +00:00
typedef lambda< F,Tag2 > l1;
typedef lambda< Tag1,Tag2 > l2;
typedef typename l1::is_le is_le;
typedef aux::le_result2<is_le, Tag2, mpl::lambda, l1, l2> le_result_;
typedef typename le_result_::result_ result_;
typedef typename le_result_::type type;
2002-09-15 22:13:24 +00:00
};
2004-09-02 15:41:37 +00:00
#endif
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
# undef AUX778076_ARITY_PARAM
# undef AUX778076_BIND_N_PARAMS
# undef AUX778076_BIND_PARAMS
# undef AUX778076_LAMBDA_PARAMS
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
#if !defined(BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
BOOST_MPL_AUX_NA_SPEC(2, lambda)
#else
BOOST_MPL_AUX_NA_SPEC2(2, 3, lambda)
#endif
}}
#endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
2002-09-15 22:13:24 +00:00
#endif // BOOST_MPL_AUX_FULL_LAMBDA_HPP_INCLUDED
///// iteration, depth == 1
// For gcc 4.4 compatability, we must include the
// BOOST_PP_ITERATION_DEPTH test inside an #else clause.
#else // BOOST_PP_IS_ITERATING
#if BOOST_PP_ITERATION_DEPTH() == 1
2004-09-02 15:41:37 +00:00
#define i_ BOOST_PP_FRAME_ITERATION(1)
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
#if i_ > 0
2002-09-15 22:13:24 +00:00
namespace aux {
2004-09-02 15:41:37 +00:00
# define AUX778076_RESULT(unused, i_, T) \
BOOST_PP_COMMA_IF(i_) \
typename BOOST_PP_CAT(T, BOOST_PP_INC(i_))::result_ \
/**/
# define AUX778076_TYPE(unused, i_, T) \
BOOST_PP_COMMA_IF(i_) \
typename BOOST_PP_CAT(T, BOOST_PP_INC(i_))::type \
/**/
2002-09-15 22:13:24 +00:00
template<
2004-09-02 15:41:37 +00:00
typename IsLE, typename Tag
, template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
, AUX778076_LAMBDA_PARAMS(i_, typename L)
2002-09-15 22:13:24 +00:00
>
2004-09-02 15:41:37 +00:00
struct BOOST_PP_CAT(le_result,i_)
2002-09-15 22:13:24 +00:00
{
typedef F<
2004-09-02 15:41:37 +00:00
BOOST_MPL_PP_REPEAT(i_, AUX778076_TYPE, L)
> result_;
typedef result_ type;
2002-09-15 22:13:24 +00:00
};
template<
typename Tag
2004-09-02 15:41:37 +00:00
, template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
, AUX778076_LAMBDA_PARAMS(i_, typename L)
2002-09-15 22:13:24 +00:00
>
2004-09-02 15:41:37 +00:00
struct BOOST_PP_CAT(le_result,i_)< true_,Tag,F,AUX778076_LAMBDA_PARAMS(i_, L) >
2002-09-15 22:13:24 +00:00
{
2004-09-02 15:41:37 +00:00
typedef BOOST_PP_CAT(bind,i_)<
BOOST_PP_CAT(quote,i_)<F,Tag>
, BOOST_MPL_PP_REPEAT(i_, AUX778076_RESULT, L)
> result_;
2004-09-04 01:10:23 +00:00
typedef mpl::protect<result_> type;
2002-09-15 22:13:24 +00:00
};
2004-09-02 15:41:37 +00:00
# undef AUX778076_TYPE
# undef AUX778076_RESULT
2002-09-15 22:13:24 +00:00
} // namespace aux
2004-09-02 15:41:37 +00:00
# define AUX778076_LAMBDA_TYPEDEF(unused, i_, T) \
typedef lambda< BOOST_PP_CAT(T, BOOST_PP_INC(i_)), Tag > \
BOOST_PP_CAT(l,BOOST_PP_INC(i_)); \
/**/
# define AUX778076_IS_LE_TYPEDEF(unused, i_, unused2) \
typedef typename BOOST_PP_CAT(l,BOOST_PP_INC(i_))::is_le \
BOOST_PP_CAT(is_le,BOOST_PP_INC(i_)); \
/**/
# define AUX778076_IS_LAMBDA_EXPR(unused, i_, unused2) \
BOOST_PP_COMMA_IF(i_) \
BOOST_PP_CAT(is_le,BOOST_PP_INC(i_))::value \
/**/
2002-09-15 22:13:24 +00:00
template<
2004-09-02 15:41:37 +00:00
template< AUX778076_LAMBDA_PARAMS(i_, typename P) > class F
, AUX778076_LAMBDA_PARAMS(i_, typename T)
2003-08-04 02:03:46 +00:00
, typename Tag
2003-03-09 02:30:59 +00:00
>
2004-09-02 15:41:37 +00:00
struct lambda<
F<AUX778076_LAMBDA_PARAMS(i_, T)>
2003-08-04 02:03:46 +00:00
, Tag
2004-09-02 15:41:37 +00:00
AUX778076_ARITY_PARAM(int_<i_>)
>
{
BOOST_MPL_PP_REPEAT(i_, AUX778076_LAMBDA_TYPEDEF, T)
BOOST_MPL_PP_REPEAT(i_, AUX778076_IS_LE_TYPEDEF, unused)
typedef typename aux::lambda_or<
BOOST_MPL_PP_REPEAT(i_, AUX778076_IS_LAMBDA_EXPR, unused)
>::type is_le;
typedef aux::BOOST_PP_CAT(le_result,i_)<
is_le, Tag, F, AUX778076_LAMBDA_PARAMS(i_, l)
> le_result_;
typedef typename le_result_::result_ result_;
typedef typename le_result_::type type;
2002-09-15 22:13:24 +00:00
};
2003-01-05 08:49:46 +00:00
2004-09-02 15:41:37 +00:00
# undef AUX778076_IS_LAMBDA_EXPR
# undef AUX778076_IS_LE_TYPEDEF
# undef AUX778076_LAMBDA_TYPEDEF
#endif // i_ > 0
2002-09-15 22:13:24 +00:00
2003-01-05 08:49:46 +00:00
template<
2004-09-02 15:41:37 +00:00
typename F AUX778076_BIND_N_PARAMS(i_, typename T)
2003-08-04 02:03:46 +00:00
, typename Tag
2003-01-05 08:49:46 +00:00
>
2004-09-02 15:41:37 +00:00
struct lambda<
BOOST_PP_CAT(bind,i_)<F AUX778076_BIND_N_PARAMS(i_, T)>
, Tag
AUX778076_ARITY_PARAM(int_<BOOST_PP_INC(i_)>)
>
2003-01-05 08:49:46 +00:00
{
2004-09-02 15:41:37 +00:00
typedef false_ is_le;
typedef BOOST_PP_CAT(bind,i_)<
2003-01-05 08:49:46 +00:00
F
2004-09-02 15:41:37 +00:00
AUX778076_BIND_N_PARAMS(i_, T)
> result_;
typedef result_ type;
2003-01-05 08:49:46 +00:00
};
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
#undef i_
#endif // BOOST_PP_ITERATION_DEPTH()
2002-09-15 22:13:24 +00:00
#endif // BOOST_PP_IS_ITERATING