From 70047424f9a5d54e6d3c78a8f0f062415bf35fed Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 28 Dec 2009 17:16:03 +0000 Subject: [PATCH] Get compiling with Visual Studio 10 beta 2. Had to work around issues with conflicts between boost::function and VisualStudio's std::tr1::mem_fn (http://social.msdn.microsoft.com/Forums/en/vcprerelease/thread/e04d93ed-d686-4ef6-9939-26e34c0955eb). Also had to work around non-standard overloaded std member functions in std::map (http://msdn.microsoft.com/en-us/library/fe72hft9(VS.100).aspx) Strongly consider rolling this back when the issues are resolved between microsoft and boost. Also, needs to be tested across all platforms. --- include/chaiscript/dispatchkit/bind_first.hpp | 4 +-- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 27 ++++++++++--------- .../dispatchkit/register_function.hpp | 27 +++++++++++++++---- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/include/chaiscript/dispatchkit/bind_first.hpp b/include/chaiscript/dispatchkit/bind_first.hpp index 934783b..1d48e32 100644 --- a/include/chaiscript/dispatchkit/bind_first.hpp +++ b/include/chaiscript/dispatchkit/bind_first.hpp @@ -35,14 +35,14 @@ namespace chaiscript boost::function bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const O &o) { - return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); + return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); } template boost::function bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param))const, const O &o) { - return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); + return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); } template diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index bbf0cce..b35f01b 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -134,7 +134,7 @@ namespace chaiscript //In the interest of runtime safety for the m, we prefer the at() method for [] access, //to throw an exception in an out of bounds condition. m->add( - fun(boost::function(static_cast(&ContainerType::at))), "[]"); + fun(boost::function(boost::mem_fn(static_cast(&ContainerType::at)))), "[]"); return m; } @@ -158,7 +158,7 @@ namespace chaiscript template ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { - m->add(fun(boost::function(&ContainerType::size)), "size"); + m->add(fun(boost::function(boost::mem_fn(&ContainerType::size))), "size"); m->add(fun(&ContainerType::empty), "empty"); m->add(fun(&ContainerType::clear), "clear"); @@ -252,7 +252,8 @@ namespace chaiscript push_back_name = "push_back"; } - m->add(fun(&ContainerType::push_back), push_back_name); + typedef void (ContainerType::*pushback)(const typename ContainerType::value_type &); + m->add(fun(static_cast(&ContainerType::push_back)), push_back_name); m->add(fun(&ContainerType::pop_back), "pop_back"); return m; } @@ -319,8 +320,7 @@ namespace chaiscript template ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { -// m->add(fun(&ContainerType::count), "count"); - m->add(fun(boost::function(&ContainerType::count)), "count"); + m->add(fun(boost::function(boost::mem_fn(&ContainerType::count))), "count"); return m; } @@ -333,7 +333,9 @@ namespace chaiscript ModulePtr map_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) { m->add(user_type(), type); - m->add(fun(&MapType::operator[]), "[]"); + + typedef typename MapType::mapped_type &(MapType::*elemaccess)(const typename MapType::key_type &); + m->add(fun(static_cast(&MapType::operator[])), "[]"); container_type(type, m); assignable_type(type, m); @@ -384,7 +386,6 @@ namespace chaiscript return m; } - /** * Add a String container * http://www.sgi.com/tech/stl/basic_string.html @@ -417,12 +418,12 @@ namespace chaiscript typedef boost::function find_func; - m->add(fun(find_func(static_cast(&String::find))), "find"); - m->add(fun(find_func(static_cast(&String::rfind))), "rfind"); - m->add(fun(find_func(static_cast(&String::find_first_of))), "find_first_of"); - m->add(fun(find_func(static_cast(&String::find_last_of))), "find_last_of"); - m->add(fun(find_func(static_cast(&String::find_first_not_of))), "find_first_not_of"); - m->add(fun(find_func(static_cast(&String::find_last_not_of))), "find_last_not_of"); + m->add(fun(find_func(boost::mem_fn(static_cast(&String::find)))), "find"); + m->add(fun(find_func(boost::mem_fn(static_cast(&String::rfind)))), "rfind"); + m->add(fun(find_func(boost::mem_fn(static_cast(&String::find_first_of)))), "find_first_of"); + m->add(fun(find_func(boost::mem_fn(static_cast(&String::find_last_of)))), "find_last_of"); + m->add(fun(find_func(boost::mem_fn(static_cast(&String::find_first_not_of)))), "find_first_not_of"); + m->add(fun(find_func(boost::mem_fn(static_cast(&String::find_last_not_of)))), "find_last_not_of"); return m; } diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 5daea43..f6ba525 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -14,12 +14,13 @@ #include #include #include +#include namespace chaiscript { namespace detail { - template + template struct Fun_Helper { template @@ -31,11 +32,27 @@ namespace chaiscript boost::function< typename boost::function_types::function_type >::type >(t))); - } - }; + } + }; template<> - struct Fun_Helper + struct Fun_Helper + { + template + static Proxy_Function go(T t) + { + return Proxy_Function( + new Proxy_Function_Impl< + typename boost::function_types::function_type >::type> ( + boost::function< + typename boost::function_types::function_type >::type + >(boost::mem_fn(t)))); + } + }; + + + template<> + struct Fun_Helper { template static Proxy_Function go(T Class::* m) @@ -55,7 +72,7 @@ namespace chaiscript template Proxy_Function fun(T t) { - return detail::Fun_Helper::value>::go(t); + return detail::Fun_Helper::value, boost::function_types::is_member_function_pointer::value>::go(t); } template