Replace boost::bind by std::bind and lambda function

This commit is contained in:
gallaert
2020-04-22 14:04:21 +01:00
committed by James Turner
parent b13d7f9392
commit 2ff6a4966a
13 changed files with 94 additions and 116 deletions
+16 -27
View File
@@ -29,7 +29,6 @@
#include <osg/BoundingBox> #include <osg/BoundingBox>
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
#include <boost/bind.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
namespace osg namespace osg
@@ -345,13 +344,10 @@ namespace canvas
if( style->func ) if( style->func )
style = style->next = new StyleSetter; style = style->next = new StyleSetter;
style->func = boost::bind style->func = std::bind(&type_match<Derived>::call,
( std::placeholders::_1,
&type_match<Derived>::call, std::placeholders::_2,
_1, bindStyleSetter<T1>(name, setter));
_2,
bindStyleSetter<T1>(name, setter)
);
return *style; return *style;
} }
@@ -528,7 +524,9 @@ namespace canvas
boost::function<void (Derived&, T)> boost::function<void (Derived&, T)>
bindOther( void (Other::*setter)(T), OtherRef Derived::*instance_ref ) 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<typename T, class Derived, class Other, class OtherRef> template<typename T, class Derived, class Other, class OtherRef>
@@ -537,16 +535,10 @@ namespace canvas
bindOther( const boost::function<void (Other&, T)>& setter, bindOther( const boost::function<void (Other&, T)>& setter,
OtherRef Derived::*instance_ref ) OtherRef Derived::*instance_ref )
{ {
return boost::bind return std::bind(setter,
( std::bind(&reference_from_pointer<Other, OtherRef>,
setter, std::bind(instance_ref, std::placeholders::_1)),
boost::bind std::placeholders::_2);
(
&reference_from_pointer<Other, OtherRef>,
boost::bind(instance_ref, _1)
),
_2
);
} }
template<typename T1, typename T2, class Derived> template<typename T1, typename T2, class Derived>
@@ -555,14 +547,11 @@ namespace canvas
bindStyleSetter( const std::string& name, bindStyleSetter( const std::string& name,
const boost::function<void (Derived&, T2)>& setter ) const boost::function<void (Derived&, T2)>& setter )
{ {
return boost::bind return std::bind(setter,
( // We will only call setters with Derived instances, so we can safely
setter, // cast here.
// We will only call setters with Derived instances, so we can safely std::bind(&derived_cast<Derived>, std::placeholders::_1),
// cast here. std::bind(&getValue<T1>, std::placeholders::_2));
boost::bind(&derived_cast<Derived>, _1),
boost::bind(&getValue<T1>, _2)
);
} }
bool isStyleEmpty(const SGPropertyNode* child) const; bool isStyleEmpty(const SGPropertyNode* child) const;
+3 -5
View File
@@ -28,8 +28,6 @@
#include <simgear/structure/SGSharedPtr.hxx> #include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/math/sg_types.hxx> #include <simgear/math/sg_types.hxx>
#include <boost/bind.hpp>
class SGPropertyNode; class SGPropertyNode;
namespace simgear namespace simgear
@@ -82,7 +80,7 @@ public:
template<class C> template<class C>
Request* done(C* instance, void (C::*mem_func)(Request*)) 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<class C> template<class C>
Request* fail(C* instance, void (C::*mem_func)(Request*)) 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<class C> template<class C>
Request* always(C* instance, void (C::*mem_func)(Request*)) 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));
} }
/** /**
+32 -34
View File
@@ -29,7 +29,6 @@
#include <simgear/structure/SGWeakReferenced.hxx> #include <simgear/structure/SGWeakReferenced.hxx>
#include <simgear/structure/SGWeakPtr.hxx> #include <simgear/structure/SGWeakPtr.hxx>
#include <boost/bind.hpp>
#include <boost/call_traits.hpp> #include <boost/call_traits.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/mpl/has_xxx.hpp> #include <boost/mpl/has_xxx.hpp>
@@ -217,7 +216,7 @@ namespace nasal
* .member("x_writeonly", &MyClass::setX) * .member("x_writeonly", &MyClass::setX)
* // Methods can be nearly anything callable and accepting a reference * // Methods can be nearly anything callable and accepting a reference
* // to an instance of the class type. (member functions, free functions * // 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("myMember", &MyClass::myMember)
* .method("doSomething", &MyClass::doSomethingElse) * .method("doSomething", &MyClass::doSomethingElse)
* .method("other", &myOtherFreeMember); * .method("other", &myOtherFreeMember);
@@ -596,9 +595,12 @@ namespace nasal
const std::string&, const std::string&,
Param& )>& getter ) Param& )>& getter )
{ {
return _get(boost::bind( return _get(std::bind(convert_param_invoker<Param>,
convert_param_invoker<Param>, getter, _1, _2, _3, _4 getter,
)); std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_3,
std::placeholders::_4));
} }
/** /**
@@ -672,12 +674,12 @@ namespace nasal
// naContext, // naContext,
// const std::string&, // const std::string&,
// naRef ) // naRef )
return _set(boost::bind( return _set(std::bind(setter,
setter, std::placeholders::_1,
_1, std::placeholders::_3,
_3, std::bind(from_nasal_ptr<Param>::get(),
boost::bind(from_nasal_ptr<Param>::get(), _2, _4) std::placeholders::_2,
)); std::placeholders::_4)));
} }
/** /**
@@ -769,7 +771,10 @@ namespace nasal
const boost::function<Ret (raw_type&, const CallContext&)>& func const boost::function<Ret (raw_type&, const CallContext&)>& func
) )
{ {
return method(name, boost::bind(method_invoker<Ret>, func, _1, _2)); return method(name, std::bind(method_invoker<Ret>,
func,
std::placeholders::_1,
std::placeholders::_2));
} }
/** /**
@@ -783,16 +788,13 @@ namespace nasal
const method_variadic_t<Ret, Args...>& func, const method_variadic_t<Ret, Args...>& func,
std::index_sequence<Indices...> ) std::index_sequence<Indices...> )
{ {
return method<Ret> return method<Ret>(name,
( typename boost::function<Ret (raw_type&, const CallContext&)>
name, (std::bind(func,
typename boost::function<Ret (raw_type&, const CallContext&)> std::placeholders::_1,
( boost::bind( std::bind(&Ghost::arg_from_nasal<Args>,
func, std::placeholders::_2,
_1, Indices)...)));
boost::bind(&Ghost::arg_from_nasal<Args>, _2, Indices)...
))
);
} }
template<class Ret, class... Args> template<class Ret, class... Args>
@@ -1124,24 +1126,20 @@ namespace nasal
naRef(*to_nasal_)(naContext, param_type) = &to_nasal; naRef(*to_nasal_)(naContext, param_type) = &to_nasal;
// Getter signature: naRef(raw_type&, naContext) // Getter signature: naRef(raw_type&, naContext)
return boost::bind return std::bind(to_nasal_,
( std::placeholders::_2,
to_nasal_, std::bind(getter, std::placeholders::_1));
_2,
boost::bind(getter, _1)
);
} }
template<class Param> template<class Param>
setter_t to_setter(void (raw_type::*setter)(Param)) setter_t to_setter(void (raw_type::*setter)(Param))
{ {
// Setter signature: void(raw_type&, naContext, naRef) // Setter signature: void(raw_type&, naContext, naRef)
return boost::bind return std::bind(setter,
( std::placeholders::_1,
setter, std::bind(from_nasal_ptr<Param>::get(),
_1, std::placeholders::_2,
boost::bind(from_nasal_ptr<Param>::get(), _2, _3) std::placeholders::_3));
);
} }
/** /**
+1 -3
View File
@@ -22,8 +22,6 @@
#include <ctime> #include <ctime>
#include <map> #include <map>
#include <boost/bind.hpp>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
@@ -148,7 +146,7 @@ public:
template<class C> template<class C>
void addStatusCallback(C* instance, void (C::*mem_func)(Catalog*)) 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; bool isUserEnabled() const;
+8 -6
View File
@@ -29,8 +29,6 @@
#include <simgear/structure/SGSharedPtr.hxx> #include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/io/HTTPRequest.hxx> #include <simgear/io/HTTPRequest.hxx>
#include <boost/bind.hpp>
namespace simgear namespace simgear
{ {
@@ -112,7 +110,7 @@ public:
template<class C> template<class C>
Install* done(C* instance, void (C::*mem_func)(Install*)) 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<class C> template<class C>
Install* fail(C* instance, void (C::*mem_func)(Install*)) 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<class C> template<class C>
Install* always(C* instance, void (C::*mem_func)(Install*)) 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, Install* progress(C* instance,
void (C::*mem_func)(Install*, unsigned int, unsigned int)) 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: private:
-2
View File
@@ -9,8 +9,6 @@
#include <iterator> #include <iterator>
#include <vector> #include <vector>
#include <boost/bind.hpp>
#include <simgear/structure/Singleton.hxx> #include <simgear/structure/Singleton.hxx>
namespace simgear namespace simgear
-2
View File
@@ -5,8 +5,6 @@
#include <iterator> #include <iterator>
#include <vector> #include <vector>
#include <boost/bind.hpp>
#include <simgear/structure/Singleton.hxx> #include <simgear/structure/Singleton.hxx>
#include "props.hxx" #include "props.hxx"
+3 -3
View File
@@ -2,8 +2,7 @@
#define SIMGEAR_EXTENDEDPROPERTYADAPTER_HXX 1 #define SIMGEAR_EXTENDEDPROPERTYADAPTER_HXX 1
#include <algorithm> #include <algorithm>
#include <functional>
#include <boost/bind.hpp>
#include <simgear/math/SGMath.hxx> #include <simgear/math/SGMath.hxx>
#include <simgear/structure/exception.hxx> #include <simgear/structure/exception.hxx>
@@ -65,7 +64,8 @@ inline void makeChildList(SGPropertyNode* prop, InIterator inBegin,
InIterator inEnd, OutIterator outBegin) InIterator inEnd, OutIterator outBegin)
{ {
std::transform(inBegin, inEnd, outBegin, std::transform(inBegin, inEnd, outBegin,
boost::bind(static_cast<SGPropertyNode* (SGPropertyNode::*)(const char*, int, bool)>(&SGPropertyNode::getChild), prop, _1, 0, true)); std::bind(static_cast<SGPropertyNode* (SGPropertyNode::*)(const char*, int, bool)>(&SGPropertyNode::getChild),
prop, std::placeholders::_1, 0, true));
} }
} }
-1
View File
@@ -29,7 +29,6 @@ using std::cerr;
# include <boost/algorithm/string/find_iterator.hpp> # include <boost/algorithm/string/find_iterator.hpp>
# include <boost/algorithm/string/predicate.hpp> # include <boost/algorithm/string/predicate.hpp>
# include <boost/algorithm/string/classification.hpp> # include <boost/algorithm/string/classification.hpp>
# include <boost/bind.hpp>
# include <boost/functional/hash.hpp> # include <boost/functional/hash.hpp>
# include <boost/range.hpp> # include <boost/range.hpp>
# include <simgear/compiler.h> # include <simgear/compiler.h>
+9 -8
View File
@@ -35,7 +35,6 @@
#include <unordered_map> #include <unordered_map>
#include <mutex> #include <mutex>
#include <boost/bind.hpp>
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp> #include <boost/tuple/tuple_comparison.hpp>
@@ -880,7 +879,6 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass,
const SGReaderWriterOptions* const SGReaderWriterOptions*
options) options)
{ {
using namespace boost;
if (!isAttributeActive(effect, prop)) if (!isAttributeActive(effect, prop))
return; return;
PropertyList pVertShaders = prop->getChildren("vertex-shader"); PropertyList pVertShaders = prop->getChildren("vertex-shader");
@@ -889,12 +887,15 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass,
PropertyList pAttributes = prop->getChildren("attribute"); PropertyList pAttributes = prop->getChildren("attribute");
ProgramKey prgKey; ProgramKey prgKey;
std::back_insert_iterator<vector<ShaderKey> > inserter(prgKey.shaders); std::back_insert_iterator<vector<ShaderKey> > inserter(prgKey.shaders);
transform(pVertShaders.begin(), pVertShaders.end(), inserter, std::transform(pVertShaders.begin(), pVertShaders.end(), inserter,
boost::bind(makeShaderKey, _1, Shader::VERTEX)); [] (SGPropertyNode_ptr& ptr) {
transform(pGeomShaders.begin(), pGeomShaders.end(), inserter, return makeShaderKey(ptr, Shader::VERTEX); });
boost::bind(makeShaderKey, _1, Shader::GEOMETRY)); std::transform(pGeomShaders.begin(), pGeomShaders.end(), inserter,
transform(pFragShaders.begin(), pFragShaders.end(), inserter, [] (SGPropertyNode_ptr& ptr) {
boost::bind(makeShaderKey, _1, Shader::FRAGMENT)); 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(), for (PropertyList::iterator itr = pAttributes.begin(),
e = pAttributes.end(); e = pAttributes.end();
itr != e; itr != e;
+5 -5
View File
@@ -29,7 +29,6 @@
#include <osg/Object> #include <osg/Object>
#include <osgDB/Registry> #include <osgDB/Registry>
#include <boost/bind.hpp>
#include <boost/multi_index_container.hpp> #include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp> #include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/ordered_index.hpp>
@@ -633,8 +632,9 @@ initFromParameters(Effect* effect, const SGPropertyNode* prop, ObjType* obj,
SetterReturn (ObjType::*setter)(const OSGParamType), SetterReturn (ObjType::*setter)(const OSGParamType),
const SGReaderWriterOptions* options) const SGReaderWriterOptions* options)
{ {
initFromParameters<OSGParamType>(effect, prop, obj, initFromParameters<OSGParamType>(effect, prop, obj,
boost::bind(setter, _1, _2), options); 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) NameItrType nameItr, const SGReaderWriterOptions* options)
{ {
initFromParameters<OSGParamType>(effect, prop, obj, initFromParameters<OSGParamType>(effect, prop, obj,
boost::bind(setter, _1, _2), nameItr, std::bind(setter, std::placeholders::_1, std::placeholders::_2),
options); nameItr, options);
} }
extern const char* colorFields[]; extern const char* colorFields[];
} }
+4 -6
View File
@@ -25,8 +25,6 @@
#include <cstring> #include <cstring>
#include <cassert> #include <cassert>
#include <boost/bind.hpp>
#include <osg/Version> #include <osg/Version>
#include <osg/Geode> #include <osg/Geode>
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
@@ -197,10 +195,10 @@ void makeEffectAnimations(PropertyList& animation_nodes,
} }
} }
animation_nodes.erase(remove_if(animation_nodes.begin(), animation_nodes.erase(std::remove_if(animation_nodes.begin(),
animation_nodes.end(), animation_nodes.end(),
!boost::bind(&SGPropertyNode_ptr::valid, [] (const SGPropertyNode_ptr& ptr) {
_1)), return !ptr.valid(); }),
animation_nodes.end()); animation_nodes.end());
} }
} }
+13 -14
View File
@@ -31,7 +31,6 @@
#include <utility> #include <utility>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <boost/bind.hpp>
#include <cstring> // for strcmp #include <cstring> // for strcmp
#include <cassert> #include <cassert>
@@ -854,12 +853,12 @@ ExpParserRegistrar leRegistrar("less-equal", predParser<LessEqualExpression>);
template<typename Logicop> template<typename Logicop>
Expression* logicopParser(const SGPropertyNode* exp, Parser* parser) Expression* logicopParser(const SGPropertyNode* exp, Parser* parser)
{ {
using namespace boost; std::vector<Expression*> children;
vector<Expression*> children;
parser->readChildren(exp, children); parser->readChildren(exp, children);
vector<Expression*>::iterator notBool = std::vector<Expression*>::const_iterator notBool =
find_if(children.begin(), children.end(), std::find_if(children.begin(), children.end(),
boost::bind(&Expression::getType, _1) != BOOL); [] (const Expression* const e) {
return e->getType () != BOOL; });
if (notBool != children.end()) if (notBool != children.end())
throw("non boolean operand to logical expression"); throw("non boolean operand to logical expression");
Logicop *expr = new Logicop; Logicop *expr = new Logicop;
@@ -873,9 +872,10 @@ ExpParserRegistrar orRegistrar("or", logicopParser<OrExpression>);
size_t BindingLayout::addBinding(const string& name, Type type) size_t BindingLayout::addBinding(const string& name, Type type)
{ {
//XXX error checkint //XXX error checkint
vector<VariableBinding>::iterator itr std::vector<VariableBinding>::const_iterator itr =
= find_if(bindings.begin(), bindings.end(), std::find_if(bindings.begin(), bindings.end(),
boost::bind(&VariableBinding::name, _1) == name); [&name] (const VariableBinding& v) {
return v.name == name; });
if (itr != bindings.end()) if (itr != bindings.end())
return itr->location; return itr->location;
size_t result = bindings.size(); 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, bool BindingLayout::findBinding(const std::string& name,
VariableBinding& result) const VariableBinding& result) const
{ {
using namespace std; std::vector<VariableBinding>::const_iterator itr =
using namespace boost; std::find_if(bindings.begin(), bindings.end(),
vector<VariableBinding>::const_iterator itr [&name] (const VariableBinding& v) {
= find_if(bindings.begin(), bindings.end(), return v.name == name; });
boost::bind(&VariableBinding::name, _1) == name);
if (itr != bindings.end()) { if (itr != bindings.end()) {
result = *itr; result = *itr;
return true; return true;