diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 56611f3..3e225b7 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -377,10 +377,10 @@ /// \subsection functionobjects Function Objects /// /// Functions are first class objects in Chaiscript and ChaiScript supports automatic conversion -/// between ChaiScript functions and boost::function objects. +/// between ChaiScript functions and std::function objects. /// /// \code -/// void callafunc(const boost::function &t_func) +/// void callafunc(const std::function &t_func) /// { /// t_func("bob"); /// } @@ -390,9 +390,9 @@ /// chaiscript::ChaiScript chai; /// chai.add(chaiscript::fun(&callafunc), "callafunc"); /// chai("callafunc(fun(x) { print(x); })"); // pass a lambda function to the registered function -/// // which expects a typed boost::function +/// // which expects a typed std::function /// -/// boost::function f = chai.eval >("dump_system"); +/// std::function f = chai.eval >("dump_system"); /// f(); // call the ChaiScript function dump_system, from C++ /// } /// \endcode diff --git a/include/chaiscript/dispatchkit/bind_first.hpp b/include/chaiscript/dispatchkit/bind_first.hpp index ae468f1..12c09a0 100644 --- a/include/chaiscript/dispatchkit/bind_first.hpp +++ b/include/chaiscript/dispatchkit/bind_first.hpp @@ -37,9 +37,9 @@ namespace chaiscript /// /// \param[in] f method pointer to bind /// \param[in] o object to bind as first parameter - /// \returns a new boost::function object with one fewer parameters than the function passed in. + /// \returns a new std::function object with one fewer parameters than the function passed in. template - boost::function + std::function bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const O &o) { return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); @@ -50,9 +50,9 @@ namespace chaiscript /// /// \param[in] f method pointer to bind /// \param[in] o object to bind as first parameter - /// \returns a new boost::function object with one fewer parameters than the function passed in. + /// \returns a new std::function object with one fewer parameters than the function passed in. template - boost::function + std::function bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)) const, const O &o) { return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); @@ -63,23 +63,23 @@ namespace chaiscript /// /// \param[in] f method pointer to bind /// \param[in] o object to bind as first parameter - /// \returns a new boost::function object with one fewer parameters than the function passed in. + /// \returns a new std::function object with one fewer parameters than the function passed in. template - boost::function + std::function bind_first(Ret (*f)(BOOST_PP_ENUM_PARAMS(m, Param)), const O &o) { return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); } - /// \brief Helper function for binding the first parameter of a boost::function object. Used in chaiscript::fun overloads + /// \brief Helper function for binding the first parameter of a std::function object. Used in chaiscript::fun overloads /// that take 1 or 2 parameters to pre-bind to the function. /// /// \param[in] f method pointer to bind /// \param[in] o object to bind as first parameter - /// \returns a new boost::function object with one fewer parameters than the function passed in. + /// \returns a new std::function object with one fewer parameters than the function passed in. template - boost::function - bind_first(const boost::function &f, const O &o) + std::function + bind_first(const std::function &f, const O &o) { return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); } diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 0129471..5aafd1b 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -355,7 +355,7 @@ namespace chaiscript } template - static boost::function (const dispatch::Proxy_Function_Base*)> return_boxed_value_vector(const Function &f) + static std::function (const dispatch::Proxy_Function_Base*)> return_boxed_value_vector(const Function &f) { return boost::bind(&do_return_boxed_value_vector, f, _1); } @@ -388,7 +388,7 @@ namespace chaiscript m->add(constructor(), "runtime_error"); - m->add(fun(boost::function(&what)), "what"); + m->add(fun(std::function(&what)), "what"); m->add(user_type(), "Dynamic_Object"); m->add(constructor(), "Dynamic_Object"); diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 96710c0..0bb93b6 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -227,10 +227,10 @@ 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 + fun(std::function (boost::mem_fn(static_cast(&ContainerType::at)))), "[]"); m->add( - fun(boost::function + fun(std::function (boost::mem_fn(static_cast(&ContainerType::at)))), "[]"); return m; @@ -255,7 +255,7 @@ namespace chaiscript template ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { - m->add(fun(boost::function(boost::mem_fn(&ContainerType::size))), "size"); + m->add(fun(std::function(boost::mem_fn(&ContainerType::size))), "size"); m->add(fun(&ContainerType::empty), "empty"); m->add(fun(&ContainerType::clear), "clear"); @@ -390,7 +390,7 @@ namespace chaiscript template ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { - m->add(fun(boost::function(boost::mem_fn(&ContainerType::count))), "count"); + m->add(fun(std::function(boost::mem_fn(&ContainerType::count))), "count"); return m; } @@ -513,7 +513,7 @@ namespace chaiscript typedef typename String::size_type (String::*find_func_ptr)(const String &, typename String::size_type) const; - typedef boost::function find_func; + typedef std::function find_func; 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"); diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index ea188bb..de4ccc3 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -32,7 +32,7 @@ namespace chaiscript /// \throws exception::bad_boxed_cast If the requested conversion is not possible /// /// boxed_cast will attempt to make conversions between value, &, *, std::shared_ptr, boost::reference_wrapper, - /// and boost::function (const and non-const) where possible. boxed_cast is used internally during function + /// and std::function (const and non-const) where possible. boxed_cast is used internally during function /// dispatch. This means that all of these conversions will be attempted automatically for you during /// ChaiScript function calls. /// @@ -43,7 +43,7 @@ namespace chaiscript /// \li Boxed_Value constructed from std::shared_ptr or value types can be extracted as reference, /// pointer, value, or std::shared_ptr types /// - /// Conversions to boost::function objects are attempted as well + /// Conversions to std::function objects are attempted as well /// /// Example: /// \code @@ -59,11 +59,11 @@ namespace chaiscript /// const int &cir = chaiscript::boxed_cast(bv); /// \endcode /// - /// boost::function conversion example + /// std::function conversion example /// \code /// chaiscript::ChaiScript chai; /// Boxed_Value bv = chai.eval("`+`"); // Get the functor for the + operator which is built in - /// boost::function f = chaiscript::boxed_cast >(bv); + /// std::function f = chaiscript::boxed_cast >(bv); /// int i = f(2,3); /// assert(i == 5); /// \endcode diff --git a/include/chaiscript/dispatchkit/function_call.hpp b/include/chaiscript/dispatchkit/function_call.hpp index 9dea81c..ec62c4c 100644 --- a/include/chaiscript/dispatchkit/function_call.hpp +++ b/include/chaiscript/dispatchkit/function_call.hpp @@ -25,13 +25,13 @@ namespace chaiscript /** * Build a function caller that knows how to dispatch on a set of functions * example: - * boost::function f = + * std::function f = * build_function_caller(dispatchkit.get_function("print")); - * \returns A boost::function object for dispatching + * \returns A std::function object for dispatching * \param[in] funcs the set of functions to dispatch on. */ template - boost::function + std::function functor(const std::vector &funcs) { FunctionType *p=0; @@ -45,14 +45,14 @@ namespace chaiscript * example: * void my_function(Proxy_Function f) * { - * boost::function local_f = + * std::function local_f = * build_function_caller(f); * } - * \returns A boost::function object for dispatching + * \returns A std::function object for dispatching * \param[in] func A function to execute. */ template - boost::function + std::function functor(Const_Proxy_Function func) { std::vector funcs; @@ -65,7 +65,7 @@ namespace chaiscript * and creating a typesafe C++ function caller from it. */ template - boost::function + std::function functor(const Boxed_Value &bv) { return functor(boxed_cast(bv)); @@ -74,12 +74,12 @@ namespace chaiscript namespace detail{ /** - * Cast helper to handle automatic casting to const boost::function & + * Cast helper to handle automatic casting to const std::function & */ template - struct Cast_Helper &> + struct Cast_Helper &> { - typedef boost::function Result_Type; + typedef std::function Result_Type; static Result_Type cast(const Boxed_Value &ob) { @@ -87,18 +87,18 @@ namespace chaiscript { return dispatch::functor(ob); } else { - return Cast_Helper_Inner &>::cast(ob); + return Cast_Helper_Inner &>::cast(ob); } } }; /** - * Cast helper to handle automatic casting to boost::function + * Cast helper to handle automatic casting to std::function */ template - struct Cast_Helper > + struct Cast_Helper > { - typedef boost::function Result_Type; + typedef std::function Result_Type; static Result_Type cast(const Boxed_Value &ob) { @@ -106,18 +106,18 @@ namespace chaiscript { return dispatch::functor(ob); } else { - return Cast_Helper_Inner >::cast(ob); + return Cast_Helper_Inner >::cast(ob); } } }; /** - * Cast helper to handle automatic casting to const boost::function + * Cast helper to handle automatic casting to const std::function */ template - struct Cast_Helper > + struct Cast_Helper > { - typedef boost::function Result_Type; + typedef std::function Result_Type; static Result_Type cast(const Boxed_Value &ob) { @@ -125,7 +125,7 @@ namespace chaiscript { return dispatch::functor(ob); } else { - return Cast_Helper_Inner >::cast(ob); + return Cast_Helper_Inner >::cast(ob); } } }; diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index e7e7b91..23c4d20 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -90,7 +90,7 @@ namespace chaiscript * used internally for unwrapping a function call's types */ template - boost::function + std::function build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector &funcs) { if (funcs.size() == 1) diff --git a/include/chaiscript/dispatchkit/proxy_constructors.hpp b/include/chaiscript/dispatchkit/proxy_constructors.hpp index 6c6e542..9fabd51 100644 --- a/include/chaiscript/dispatchkit/proxy_constructors.hpp +++ b/include/chaiscript/dispatchkit/proxy_constructors.hpp @@ -70,7 +70,7 @@ namespace chaiscript Proxy_Function build_constructor_(Class (*)(BOOST_PP_ENUM_PARAMS(n, Param))) { typedef std::shared_ptr (sig)(BOOST_PP_ENUM_PARAMS(n, Param)); - return Proxy_Function(new Proxy_Function_Impl(boost::function(&(constructor_)))); + return Proxy_Function(new Proxy_Function_Impl(std::function(&(constructor_)))); } } } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 300a021..e6f0e1a 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -207,7 +207,7 @@ namespace chaiscript { public: Dynamic_Proxy_Function( - const boost::function &)> &t_f, + const std::function &)> &t_f, int t_arity=-1, const AST_NodePtr &t_parsenode = AST_NodePtr(), const std::string &t_description = "", @@ -304,7 +304,7 @@ namespace chaiscript return types; } - boost::function &)> m_f; + std::function &)> m_f; int m_arity; std::string m_description; Proxy_Function m_guard; @@ -440,14 +440,14 @@ namespace chaiscript /** * The standard typesafe function call implementation of Proxy_Function - * It takes a boost::function<> object and performs runtime + * It takes a std::function<> object and performs runtime * type checking of Boxed_Value parameters, in a type safe manner */ template class Proxy_Function_Impl : public Proxy_Function_Base { public: - Proxy_Function_Impl(const boost::function &f) + Proxy_Function_Impl(const std::function &f) : Proxy_Function_Base(detail::build_param_type_list(static_cast(0))), m_f(f), m_dummy_func(0) { @@ -483,7 +483,7 @@ namespace chaiscript return ""; } - boost::function internal_function() const + std::function internal_function() const { return m_f; } @@ -491,11 +491,11 @@ namespace chaiscript protected: virtual Boxed_Value do_call(const std::vector ¶ms) const { - return detail::Do_Call::result_type>::go(m_f, params); + return detail::Do_Call::result_type>::go(m_f, params); } private: - boost::function m_f; + std::function m_f; Func *m_dummy_func; }; diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index acd85d2..235a935 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -88,7 +88,7 @@ namespace chaiscript * the bad_boxed_cast is passed up to the caller. */ template - Ret call_func(const boost::function &f, + Ret call_func(const std::function &f, const std::vector ¶ms) { if (params.size() != n) @@ -137,7 +137,7 @@ namespace chaiscript struct Do_Call { template - static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) + static Boxed_Value go(const std::function &fun, const std::vector ¶ms) { return Handle_Return::handle(call_func(fun, params)); } @@ -147,7 +147,7 @@ namespace chaiscript struct Do_Call { template - static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) + static Boxed_Value go(const std::function &fun, const std::vector ¶ms) { call_func(fun, params); return Handle_Return::handle(); diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 83e5687..65a83ee 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -31,7 +31,7 @@ namespace chaiscript return Proxy_Function( new Proxy_Function_Impl< typename boost::function_types::function_type >::type> ( - boost::function< + std::function< typename boost::function_types::function_type >::type >(t))); } @@ -46,7 +46,7 @@ namespace chaiscript return Proxy_Function( new Proxy_Function_Impl< typename boost::function_types::function_type >::type> ( - boost::function< + std::function< typename boost::function_types::function_type >::type >(boost::mem_fn(t)))); } @@ -65,19 +65,19 @@ namespace chaiscript } } - /// \brief Creates a new Proxy_Function object from a boost::function object - /// \param[in] f boost::function to expose to ChaiScript + /// \brief Creates a new Proxy_Function object from a std::function object + /// \param[in] f std::function to expose to ChaiScript /// /// \b Example: /// \code - /// boost::function f = get_some_function(); + /// std::function f = get_some_function(); /// chaiscript::ChaiScript chai; /// chai.add(fun(f), "some_function"); /// \endcode /// /// \sa \ref addingfunctions template - Proxy_Function fun(const boost::function &f) + Proxy_Function fun(const std::function &f) { return Proxy_Function(new dispatch::Proxy_Function_Impl(f)); } diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 15cc6e7..7cef971 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -1147,7 +1147,7 @@ namespace chaiscript virtual ~Attr_Decl_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ try { - t_ss.add(fun(boost::function(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, this->children[0]->text, + t_ss.add(fun(std::function(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, this->children[0]->text, this->children[1]->text, _1))), this->children[1]->text); } diff --git a/samples/example.cpp b/samples/example.cpp index 5b3cbbf..2ea6e8b 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -40,7 +40,7 @@ void hello_constructor(const chaiscript::Boxed_Value & /*o*/) struct System { - std::map > m_callbacks; + std::map > m_callbacks; void add_callback(const std::string &t_name, const chaiscript::Proxy_Function &t_func) @@ -52,7 +52,7 @@ struct System void do_callbacks(const std::string &inp) { log("Running Callbacks: " + inp); - for (std::map >::iterator itr = m_callbacks.begin(); + for (std::map >::iterator itr = m_callbacks.begin(); itr != m_callbacks.end(); ++itr) { @@ -87,7 +87,7 @@ int main(int /*argc*/, char * /*argv*/[]) { // Let's use chaiscript to add a new lambda callback to our system. // The function "{ 'Callback1' + x }" is created in chaiscript and passed into our C++ application // in the "add_callback" function of struct System the chaiscript function is converted into a - // boost::function, so it can be handled and called easily and type-safely + // std::function, so it can be handled and called easily and type-safely chai.eval("system.add_callback(\"#1\", fun(x) { \"Callback1 \" + x });"); // Because we are sharing the "system" object with the chaiscript engine we have equal @@ -108,14 +108,14 @@ int main(int /*argc*/, char * /*argv*/[]) { // A shortcut to using eval is just to use the chai operator() chai("log(\"Test Module\", \"Test Message\");"); - //Finally, it is possible to register any boost::function as a system function, in this + //Finally, it is possible to register any std::function as a system function, in this //way, we can, for instance add a bound member function to the system chai.add(fun(&System::do_callbacks, boost::ref(system), std::string("Bound Test")), "do_callbacks"); //Call bound version of do_callbacks chai("do_callbacks()"); - boost::function caller = chai.eval >("fun() { system.do_callbacks(\"From Functor\"); }"); + std::function caller = chai.eval >("fun() { system.do_callbacks(\"From Functor\"); }"); caller(); @@ -139,7 +139,7 @@ int main(int /*argc*/, char * /*argv*/[]) { //To do: Add examples of handling Boxed_Values directly when needed //Creating a functor on the stack and using it immediatly - int x = chai.eval >("fun (x, y) { return x + y; }")(5, 6); + int x = chai.eval >("fun (x, y) { return x + y; }")(5, 6); log("Functor test output", boost::lexical_cast(x)); @@ -165,7 +165,7 @@ int main(int /*argc*/, char * /*argv*/[]) { //Dynamic objects test chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Function("TestType", fun(&hello_world))), "hello_world"); chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Constructor("TestType", fun(&hello_constructor))), "TestType"); - chai.add(fun(boost::function(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", _1))), "attr"); + chai.add(fun(std::function(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", _1))), "attr"); chai.eval("var x = TestType()"); // chai.eval("x.attr = \"hi\""); diff --git a/src/main.cpp b/src/main.cpp index bc83332..b1ca539 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,7 +52,7 @@ void version(int){ std::cout << "chai: compiled " << __TIME__ << " " << __DATE__ << std::endl; } -bool throws_exception(const boost::function &f) +bool throws_exception(const std::function &f) { try { f(); @@ -63,7 +63,7 @@ bool throws_exception(const boost::function &f) return false; } -chaiscript::exception::eval_error get_eval_error(const boost::function &f) +chaiscript::exception::eval_error get_eval_error(const std::function &f) { try { f(); @@ -113,7 +113,7 @@ void interactive(chaiscript::ChaiScript& chai) //Then, we try to print the result of the evaluation to the user if (!val.get_type_info().bare_equal(chaiscript::user_type())) { try { - std::cout << chai.eval >("to_string")(val) << std::endl; + std::cout << chai.eval >("to_string")(val) << std::endl; } catch (...) {} //If we can't, do nothing } diff --git a/unittests/functor_cast_test.cpp b/unittests/functor_cast_test.cpp index 1f6f7ec..7c76ca2 100644 --- a/unittests/functor_cast_test.cpp +++ b/unittests/functor_cast_test.cpp @@ -1,6 +1,6 @@ #include -double test_call(const boost::function &f, int val) +double test_call(const std::function &f, int val) { return f(val); } diff --git a/unittests/functor_creation_test.cpp b/unittests/functor_creation_test.cpp index 6578a6d..6a78fee 100644 --- a/unittests/functor_creation_test.cpp +++ b/unittests/functor_creation_test.cpp @@ -7,15 +7,15 @@ int main() chai.eval("def func() { print(\"Hello World\"); } "); - boost::function f = chai.eval >("func"); + std::function f = chai.eval >("func"); f(); - if (chai.eval >("to_string")(6) != "6") + if (chai.eval >("to_string")(6) != "6") { return EXIT_FAILURE; } - if (chai.eval >("to_string")(chaiscript::var(6)) == "6") + if (chai.eval >("to_string")(chaiscript::var(6)) == "6") { return EXIT_SUCCESS; } else {