Boost logo

Boost Users :

From: Jason House (jasonhouse_at_[hidden])
Date: 2007-01-04 00:46:05


I hope the sheer size of this post doesn't scare those who can help me
away :(

Depending on how I use the code at the bottom of this post, things
either work or they blow up with varying error messages deep within the
boost libraries. The very last function in the code below is the last
consistent "source" of the errors. As best as I understand it, that
line is correct. I'm scratching my head on how to diagnose what's going
wrong.

The simplest error I got seemed to complain about const qualifiers that
seem to have been added internally to boost::lambda::bind. I'm not sure
which error message to pick out from other error scenarios (such as 3
input parameters (types T0, T1, and T2)). This error had R0=void, and
no input arguments (T0, T1, etc...). The code at the bottom of this
post compiles with R0=void and T0=int.

actions.hpp:87: error: no matching function for call to
‘boost::lambda::function_adaptor<
   GTPInternalResponse (*)(
     boost::function0<void, std::allocator<boost::function_base> >*,
     GTPCommand)>
   ::apply(
     GTPInternalResponse (* const&)(
       boost::function0<void, std::allocator<boost::function_base> >*,
       GTPCommand),
     boost::function0<void, std::allocator<boost::function_base> >* const&)’

As clarification for understanding the code:
   GTPInternalResponse can be thought of a string and GTPCommand as a
tokenized string. The extract<>() function consumes some string tokens
and returns a value of the specified type (T0,T1,T2,T3, etc...)
   The only big impact on this code externally (besides the calls to
GTPFunctionObjectN) is #define's for GTP_PARAM_COUNT and
GTP_PARAM_COUNT_PLUS_ONE. GTP_PARAM_COUNT_PLUS_ONE == GTP_PARAM_COUNT.
  The useful range for GTP_PARAM_COUNT is between 0 and 3 (inclusive).

> #include <boost/preprocessor/enum_params.hpp> // expands for 0 ... N-1
> #include <boost/preprocessor/repetition/enum_shifted_params.hpp> // expands for 1 ... N-1
>
> #if GTP_PARAM_COUNT == 0
> # define GTP_OPTIONAL_COMMA
> #else
> # define GTP_OPTIONAL_COMMA ,
> #endif
>
>
> // GTP_PARMS expands to " typename T0, typename T1, typename T2" if GTP_PARAM_COUNT is 3
> #define GTP_TEMPLATE_PARAMS BOOST_PP_ENUM_PARAMS(GTP_PARAM_COUNT, typename T)
>
> // expands to "typename R0 , typename T0, typename T1, typename T2" if GTP_PARAM_COUNT is 3
> #define GTP_FULL_TEMPLATE_PARAMS typename R0 GTP_OPTIONAL_COMMA GTP_TEMPLATE_PARAMS
>
> // GTP_PARAM expands to " T3 a3" if INDEX is 3
> #define GTP_PARAM(UNKNOWN1,INDEX,UNKNOWN2) BOOST_PP_CAT(T,I) BOOST_PP_CAT(a,I)
>
> // GTP_PARAMS expands to " T0 a0, T1 a1, T2 a2" if GTP_PARAM_COUNT is 3
> #define GTP_PARAMS BOOST_PP_ENUM(GTP_PARAM_COUNT,GTP_PARAM,BOOST_PP_EMPTY)
>
> // GTP_PARAM_TYPES expands to " T0, T1, T2" if GTP_PARAM_COUNT is 3
> #define GTP_PARAM_TYPES BOOST_PP_ENUM_PARAMS(GTP_PARAM_COUNT, T)
>
> // expands to "R0 , T0, T1, T2" if GTP_PARAM_COUNT is 3
> #define GTP_FULL_PARAM_TYPES R0 GTP_OPTIONAL_COMMA GTP_PARAM_TYPES
>
> // GTP_PARAM_NAMES expands to " a0, a1, a2" if GTP_PARAM_COUNT is 3
> #define GTP_PARAM_NAMES BOOST_PP_ENUM_PARAMS(GTP_PARAM_COUNT, a)
>
> // expands to "boost::function3 < R0 , T0, T1, T2 >" when GTP_PARAM_COUNT is 3
> #define GTP_BOOST_FUNCTION BOOST_PP_CAT(boost::function,GTP_PARAM_COUNT) < GTP_FULL_PARAM_TYPES >
>
> // expands to "boost::function3 < void , T0, T1, T2 >" when GTP_PARAM_COUNT is 3
> #define GTP_BOOST_FUNCTION_VOID BOOST_PP_CAT(boost::function,GTP_PARAM_COUNT) < void GTP_OPTIONAL_COMMA GTP_PARAM_TYPES >
>
> // expands to type_wrapper3 when GTP_PARAM_COUNT is 3
> #define GTP_TYPE_WRAPPER BOOST_PP_CAT(type_wrapper,GTP_PARAM_COUNT)
>
> //////////////////////////////////////////////////////////////
> // gtp_detail::type_wrapper for converting all input arguments
> namespace gtp_detail{
>
> template < GTP_FULL_TEMPLATE_PARAMS >
> struct GTP_TYPE_WRAPPER{
> static GTPInternalResponse wrap(GTP_BOOST_FUNCTION *(callback_function), GTPCommand cmd){
> unsigned int position = 0;
> /// \bug Must figure out how to auto generate this repetative body
> #if GTP_PARAM_COUNT >= 1
> assert(position < cmd.GetArgumentCount());
> T0 a0 = extract<T0>(cmd, position);
> #endif
> #if GTP_PARAM_COUNT >= 2
> assert(position < cmd.GetArgumentCount());
> T1 a1 = extract<T1>(cmd,position);
> #endif
> #if GTP_PARAM_COUNT >= 3
> assert(position < cmd.GetArgumentCount());
> T2 a2 = extract<T2>(cmd,position);
> #endif
> assert(position == cmd.GetArgumentCount());
> return converter<R0, GTPInternalResponse>( (*callback_function)(GTP_PARAM_NAMES) );
> }
> };
>
> template < GTP_TEMPLATE_PARAMS >
> struct GTP_TYPE_WRAPPER < void GTP_OPTIONAL_COMMA GTP_PARAM_TYPES >{
> static GTPInternalResponse wrap(GTP_BOOST_FUNCTION_VOID *(callback_function), GTPCommand cmd){
> unsigned int position = 0;
> /// \bug Must figure out how to auto generate this repetative body
> #if GTP_PARAM_COUNT >= 1
> assert(position < cmd.GetArgumentCount());
> T0 a0 = extract<T0>(cmd, position);
> #endif
> #if GTP_PARAM_COUNT >= 2
> assert(position < cmd.GetArgumentCount());
> T1 a1 = extract<T1>(cmd,position);
> #endif
> #if GTP_PARAM_COUNT >= 3
> assert(position < cmd.GetArgumentCount());
> T2 a2 = extract<T2>(cmd,position);
> #endif
> assert(position == cmd.GetArgumentCount());
> (*callback_function)(GTP_PARAM_NAMES);
> return GTPInternalResponse();
> }
> };
>
> };
>
> ///////////////////////////////////////////////////////
> // GTPCommandCallBack accepting a boost function object
>
> // expands to GTPFunctionObject3 when GTP_PARAM_COUNT is 3
> #define GTP_COMMAND_CALLBACK BOOST_PP_CAT(GTPCommandCallBack,GTP_PARAM_COUNT)
>
> // expands to " boost::lambda::_1, boost::lambda::_2, boost::lambda::_3" if GTP_PARAM_COUNT is 3
> #define GTP_LAMBDA_PARAMS BOOST_PP_ENUM_SHIFTED_PARAMS(GTP_PARAM_COUNT_PLUS_ONE, boost::lambda::_)
>
> template< GTP_FULL_TEMPLATE_PARAMS > inline
> GTPFunctionObject* GTP_COMMAND_CALLBACK(GTP_BOOST_FUNCTION *callback_function){
> return new GTPFunctionObject(boost::lambda::bind((&gtp_detail::GTP_TYPE_WRAPPER<GTP_FULL_PARAM_TYPES>::wrap), callback_function GTP_OPTIONAL_COMMA GTP_LAMBDA_PARAMS));
> }


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net