Fix problem with functor<>() not casting to the proper type and add unit test for this case

This commit is contained in:
Jason Turner
2010-08-03 15:19:20 +00:00
parent e1fbf54e40
commit a122403c20
4 changed files with 28 additions and 8 deletions

View File

@@ -27,7 +27,7 @@ namespace chaiscript
*/
template<typename FunctionType>
boost::function<FunctionType>
functor(const std::vector<std::pair<std::string, Proxy_Function > > &funcs)
functor(const std::vector<std::pair<std::string, Const_Proxy_Function > > &funcs)
{
FunctionType *p=0;
return detail::build_function_caller_helper(p, funcs);
@@ -48,9 +48,9 @@ namespace chaiscript
*/
template<typename FunctionType>
boost::function<FunctionType>
functor(Proxy_Function func)
functor(Const_Proxy_Function func)
{
std::vector<std::pair<std::string, Proxy_Function > > funcs;
std::vector<std::pair<std::string, Const_Proxy_Function > > funcs;
funcs.push_back(std::make_pair(std::string(), func));
return functor<FunctionType>(funcs);
}
@@ -63,7 +63,7 @@ namespace chaiscript
boost::function<FunctionType>
functor(const Boxed_Value &bv)
{
return functor<FunctionType>(boxed_cast<Proxy_Function >(bv));
return functor<FunctionType>(boxed_cast<Const_Proxy_Function >(bv));
}
}

View File

@@ -32,7 +32,7 @@ namespace chaiscript
template<typename Ret>
struct Function_Caller_Ret
{
static Ret call(const std::vector<std::pair<std::string, Proxy_Function > > &t_funcs,
static Ret call(const std::vector<std::pair<std::string, Const_Proxy_Function > > &t_funcs,
const std::vector<Boxed_Value> &params)
{
return boxed_cast<Ret>(dispatch(t_funcs, params));
@@ -45,7 +45,7 @@ namespace chaiscript
template<>
struct Function_Caller_Ret<void>
{
static void call(const std::vector<std::pair<std::string, Proxy_Function > > &t_funcs,
static void call(const std::vector<std::pair<std::string, Const_Proxy_Function > > &t_funcs,
const std::vector<Boxed_Value> &params)
{
dispatch(t_funcs, params);
@@ -70,7 +70,7 @@ namespace chaiscript
* used internally for unwrapping a function call's types
*/
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
Ret function_caller(const std::vector<std::pair<std::string, Proxy_Function > > &funcs
Ret function_caller(const std::vector<std::pair<std::string, Const_Proxy_Function > > &funcs
BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) )
{
std::vector<Boxed_Value> params;
@@ -85,7 +85,7 @@ namespace chaiscript
*/
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param)) >
build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector<std::pair<std::string, Proxy_Function> > &funcs)
build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector<std::pair<std::string, Const_Proxy_Function> > &funcs)
{
return boost::bind(&function_caller<Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param)>, funcs
BOOST_PP_ENUM_TRAILING(n, curry, ~));