Remove need for boost::function_types library

This commit is contained in:
Jason Turner
2011-09-12 08:18:51 -06:00
parent 194001f9a1
commit 6f282b6a56
5 changed files with 42 additions and 31 deletions

View File

@@ -12,8 +12,8 @@
#include "register_function.hpp" #include "register_function.hpp"
#include "operators.hpp" #include "operators.hpp"
#include "boxed_number.hpp" #include "boxed_number.hpp"
#include <boost/function_types/result_type.hpp>
#include <sstream> #include <sstream>
#include <type_traits>
namespace chaiscript namespace chaiscript
{ {
@@ -346,7 +346,9 @@ namespace chaiscript
static std::vector<Boxed_Value> do_return_boxed_value_vector(FunctionType f, static std::vector<Boxed_Value> do_return_boxed_value_vector(FunctionType f,
const dispatch::Proxy_Function_Base *b) const dispatch::Proxy_Function_Base *b)
{ {
typedef typename boost::function_types::result_type<FunctionType>::type Vector; typedef decltype(std::mem_fn(f)) MemFunType;
typedef typename MemFunType::result_type Vector;
Vector v = (b->*f)(); Vector v = (b->*f)();
std::vector<Boxed_Value> vbv; std::vector<Boxed_Value> vbv;

View File

@@ -15,6 +15,7 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include <deque> #include <deque>
#include <algorithm>
#include "boxed_value.hpp" #include "boxed_value.hpp"
#include "type_info.hpp" #include "type_info.hpp"

View File

@@ -246,9 +246,9 @@ namespace chaiscript
{ {
//Can only be used with related polymorphic types //Can only be used with related polymorphic types
//may be expanded some day to support conversions other than child -> parent //may be expanded some day to support conversions other than child -> parent
BOOST_STATIC_ASSERT((std::is_base_of<Base,Derived>::value)); static_assert(std::is_base_of<Base,Derived>::value, "Classes are not related by inheritance");
BOOST_STATIC_ASSERT(std::is_polymorphic<Base>::value); static_assert(std::is_polymorphic<Base>::value, "Base class must be polymorphic");
BOOST_STATIC_ASSERT(std::is_polymorphic<Derived>::value); static_assert(std::is_polymorphic<Derived>::value, "Derived class must be polymorphic");
return detail::Dynamic_Conversions::create<Base, Derived>(); return detail::Dynamic_Conversions::create<Base, Derived>();
} }

View File

@@ -9,8 +9,6 @@
#include "dispatchkit.hpp" #include "dispatchkit.hpp"
#include "bind_first.hpp" #include "bind_first.hpp"
#include <boost/function_types/components.hpp>
#include <boost/function_types/function_type.hpp>
namespace chaiscript namespace chaiscript
{ {
@@ -18,39 +16,48 @@ namespace chaiscript
{ {
namespace detail namespace detail
{ {
template<bool Object, bool MemFn> template<typename T>
struct FunctionSignature
{
};
template<typename Sig>
struct FunctionSignature<std::function<Sig> >
{
typedef Sig Signature;
};
template<typename Ret, typename ... Args>
std::function<Ret (Args...) > to_function(Ret (*func)(Args...))
{
return std::function<Ret (Args...)>(func);
}
template<typename Ret, typename Class, typename ... Args>
std::function<Ret (Class &, Args...) > to_function(Ret (Class::*func)(Args...))
{
return std::function<Ret (Class &, Args...)>(func);
}
template<typename Ret, typename Class, typename ... Args>
std::function<Ret (const Class &, Args...) > to_function(Ret (Class::*func)(Args...) const)
{
return std::function<Ret (const Class &, Args...)>(func);
}
template<bool Object>
struct Fun_Helper struct Fun_Helper
{ {
template<typename T> template<typename T>
static Proxy_Function go(T t) static Proxy_Function go(T t)
{ {
return Proxy_Function( return Proxy_Function(
new Proxy_Function_Impl< new Proxy_Function_Impl<typename FunctionSignature<decltype(to_function(t)) >::Signature>(to_function(t)));
typename boost::function_types::function_type<boost::function_types::components<T> >::type> (
std::function<
typename boost::function_types::function_type<boost::function_types::components<T> >::type
>(t)));
} }
}; };
template<> template<>
struct Fun_Helper<false, true> struct Fun_Helper<true>
{
template<typename T>
static Proxy_Function go(T t)
{
return Proxy_Function(
new Proxy_Function_Impl<
typename boost::function_types::function_type<boost::function_types::components<T> >::type> (
std::function<
typename boost::function_types::function_type<boost::function_types::components<T> >::type
>(std::mem_fn(t))));
}
};
template<>
struct Fun_Helper<true, false>
{ {
template<typename T, typename Class> template<typename T, typename Class>
static Proxy_Function go(T Class::* m) static Proxy_Function go(T Class::* m)
@@ -101,7 +108,7 @@ namespace chaiscript
template<typename T> template<typename T>
Proxy_Function fun(T t) Proxy_Function fun(T t)
{ {
return dispatch::detail::Fun_Helper<std::is_member_object_pointer<T>::value, std::is_member_function_pointer<T>::value>::go(t); return dispatch::detail::Fun_Helper<std::is_member_object_pointer<T>::value>::go(t);
} }
/// \brief Creates a new Proxy_Function object from a free function, member function or data member and binds the first parameter of it /// \brief Creates a new Proxy_Function object from a free function, member function or data member and binds the first parameter of it

View File

@@ -10,6 +10,7 @@
#include <exception> #include <exception>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <cstring>
#include "chaiscript_prelude.hpp" #include "chaiscript_prelude.hpp"
#include "chaiscript_common.hpp" #include "chaiscript_common.hpp"