From aa402fdfdefe6501ee4cfae492075dd3ebfee886 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 10:52:59 -0600 Subject: [PATCH] swap boost::reference_wrapper for std::reference_wrapper --- include/chaiscript/chaiscript.hpp | 6 +-- include/chaiscript/dispatchkit/boxed_cast.hpp | 4 +- .../dispatchkit/boxed_cast_helper.hpp | 39 ++++++++++--------- .../chaiscript/dispatchkit/boxed_value.hpp | 16 ++++---- .../dispatchkit/dynamic_cast_conversion.hpp | 4 +- .../dispatchkit/function_call_detail.hpp | 2 +- .../chaiscript/dispatchkit/handle_return.hpp | 6 +-- .../dispatchkit/register_function.hpp | 4 +- include/chaiscript/dispatchkit/type_info.hpp | 8 ++-- .../chaiscript/language/chaiscript_engine.hpp | 12 +++--- .../chaiscript/language/chaiscript_eval.hpp | 14 +++---- samples/example.cpp | 2 +- src/multithreaded.cpp | 2 +- unittests/boxed_cast_test.cpp | 24 ++++++------ 14 files changed, 72 insertions(+), 71 deletions(-) diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 3e225b7..497c9c4 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -298,7 +298,7 @@ /// \subsection pointerconversions Pointer / Object Conversions /// /// As much as possible, ChaiScript attempts to convert between &, *, const &, const *, std::shared_ptr, -/// std::shared_ptr, boost::reference_wrapper, boost::reference_wrapper and value types automatically. +/// std::shared_ptr, std::reference_wrapper, std::reference_wrapper and value types automatically. /// /// If a chaiscript::var object was created in C++ from a pointer, it cannot be convered to a shared_ptr (this would add invalid reference counting). /// Const may be added, but never removed. @@ -315,8 +315,8 @@ /// void fun6(std::shared_ptr); /// void fun7(const std::shared_ptr &); /// void fun8(const std::shared_ptr &); -/// void fun9(boost::reference_wrapper); -/// void fun10(boost::reference_wrapper); +/// void fun9(std::reference_wrapper); +/// void fun10(std::reference_wrapper); /// /// int main() /// { diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index be13422..59ccbfa 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -29,14 +29,14 @@ namespace chaiscript /// \returns Type equivalent to the requested type /// \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, + /// boxed_cast will attempt to make conversions between value, &, *, std::shared_ptr, std::reference_wrapper, /// 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. /// /// \li non-const values can be extracted as const or non-const /// \li const values can be extracted only as const - /// \li Boxed_Value constructed from pointer or boost::reference_wrapper can be extracted as reference, + /// \li Boxed_Value constructed from pointer or std::reference_wrapper can be extracted as reference, /// pointer or value types /// \li Boxed_Value constructed from std::shared_ptr or value types can be extracted as reference, /// pointer, value, or std::shared_ptr types diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index 2800c74..15c237d 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -26,7 +26,7 @@ namespace chaiscript template struct Cast_Helper_Inner { - typedef typename boost::reference_wrapper::type > Result_Type; + typedef typename std::reference_wrapper::type > Result_Type; static Result_Type cast(const Boxed_Value &ob) { @@ -34,16 +34,16 @@ namespace chaiscript { if (!ob.get_type_info().is_const()) { - return boost::cref((boost::any_cast >(ob.get())).get()); + return std::cref((boost::any_cast >(ob.get())).get()); } else { - return boost::any_cast >(ob.get()); + return boost::any_cast >(ob.get()); } } else { if (!ob.get_type_info().is_const()) { - return boost::cref(*(boost::any_cast >(ob.get()))); + return std::cref(*(boost::any_cast >(ob.get()))); } else { - return boost::cref(*(boost::any_cast >(ob.get()))); + return std::cref(*(boost::any_cast >(ob.get()))); } } } @@ -76,9 +76,9 @@ namespace chaiscript { if (!ob.get_type_info().is_const()) { - return (boost::any_cast >(ob.get())).get_pointer(); + return &(boost::any_cast >(ob.get())).get(); } else { - return (boost::any_cast >(ob.get())).get_pointer(); + return &(boost::any_cast >(ob.get())).get(); } } else { if (!ob.get_type_info().is_const()) @@ -103,7 +103,7 @@ namespace chaiscript { if (ob.is_ref()) { - return (boost::any_cast >(ob.get())).get_pointer(); + return &(boost::any_cast >(ob.get())).get(); } else { return (boost::any_cast >(ob.get())).get(); } @@ -116,15 +116,16 @@ namespace chaiscript template struct Cast_Helper_Inner { - typedef typename boost::reference_wrapper Result_Type; + typedef Result& Result_Type; - static Result_Type cast(const Boxed_Value &ob) + static Result &cast(const Boxed_Value &ob) { if (ob.is_ref()) { - return boost::any_cast >(ob.get()); + return boost::any_cast >(ob.get()); } else { - return boost::ref(*(boost::any_cast >(ob.get()))); + Result &r = *(boost::any_cast >(ob.get())); + return r; } } }; @@ -220,35 +221,35 @@ namespace chaiscript /** - * Cast_Helper_Inner for casting to a boost::reference_wrapper type + * Cast_Helper_Inner for casting to a std::reference_wrapper type */ template - struct Cast_Helper_Inner > : Cast_Helper_Inner + struct Cast_Helper_Inner > : Cast_Helper_Inner { }; template - struct Cast_Helper_Inner > : Cast_Helper_Inner + struct Cast_Helper_Inner > : Cast_Helper_Inner { }; template - struct Cast_Helper_Inner &> : Cast_Helper_Inner + struct Cast_Helper_Inner &> : Cast_Helper_Inner { }; template - struct Cast_Helper_Inner > : Cast_Helper_Inner + struct Cast_Helper_Inner > : Cast_Helper_Inner { }; template - struct Cast_Helper_Inner > : Cast_Helper_Inner + struct Cast_Helper_Inner > : Cast_Helper_Inner { }; template - struct Cast_Helper_Inner & > : Cast_Helper_Inner + struct Cast_Helper_Inner & > : Cast_Helper_Inner { }; diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 6d9a8f0..8026fe6 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -103,17 +103,17 @@ namespace chaiscript template static std::shared_ptr get(T *t) { - return get(boost::ref(*t)); + return get(std::ref(*t)); } template - static std::shared_ptr get(boost::reference_wrapper obj) + static std::shared_ptr get(std::reference_wrapper obj) { return std::shared_ptr(new Data( detail::Get_Type_Info::get(), boost::any(obj), true, - obj.get_pointer()) + &obj.get()) ); } @@ -271,7 +271,7 @@ namespace chaiscript std::shared_ptr m_data; }; - /// \brief Creates a Boxed_Value. If the object passed in is a value type, it is copied. If it is a pointer, std::shared_ptr, or boost::reference_type + /// \brief Creates a Boxed_Value. If the object passed in is a value type, it is copied. If it is a pointer, std::shared_ptr, or std::reference_type /// a copy is not made. /// \param t The value to box /// @@ -323,19 +323,19 @@ namespace chaiscript return Boxed_Value( std::const_pointer_cast::type>(t) ); } - /// \brief Takes a boost::reference_wrapper value, adds const to the referenced type and returns an immutable Boxed_Value. + /// \brief Takes a std::reference_wrapper value, adds const to the referenced type and returns an immutable Boxed_Value. /// Does not copy the referenced value. /// \param[in] t Reference object to make immutable /// \returns Immutable Boxed_Value /// \sa Boxed_Value::is_const template - Boxed_Value const_var_impl(const boost::reference_wrapper &t) + Boxed_Value const_var_impl(const std::reference_wrapper &t) { - return Boxed_Value( boost::cref(t.get()) ); + return Boxed_Value( std::cref(t.get()) ); } } - /// \brief Takes an object and returns an immutable Boxed_Value. If the object is a boost::reference or pointer type + /// \brief Takes an object and returns an immutable Boxed_Value. If the object is a std::reference or pointer type /// the value is not copied. If it is an object type, it is copied. /// \param[in] t Object to make immutable /// \returns Immutable Boxed_Value diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index 5d66f29..6b888c3 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -112,11 +112,11 @@ namespace chaiscript { const Derived &d = detail::Cast_Helper::cast(t_derived); const Base &data = dynamic_cast(d); - return Boxed_Value(boost::cref(data)); + return Boxed_Value(std::cref(data)); } else { Derived &d = detail::Cast_Helper::cast(t_derived); Base &data = dynamic_cast(d); - return Boxed_Value(boost::ref(data)); + return Boxed_Value(std::ref(data)); } } } else { diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index c20049f..5c9d9e1 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -6,7 +6,7 @@ #include -#define addparam(z,n,text) params.push_back((boost::is_reference::value&&!(boost::is_same::type>::type>::value))?Boxed_Value(boost::ref(BOOST_PP_CAT(p, n))):Boxed_Value(BOOST_PP_CAT(p, n) )); +#define addparam(z,n,text) params.push_back((boost::is_reference::value&&!(boost::is_same::type>::type>::value))?Boxed_Value(std::ref(BOOST_PP_CAT(p, n))):Boxed_Value(BOOST_PP_CAT(p, n) )); #define curry(z,n,text) BOOST_PP_CAT(std::placeholders::_, BOOST_PP_INC(n)) diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index 70cc02e..828d01e 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -75,7 +75,7 @@ namespace chaiscript { static Boxed_Value handle(const Ret &r) { - return Boxed_Value(boost::cref(r)); + return Boxed_Value(std::cref(r)); } }; @@ -88,12 +88,12 @@ namespace chaiscript { static Boxed_Value handle(Ret &r) { - return Boxed_Value(boost::ref(r)); + return Boxed_Value(std::ref(r)); } static Boxed_Value handle(const Ret &r) { - return Boxed_Value(boost::cref(r)); + return Boxed_Value(std::cref(r)); } }; diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 0c1f8e8..ad88586 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -120,7 +120,7 @@ namespace chaiscript /// MyClass obj; /// chaiscript::ChaiScript chai; /// // Add function taking only one argument, an int, and permanently bound to "obj" - /// chai.add(fun(&MyClass::memberfunction, boost::ref(obj)), "memberfunction"); + /// chai.add(fun(&MyClass::memberfunction, std::ref(obj)), "memberfunction"); /// \endcode /// /// \sa \ref addingfunctions @@ -146,7 +146,7 @@ namespace chaiscript /// chaiscript::ChaiScript chai; /// // Add function taking only no arguments, and permanently bound to "obj" and "1" /// // memberfunction() will be equivalent to obj.memberfunction(1) - /// chai.add(fun(&MyClass::memberfunction, boost::ref(obj), 1), "memberfunction"); + /// chai.add(fun(&MyClass::memberfunction, std::ref(obj), 1), "memberfunction"); /// \endcode /// /// \sa \ref addingfunctions diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index aed318c..2a79765 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -187,7 +187,7 @@ namespace chaiscript }; template - struct Get_Type_Info > + struct Get_Type_Info > { typedef T type; @@ -196,13 +196,13 @@ namespace chaiscript return Type_Info(boost::is_const::value, boost::is_reference::value, boost::is_pointer::value, boost::is_void::value, boost::is_arithmetic::value && !boost::is_same::type, bool>::value, - &typeid(boost::reference_wrapper ), + &typeid(std::reference_wrapper ), &typeid(typename Bare_Type::type)); } }; template - struct Get_Type_Info &> + struct Get_Type_Info &> { typedef T type; @@ -211,7 +211,7 @@ namespace chaiscript return Type_Info(boost::is_const::value, boost::is_reference::value, boost::is_pointer::value, boost::is_void::value, boost::is_arithmetic::value && !boost::is_same::type, bool>::value, - &typeid(const boost::reference_wrapper &), + &typeid(const std::reference_wrapper &), &typeid(typename Bare_Type::type)); } }; diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 1b866d8..4b91239 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -344,13 +344,13 @@ namespace chaiscript add(Bootstrap::bootstrap()); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_system, boost::ref(m_engine)), "dump_system"); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_object, boost::ref(m_engine)), "dump_object"); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::is_type, boost::ref(m_engine)), "is_type"); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::type_name, boost::ref(m_engine)), "type_name"); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, boost::ref(m_engine)), "function_exists"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_system, std::ref(m_engine)), "dump_system"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_object, std::ref(m_engine)), "dump_object"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::is_type, std::ref(m_engine)), "is_type"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::type_name, std::ref(m_engine)), "type_name"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, std::ref(m_engine)), "function_exists"); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type_name, boost::ref(m_engine)), "name"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type_name, std::ref(m_engine)), "name"); typedef void (ChaiScript::*load_mod_1)(const std::string&); diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 55ed373..356299a 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -556,7 +556,7 @@ namespace chaiscript } return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function - (std::bind(chaiscript::eval::detail::eval_function, boost::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), + (std::bind(chaiscript::eval::detail::eval_function, std::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back()))); } @@ -624,7 +624,7 @@ namespace chaiscript if (guardnode) { guard = std::shared_ptr (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - boost::ref(t_ss), guardnode, + std::ref(t_ss), guardnode, t_param_names, std::placeholders::_1), static_cast(numparams), guardnode)); } @@ -633,7 +633,7 @@ namespace chaiscript const std::string & l_annotation = this->annotation?this->annotation->text:""; t_ss.add(Proxy_Function (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - boost::ref(t_ss), this->children.back(), + std::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), l_annotation, guard)), l_function_name); } @@ -942,7 +942,7 @@ namespace chaiscript throw; } catch (const std::exception &e) { - Boxed_Value except = Boxed_Value(boost::ref(e)); + Boxed_Value except = Boxed_Value(std::ref(e)); size_t end_point = this->children.size(); if (this->children.back()->identifier == AST_Node_Type::Finally) { @@ -1099,7 +1099,7 @@ namespace chaiscript if (guardnode) { guard = std::shared_ptr (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - boost::ref(t_ss), guardnode, + std::ref(t_ss), guardnode, t_param_names, std::placeholders::_1), static_cast(numparams), guardnode)); } @@ -1111,7 +1111,7 @@ namespace chaiscript t_ss.add(Proxy_Function (new dispatch::detail::Dynamic_Object_Constructor(class_name, Proxy_Function (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - boost::ref(t_ss), this->children.back(), + std::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), l_annotation, guard)))), function_name); @@ -1126,7 +1126,7 @@ namespace chaiscript t_ss.add(Proxy_Function (new dispatch::detail::Dynamic_Object_Function(class_name, Proxy_Function (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - boost::ref(t_ss), this->children.back(), + std::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), l_annotation, guard)), ti)), function_name); diff --git a/samples/example.cpp b/samples/example.cpp index 33d0234..5a706f0 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -109,7 +109,7 @@ int main(int /*argc*/, char * /*argv*/[]) { //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"); + chai.add(fun(&System::do_callbacks, std::ref(system), std::string("Bound Test")), "do_callbacks"); //Call bound version of do_callbacks chai("do_callbacks()"); diff --git a/src/multithreaded.cpp b/src/multithreaded.cpp index c1eddd4..e0d7767 100644 --- a/src/multithreaded.cpp +++ b/src/multithreaded.cpp @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < argc - 1; ++i) { - threads.push_back(std::shared_ptr(new boost::thread(std::bind(do_work, boost::ref(chai))))); + threads.push_back(std::shared_ptr(new boost::thread(std::bind(do_work, std::ref(chai))))); } for (int i = 0; i < argc - 1; ++i) diff --git a/unittests/boxed_cast_test.cpp b/unittests/boxed_cast_test.cpp index 5d5a5db..c183731 100644 --- a/unittests/boxed_cast_test.cpp +++ b/unittests/boxed_cast_test.cpp @@ -78,14 +78,14 @@ bool do_test(const Boxed_Value &bv, bool T, bool ConstT, bool TRef, bool ConstTR passed &= test_type_conversion >(bv, ConstSharedConstPtrT); passed &= test_type_conversion &>(bv, ConstSharedPtrTRef); passed &= test_type_conversion &>(bv, ConstSharedPtrTConstRef); - passed &= test_type_conversion >(bv, BoostRef); - passed &= test_type_conversion >(bv, BoostConstRef); - passed &= test_type_conversion &>(bv, false); - passed &= test_type_conversion &>(bv, false); - passed &= test_type_conversion >(bv, ConstBoostRef); - passed &= test_type_conversion >(bv, ConstBoostConstRef); - passed &= test_type_conversion &>(bv, ConstBoostRefRef); - passed &= test_type_conversion &>(bv, ConstBoostConstRefRef); + passed &= test_type_conversion >(bv, BoostRef); + passed &= test_type_conversion >(bv, BoostConstRef); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion >(bv, ConstBoostRef); + passed &= test_type_conversion >(bv, ConstBoostConstRef); + passed &= test_type_conversion &>(bv, ConstBoostRefRef); + passed &= test_type_conversion &>(bv, ConstBoostConstRefRef); passed &= test_type_conversion(bv, Number); passed &= test_type_conversion(bv, ConstNumber); passed &= test_type_conversion(bv, false); @@ -137,13 +137,13 @@ bool built_in_type_test(const T &initial, bool ispod) true, false, true, false, true, ispod && true, ispod && true, ispod && true, ispod && false, true); - passed &= do_test(var(boost::ref(i)), true, true, true, true, true, + passed &= do_test(var(std::ref(i)), true, true, true, true, true, true, true, true, false, false, false, false, false, false, true, true, true, true, true, true, ispod && true, ispod && true, ispod && true, true, true); - passed &= do_test(var(boost::cref(i)), true, true, false, true, false, + passed &= do_test(var(std::cref(i)), true, true, false, true, false, true, false, true, false, false, false, false, false, false, false, true, false, true, false, true, @@ -167,7 +167,7 @@ bool built_in_type_test(const T &initial, bool ispod) true, false, true, false, true, ispod && true, ispod && true, ispod && true, false, true); - passed &= do_test(var(boost::ref(ir)), true, true, false, true, false, + passed &= do_test(var(std::ref(ir)), true, true, false, true, false, true, false, true, false, false, false, false, false, false, false, true, false, true, false, true, @@ -180,7 +180,7 @@ bool built_in_type_test(const T &initial, bool ispod) true, false, true, false, true, ispod && true, ispod && true, ispod && true, false, true); - passed &= do_test(const_var(boost::ref(ir)), true, true, false, true, false, + passed &= do_test(const_var(std::ref(ir)), true, true, false, true, false, true, false, true, false, false, false, false, false, false, false, true, false, true, false, true,