From 2ff6a4966a22b34eec59db656c2895d2a50be9cd Mon Sep 17 00:00:00 2001 From: gallaert Date: Mon, 20 Apr 2020 19:47:28 +0100 Subject: [PATCH] Replace boost::bind by std::bind and lambda function --- simgear/canvas/elements/CanvasElement.hxx | 43 ++++++--------- simgear/io/HTTPRequest.hxx | 8 ++- simgear/nasal/cppbind/Ghost.hxx | 66 +++++++++++------------ simgear/package/Catalog.hxx | 4 +- simgear/package/Install.hxx | 14 ++--- simgear/props/AtomicChangeListener.cxx | 2 - simgear/props/AtomicChangeListener.hxx | 2 - simgear/props/ExtendedPropertyAdapter.hxx | 6 +-- simgear/props/props.cxx | 1 - simgear/scene/material/Effect.cxx | 17 +++--- simgear/scene/material/EffectBuilder.hxx | 10 ++-- simgear/scene/model/SGReaderWriterXML.cxx | 10 ++-- simgear/structure/SGExpression.cxx | 27 +++++----- 13 files changed, 94 insertions(+), 116 deletions(-) diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx index c993b5d0..31fe8ccc 100644 --- a/simgear/canvas/elements/CanvasElement.hxx +++ b/simgear/canvas/elements/CanvasElement.hxx @@ -29,7 +29,6 @@ #include #include -#include #include namespace osg @@ -345,13 +344,10 @@ namespace canvas if( style->func ) style = style->next = new StyleSetter; - style->func = boost::bind - ( - &type_match::call, - _1, - _2, - bindStyleSetter(name, setter) - ); + style->func = std::bind(&type_match::call, + std::placeholders::_1, + std::placeholders::_2, + bindStyleSetter(name, setter)); return *style; } @@ -528,7 +524,9 @@ namespace canvas boost::function bindOther( void (Other::*setter)(T), OtherRef Derived::*instance_ref ) { - return boost::bind(setter, boost::bind(instance_ref, _1), _2); + return std::bind(setter, + std::bind(instance_ref, std::placeholders::_1), + std::placeholders::_2); } template @@ -537,16 +535,10 @@ namespace canvas bindOther( const boost::function& setter, OtherRef Derived::*instance_ref ) { - return boost::bind - ( - setter, - boost::bind - ( - &reference_from_pointer, - boost::bind(instance_ref, _1) - ), - _2 - ); + return std::bind(setter, + std::bind(&reference_from_pointer, + std::bind(instance_ref, std::placeholders::_1)), + std::placeholders::_2); } template @@ -555,14 +547,11 @@ namespace canvas bindStyleSetter( const std::string& name, const boost::function& setter ) { - return boost::bind - ( - setter, - // We will only call setters with Derived instances, so we can safely - // cast here. - boost::bind(&derived_cast, _1), - boost::bind(&getValue, _2) - ); + return std::bind(setter, + // We will only call setters with Derived instances, so we can safely + // cast here. + std::bind(&derived_cast, std::placeholders::_1), + std::bind(&getValue, std::placeholders::_2)); } bool isStyleEmpty(const SGPropertyNode* child) const; diff --git a/simgear/io/HTTPRequest.hxx b/simgear/io/HTTPRequest.hxx index 9ba8db3e..ef55e832 100644 --- a/simgear/io/HTTPRequest.hxx +++ b/simgear/io/HTTPRequest.hxx @@ -28,8 +28,6 @@ #include #include -#include - class SGPropertyNode; namespace simgear @@ -82,7 +80,7 @@ public: template Request* done(C* instance, void (C::*mem_func)(Request*)) { - return done(boost::bind(mem_func, instance, _1)); + return done(std::bind(mem_func, instance, std::placeholders::_1)); } /** @@ -97,7 +95,7 @@ public: template Request* fail(C* instance, void (C::*mem_func)(Request*)) { - return fail(boost::bind(mem_func, instance, _1)); + return fail(std::bind(mem_func, instance, std::placeholders::_1)); } /** @@ -112,7 +110,7 @@ public: template Request* always(C* instance, void (C::*mem_func)(Request*)) { - return always(boost::bind(mem_func, instance, _1)); + return always(std::bind(mem_func, instance, std::placeholders::_1)); } /** diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index 3d6c6bd1..235d6453 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -217,7 +216,7 @@ namespace nasal * .member("x_writeonly", &MyClass::setX) * // Methods can be nearly anything callable and accepting a reference * // to an instance of the class type. (member functions, free functions - * // and anything else bindable using boost::function and boost::bind) + * // and anything else bindable using boost::function and std::bind) * .method("myMember", &MyClass::myMember) * .method("doSomething", &MyClass::doSomethingElse) * .method("other", &myOtherFreeMember); @@ -596,9 +595,12 @@ namespace nasal const std::string&, Param& )>& getter ) { - return _get(boost::bind( - convert_param_invoker, getter, _1, _2, _3, _4 - )); + return _get(std::bind(convert_param_invoker, + getter, + std::placeholders::_1, + std::placeholders::_2, + std::placeholders::_3, + std::placeholders::_4)); } /** @@ -672,12 +674,12 @@ namespace nasal // naContext, // const std::string&, // naRef ) - return _set(boost::bind( - setter, - _1, - _3, - boost::bind(from_nasal_ptr::get(), _2, _4) - )); + return _set(std::bind(setter, + std::placeholders::_1, + std::placeholders::_3, + std::bind(from_nasal_ptr::get(), + std::placeholders::_2, + std::placeholders::_4))); } /** @@ -769,7 +771,10 @@ namespace nasal const boost::function& func ) { - return method(name, boost::bind(method_invoker, func, _1, _2)); + return method(name, std::bind(method_invoker, + func, + std::placeholders::_1, + std::placeholders::_2)); } /** @@ -783,16 +788,13 @@ namespace nasal const method_variadic_t& func, std::index_sequence ) { - return method - ( - name, - typename boost::function - ( boost::bind( - func, - _1, - boost::bind(&Ghost::arg_from_nasal, _2, Indices)... - )) - ); + return method(name, + typename boost::function + (std::bind(func, + std::placeholders::_1, + std::bind(&Ghost::arg_from_nasal, + std::placeholders::_2, + Indices)...))); } template @@ -1124,24 +1126,20 @@ namespace nasal naRef(*to_nasal_)(naContext, param_type) = &to_nasal; // Getter signature: naRef(raw_type&, naContext) - return boost::bind - ( - to_nasal_, - _2, - boost::bind(getter, _1) - ); + return std::bind(to_nasal_, + std::placeholders::_2, + std::bind(getter, std::placeholders::_1)); } template setter_t to_setter(void (raw_type::*setter)(Param)) { // Setter signature: void(raw_type&, naContext, naRef) - return boost::bind - ( - setter, - _1, - boost::bind(from_nasal_ptr::get(), _2, _3) - ); + return std::bind(setter, + std::placeholders::_1, + std::bind(from_nasal_ptr::get(), + std::placeholders::_2, + std::placeholders::_3)); } /** diff --git a/simgear/package/Catalog.hxx b/simgear/package/Catalog.hxx index 3bfe4065..0b885dfc 100644 --- a/simgear/package/Catalog.hxx +++ b/simgear/package/Catalog.hxx @@ -22,8 +22,6 @@ #include #include -#include - #include #include @@ -148,7 +146,7 @@ public: template void addStatusCallback(C* instance, void (C::*mem_func)(Catalog*)) { - return addStatusCallback(boost::bind(mem_func, instance, _1)); + return addStatusCallback(std::bind(mem_func, instance, std::placeholders::_1)); } bool isUserEnabled() const; diff --git a/simgear/package/Install.hxx b/simgear/package/Install.hxx index 268564eb..1a4124b4 100644 --- a/simgear/package/Install.hxx +++ b/simgear/package/Install.hxx @@ -29,8 +29,6 @@ #include #include -#include - namespace simgear { @@ -112,7 +110,7 @@ public: template Install* done(C* instance, void (C::*mem_func)(Install*)) { - return done(boost::bind(mem_func, instance, _1)); + return done(std::bind(mem_func, instance, std::placeholders::_1)); } /** @@ -126,7 +124,7 @@ public: template Install* fail(C* instance, void (C::*mem_func)(Install*)) { - return fail(boost::bind(mem_func, instance, _1)); + return fail(std::bind(mem_func, instance, std::placeholders::_1)); } /** @@ -141,7 +139,7 @@ public: template Install* always(C* instance, void (C::*mem_func)(Install*)) { - return always(boost::bind(mem_func, instance, _1)); + return always(std::bind(mem_func, instance, std::placeholders::_1)); } /** @@ -155,7 +153,11 @@ public: Install* progress(C* instance, void (C::*mem_func)(Install*, unsigned int, unsigned int)) { - return progress(boost::bind(mem_func, instance, _1, _2, _3)); + return progress(std::bind(mem_func, + instance, + std::placeholders::_1, + std::placeholders::_2, + std::placeholders::_3)); } private: diff --git a/simgear/props/AtomicChangeListener.cxx b/simgear/props/AtomicChangeListener.cxx index 5b324885..4409e135 100644 --- a/simgear/props/AtomicChangeListener.cxx +++ b/simgear/props/AtomicChangeListener.cxx @@ -9,8 +9,6 @@ #include #include -#include - #include namespace simgear diff --git a/simgear/props/AtomicChangeListener.hxx b/simgear/props/AtomicChangeListener.hxx index 43208ad5..1c2a9750 100644 --- a/simgear/props/AtomicChangeListener.hxx +++ b/simgear/props/AtomicChangeListener.hxx @@ -5,8 +5,6 @@ #include #include -#include - #include #include "props.hxx" diff --git a/simgear/props/ExtendedPropertyAdapter.hxx b/simgear/props/ExtendedPropertyAdapter.hxx index cbe50760..7c0785ea 100644 --- a/simgear/props/ExtendedPropertyAdapter.hxx +++ b/simgear/props/ExtendedPropertyAdapter.hxx @@ -2,8 +2,7 @@ #define SIMGEAR_EXTENDEDPROPERTYADAPTER_HXX 1 #include - -#include +#include #include #include @@ -65,7 +64,8 @@ inline void makeChildList(SGPropertyNode* prop, InIterator inBegin, InIterator inEnd, OutIterator outBegin) { std::transform(inBegin, inEnd, outBegin, - boost::bind(static_cast(&SGPropertyNode::getChild), prop, _1, 0, true)); + std::bind(static_cast(&SGPropertyNode::getChild), + prop, std::placeholders::_1, 0, true)); } } diff --git a/simgear/props/props.cxx b/simgear/props/props.cxx index c6a84df0..e5777aa8 100644 --- a/simgear/props/props.cxx +++ b/simgear/props/props.cxx @@ -29,7 +29,6 @@ using std::cerr; # include # include # include -# include # include # include # include diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index d10d6b83..3e0cfc58 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -35,7 +35,6 @@ #include #include -#include #include #include #include @@ -880,7 +879,6 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass, const SGReaderWriterOptions* options) { - using namespace boost; if (!isAttributeActive(effect, prop)) return; PropertyList pVertShaders = prop->getChildren("vertex-shader"); @@ -889,12 +887,15 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass, PropertyList pAttributes = prop->getChildren("attribute"); ProgramKey prgKey; std::back_insert_iterator > inserter(prgKey.shaders); - transform(pVertShaders.begin(), pVertShaders.end(), inserter, - boost::bind(makeShaderKey, _1, Shader::VERTEX)); - transform(pGeomShaders.begin(), pGeomShaders.end(), inserter, - boost::bind(makeShaderKey, _1, Shader::GEOMETRY)); - transform(pFragShaders.begin(), pFragShaders.end(), inserter, - boost::bind(makeShaderKey, _1, Shader::FRAGMENT)); + std::transform(pVertShaders.begin(), pVertShaders.end(), inserter, + [] (SGPropertyNode_ptr& ptr) { + return makeShaderKey(ptr, Shader::VERTEX); }); + std::transform(pGeomShaders.begin(), pGeomShaders.end(), inserter, + [] (SGPropertyNode_ptr& ptr) { + return makeShaderKey(ptr, Shader::GEOMETRY); }); + std::transform(pFragShaders.begin(), pFragShaders.end(), inserter, + [] (SGPropertyNode_ptr& ptr) { + return makeShaderKey(ptr, Shader::FRAGMENT); }); for (PropertyList::iterator itr = pAttributes.begin(), e = pAttributes.end(); itr != e; diff --git a/simgear/scene/material/EffectBuilder.hxx b/simgear/scene/material/EffectBuilder.hxx index c3aec49c..88703569 100644 --- a/simgear/scene/material/EffectBuilder.hxx +++ b/simgear/scene/material/EffectBuilder.hxx @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -633,8 +632,9 @@ initFromParameters(Effect* effect, const SGPropertyNode* prop, ObjType* obj, SetterReturn (ObjType::*setter)(const OSGParamType), const SGReaderWriterOptions* options) { - initFromParameters(effect, prop, obj, - boost::bind(setter, _1, _2), options); + initFromParameters(effect, prop, obj, + std::bind(setter, std::placeholders::_1, std::placeholders::_2), + options); } /* @@ -694,8 +694,8 @@ initFromParameters(Effect* effect, const SGPropertyNode* prop, ObjType* obj, NameItrType nameItr, const SGReaderWriterOptions* options) { initFromParameters(effect, prop, obj, - boost::bind(setter, _1, _2), nameItr, - options); + std::bind(setter, std::placeholders::_1, std::placeholders::_2), + nameItr, options); } extern const char* colorFields[]; } diff --git a/simgear/scene/model/SGReaderWriterXML.cxx b/simgear/scene/model/SGReaderWriterXML.cxx index 7084c3a3..91f5bd11 100644 --- a/simgear/scene/model/SGReaderWriterXML.cxx +++ b/simgear/scene/model/SGReaderWriterXML.cxx @@ -25,8 +25,6 @@ #include #include -#include - #include #include #include @@ -197,10 +195,10 @@ void makeEffectAnimations(PropertyList& animation_nodes, } } - animation_nodes.erase(remove_if(animation_nodes.begin(), - animation_nodes.end(), - !boost::bind(&SGPropertyNode_ptr::valid, - _1)), + animation_nodes.erase(std::remove_if(animation_nodes.begin(), + animation_nodes.end(), + [] (const SGPropertyNode_ptr& ptr) { + return !ptr.valid(); }), animation_nodes.end()); } } diff --git a/simgear/structure/SGExpression.cxx b/simgear/structure/SGExpression.cxx index 1a581a90..ba2862ee 100644 --- a/simgear/structure/SGExpression.cxx +++ b/simgear/structure/SGExpression.cxx @@ -31,7 +31,6 @@ #include #include #include -#include #include // for strcmp #include @@ -854,12 +853,12 @@ ExpParserRegistrar leRegistrar("less-equal", predParser); template Expression* logicopParser(const SGPropertyNode* exp, Parser* parser) { - using namespace boost; - vector children; + std::vector children; parser->readChildren(exp, children); - vector::iterator notBool = - find_if(children.begin(), children.end(), - boost::bind(&Expression::getType, _1) != BOOL); + std::vector::const_iterator notBool = + std::find_if(children.begin(), children.end(), + [] (const Expression* const e) { + return e->getType () != BOOL; }); if (notBool != children.end()) throw("non boolean operand to logical expression"); Logicop *expr = new Logicop; @@ -873,9 +872,10 @@ ExpParserRegistrar orRegistrar("or", logicopParser); size_t BindingLayout::addBinding(const string& name, Type type) { //XXX error checkint - vector::iterator itr - = find_if(bindings.begin(), bindings.end(), - boost::bind(&VariableBinding::name, _1) == name); + std::vector::const_iterator itr = + std::find_if(bindings.begin(), bindings.end(), + [&name] (const VariableBinding& v) { + return v.name == name; }); if (itr != bindings.end()) return itr->location; size_t result = bindings.size(); @@ -886,11 +886,10 @@ size_t BindingLayout::addBinding(const string& name, Type type) bool BindingLayout::findBinding(const std::string& name, VariableBinding& result) const { - using namespace std; - using namespace boost; - vector::const_iterator itr - = find_if(bindings.begin(), bindings.end(), - boost::bind(&VariableBinding::name, _1) == name); + std::vector::const_iterator itr = + std::find_if(bindings.begin(), bindings.end(), + [&name] (const VariableBinding& v) { + return v.name == name; }); if (itr != bindings.end()) { result = *itr; return true;