From 567293c14d1a4daac30185019970f37fddf84ca1 Mon Sep 17 00:00:00 2001 From: gallaert Date: Tue, 21 Apr 2020 15:38:45 +0100 Subject: [PATCH] Replace boost::function by std::function --- simgear/canvas/canvas_fwd.hxx | 10 ++-- simgear/canvas/elements/CanvasElement.hxx | 28 +++++----- simgear/canvas/layout/NasalWidget.cxx | 16 +++--- simgear/canvas/layout/NasalWidget.hxx | 4 +- simgear/io/HTTPRequest.cxx | 2 + simgear/io/HTTPRequest.hxx | 2 +- simgear/io/test_HTTP.cxx | 2 +- simgear/io/test_repository.cxx | 1 + simgear/misc/ListDiff.hxx | 3 +- simgear/misc/lru_cache.hxx | 1 - simgear/nasal/cppbind/Ghost.hxx | 51 +++++++++---------- .../nasal/cppbind/NasalEmesaryInterface.hxx | 2 - simgear/nasal/cppbind/NasalObject.hxx | 2 +- .../cppbind/detail/from_nasal_helper.hxx | 13 +++-- .../nasal/cppbind/detail/to_nasal_helper.cxx | 2 - .../nasal/cppbind/detail/to_nasal_helper.hxx | 3 +- simgear/nasal/cppbind/test/cppbind_test.cxx | 14 ++--- .../nasal/cppbind/test/cppbind_test_ghost.cxx | 2 +- simgear/package/Catalog.cxx | 3 +- simgear/package/Catalog.hxx | 2 +- simgear/package/Install.cxx | 3 +- simgear/package/Install.hxx | 5 +- simgear/package/Package.cxx | 1 + simgear/package/Package.hxx | 2 +- simgear/package/Root.cxx | 4 +- simgear/props/PropertyBasedMgr.hxx | 3 +- simgear/structure/function_list.hxx | 10 ++-- simgear/structure/function_list_test.cxx | 4 +- 28 files changed, 96 insertions(+), 99 deletions(-) diff --git a/simgear/canvas/canvas_fwd.hxx b/simgear/canvas/canvas_fwd.hxx index 4d0127d1..4913f569 100644 --- a/simgear/canvas/canvas_fwd.hxx +++ b/simgear/canvas/canvas_fwd.hxx @@ -26,9 +26,9 @@ #include #include -#include - +#include #include +#include #include namespace simgear @@ -83,10 +83,10 @@ namespace canvas typedef osg::ref_ptr FontPtr; typedef std::vector Placements; - typedef boost::function PlacementFactory; + typedef std::function PlacementFactory; - typedef boost::function EventListener; + typedef std::function EventListener; } // namespace canvas } // namespace simgear diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx index 31fe8ccc..5bd700b1 100644 --- a/simgear/canvas/elements/CanvasElement.hxx +++ b/simgear/canvas/elements/CanvasElement.hxx @@ -29,8 +29,6 @@ #include #include -#include - namespace osg { class Drawable; @@ -61,9 +59,9 @@ namespace canvas OSGUserData(ElementPtr element); }; - typedef boost::function + typedef std::function StyleSetterFunc; - typedef boost::function + typedef std::function StyleSetterFuncUnchecked; struct StyleSetter: public SGReferenced @@ -318,7 +316,7 @@ namespace canvas StyleSetter addStyle( const std::string& name, const std::string& type, - const boost::function& setter, + const std::function& setter, bool inheritable = true ) { StyleInfo& style_info = _style_setters[ name ]; @@ -359,7 +357,7 @@ namespace canvas StyleSetter addStyle( const std::string& name, const std::string& type, - const boost::function& setter, + const std::function& setter, bool inheritable = true ) { return addStyle(name, type, setter, inheritable); @@ -380,7 +378,7 @@ namespace canvas ( name, type, - boost::function(setter), + std::function(setter), inheritable ); } @@ -401,7 +399,7 @@ namespace canvas ( name, type, - boost::function(setter), + std::function(setter), inheritable ); } @@ -420,7 +418,7 @@ namespace canvas ( name, type, - boost::function(setter), + std::function(setter), inheritable ); } @@ -483,7 +481,7 @@ namespace canvas StyleSetter addStyle( const std::string& name, const std::string& type, - const boost::function& setter, + const std::function& setter, OtherRef Derived::*instance_ref, bool inheritable = true ) { @@ -513,7 +511,7 @@ namespace canvas ( name, type, - boost::function(setter), + std::function(setter), instance_ref, inheritable ); @@ -521,7 +519,7 @@ namespace canvas template static - boost::function + std::function bindOther( void (Other::*setter)(T), OtherRef Derived::*instance_ref ) { return std::bind(setter, @@ -531,8 +529,8 @@ namespace canvas template static - boost::function - bindOther( const boost::function& setter, + std::function + bindOther( const std::function& setter, OtherRef Derived::*instance_ref ) { return std::bind(setter, @@ -545,7 +543,7 @@ namespace canvas static StyleSetterFuncUnchecked bindStyleSetter( const std::string& name, - const boost::function& setter ) + const std::function& setter ) { return std::bind(setter, // We will only call setters with Derived instances, so we can safely diff --git a/simgear/canvas/layout/NasalWidget.cxx b/simgear/canvas/layout/NasalWidget.cxx index 9e984642..faf9577b 100644 --- a/simgear/canvas/layout/NasalWidget.cxx +++ b/simgear/canvas/layout/NasalWidget.cxx @@ -150,7 +150,7 @@ namespace canvas //---------------------------------------------------------------------------- bool NasalWidget::hasHeightForWidth() const { - return !_height_for_width.empty() || !_min_height_for_width.empty(); + return _height_for_width || _min_height_for_width; } //---------------------------------------------------------------------------- @@ -186,7 +186,7 @@ namespace canvas int NasalWidget::callHeightForWidthFunc( const HeightForWidthFunc& hfw, int w ) const { - if( hfw.empty() ) + if( !hfw ) return -1; try @@ -239,17 +239,17 @@ namespace canvas //---------------------------------------------------------------------------- int NasalWidget::heightForWidthImpl(int w) const { - return callHeightForWidthFunc( _height_for_width.empty() - ? _min_height_for_width - : _height_for_width, w ); + return callHeightForWidthFunc( _height_for_width + ? _height_for_width + : _min_height_for_width, w ); } //---------------------------------------------------------------------------- int NasalWidget::minimumHeightForWidthImpl(int w) const { - return callHeightForWidthFunc( _min_height_for_width.empty() - ? _height_for_width - : _min_height_for_width, w ); + return callHeightForWidthFunc( _min_height_for_width + ? _min_height_for_width + : _height_for_width, w ); } diff --git a/simgear/canvas/layout/NasalWidget.hxx b/simgear/canvas/layout/NasalWidget.hxx index 02a26ba2..95d7d3ec 100644 --- a/simgear/canvas/layout/NasalWidget.hxx +++ b/simgear/canvas/layout/NasalWidget.hxx @@ -40,8 +40,8 @@ namespace canvas { public: - typedef boost::function SetGeometryFunc; - typedef boost::function HeightForWidthFunc; + typedef std::function SetGeometryFunc; + typedef std::function HeightForWidthFunc; /** * diff --git a/simgear/io/HTTPRequest.cxx b/simgear/io/HTTPRequest.cxx index 7266d780..1e649c01 100644 --- a/simgear/io/HTTPRequest.cxx +++ b/simgear/io/HTTPRequest.cxx @@ -18,6 +18,8 @@ #include #include "HTTPRequest.hxx" +#include + #include #include #include diff --git a/simgear/io/HTTPRequest.hxx b/simgear/io/HTTPRequest.hxx index ef55e832..a8f17341 100644 --- a/simgear/io/HTTPRequest.hxx +++ b/simgear/io/HTTPRequest.hxx @@ -44,7 +44,7 @@ class Request: public SGReferenced { public: - typedef boost::function Callback; + typedef std::function Callback; enum ReadyState { diff --git a/simgear/io/test_HTTP.cxx b/simgear/io/test_HTTP.cxx index 13723741..7311b922 100644 --- a/simgear/io/test_HTTP.cxx +++ b/simgear/io/test_HTTP.cxx @@ -1,5 +1,5 @@ #include - +#include #include #include #include diff --git a/simgear/io/test_repository.cxx b/simgear/io/test_repository.cxx index 9c641b77..37a5b63c 100644 --- a/simgear/io/test_repository.cxx +++ b/simgear/io/test_repository.cxx @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/simgear/misc/ListDiff.hxx b/simgear/misc/ListDiff.hxx index 2db9234c..f5d2cc11 100644 --- a/simgear/misc/ListDiff.hxx +++ b/simgear/misc/ListDiff.hxx @@ -21,7 +21,6 @@ #define SG_LISTDIFF_HXX_ #include -#include namespace simgear { @@ -30,7 +29,7 @@ namespace simgear struct ListDiff { typedef std::vector List; - typedef boost::function Callback; + typedef std::function Callback; /** * Perform list diff in-place (modifies both lists) and call cb_add for diff --git a/simgear/misc/lru_cache.hxx b/simgear/misc/lru_cache.hxx index 13d74fb5..2070a114 100644 --- a/simgear/misc/lru_cache.hxx +++ b/simgear/misc/lru_cache.hxx @@ -33,7 +33,6 @@ #ifndef LRU_CACHE_HXX_ #define LRU_CACHE_HXX_ -#include #include #include #include diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index 235d6453..80a8d43a 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -30,7 +30,6 @@ #include #include -#include #include #include @@ -216,7 +215,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 std::bind) + * // and anything else bindable using std::function and std::bind) * .method("myMember", &MyClass::myMember) * .method("doSomething", &MyClass::doSomethingElse) * .method("other", &myOtherFreeMember); @@ -233,16 +232,16 @@ namespace nasal using weak_ref = typename shared_ptr_traits::weak_ref; using member_func_t = naRef (raw_type::*)(const CallContext&); using free_func_t = naRef (*)(raw_type&, const CallContext&); - using getter_t = boost::function; - using setter_t = boost::function; - using method_t = boost::function; + using getter_t = std::function; + using setter_t = std::function; + using method_t = std::function; using fallback_getter_t = - boost::function; + std::function; using fallback_setter_t = - boost::function; + std::function; template - using method_variadic_t = boost::function; + using method_variadic_t = std::function; class MethodHolder: public internal::MethodHolder @@ -564,7 +563,7 @@ namespace nasal const getter_t& getter, const setter_t& setter = setter_t() ) { - if( !getter.empty() || !setter.empty() ) + if( getter || setter ) _members[field] = member_t(getter, setter); else SG_LOG @@ -591,9 +590,9 @@ namespace nasal * of this ghost, and convert it to the given @a Param type. */ template - Ghost& _get( const boost::function& getter ) + Ghost& _get( const std::function& getter ) { return _get(std::bind(convert_param_invoker, getter, @@ -623,7 +622,7 @@ namespace nasal Ghost& _get(bool (raw_type::*getter)(const std::string&, Param&) const) { return _get( - boost::function(getter) + std::function(getter) ); } @@ -666,9 +665,9 @@ namespace nasal * this ghost, and convert it to the given @a Param type. */ template - Ghost& _set(const boost::function& setter) + Ghost& _set(const std::function& setter) { // Setter signature: bool( raw_type&, // naContext, @@ -702,7 +701,7 @@ namespace nasal Ghost& _set(bool (raw_type::*setter)(const std::string&, Param)) { return _set( - boost::function(setter) + std::function(setter) ); } @@ -768,7 +767,7 @@ namespace nasal Ghost& method ( const std::string& name, - const boost::function& func + const std::function& func ) { return method(name, std::bind(method_invoker, @@ -789,7 +788,7 @@ namespace nasal std::index_sequence ) { return method(name, - typename boost::function + typename std::function (std::bind(func, std::placeholders::_1, std::bind(&Ghost::arg_from_nasal, @@ -1149,9 +1148,9 @@ namespace nasal static bool convert_param_invoker ( - const boost::function& func, + const std::function& func, raw_type& obj, naContext c, const std::string& key, @@ -1174,7 +1173,7 @@ namespace nasal std::enable_if_t::value, naRef> method_invoker ( - const boost::function& func, + const std::function& func, raw_type& obj, const CallContext& ctx ) @@ -1190,7 +1189,7 @@ namespace nasal std::enable_if_t::value, naRef> method_invoker ( - const boost::function& func, + const std::function& func, raw_type& obj, const CallContext& ctx ) @@ -1362,7 +1361,7 @@ namespace nasal } else if( member->second.func ) *out = member->second.func->get_naRef(c); - else if( !member->second.getter.empty() ) + else if( member->second.getter ) *out = member->second.getter(obj, c); else return "Read-protected member"; @@ -1411,7 +1410,7 @@ namespace nasal else if( !fallback_set(obj, c, key, val) ) naRuntimeError(c, "ghost: Failed to write (_set: %s)", key.c_str()); } - else if( member->second.setter.empty() ) + else if( !member->second.setter ) naRuntimeError(c, "ghost: Write protected member: %s", key.c_str()); else if( member->second.func ) naRuntimeError(c, "ghost: Write to function: %s", key.c_str()); diff --git a/simgear/nasal/cppbind/NasalEmesaryInterface.hxx b/simgear/nasal/cppbind/NasalEmesaryInterface.hxx index 64d24f18..df991aad 100644 --- a/simgear/nasal/cppbind/NasalEmesaryInterface.hxx +++ b/simgear/nasal/cppbind/NasalEmesaryInterface.hxx @@ -27,8 +27,6 @@ #include #include -#include - #include #include diff --git a/simgear/nasal/cppbind/NasalObject.hxx b/simgear/nasal/cppbind/NasalObject.hxx index 4d965d9c..44caf563 100644 --- a/simgear/nasal/cppbind/NasalObject.hxx +++ b/simgear/nasal/cppbind/NasalObject.hxx @@ -52,7 +52,7 @@ namespace nasal return Ret(); Context ctx; - auto func = get_member>( + auto func = get_member>( ctx, _nasal_impl.get_naRef(), name ); if( func ) diff --git a/simgear/nasal/cppbind/detail/from_nasal_helper.hxx b/simgear/nasal/cppbind/detail/from_nasal_helper.hxx index afda9f24..b4f2d64f 100644 --- a/simgear/nasal/cppbind/detail/from_nasal_helper.hxx +++ b/simgear/nasal/cppbind/detail/from_nasal_helper.hxx @@ -32,9 +32,8 @@ #include #include -#include - #include +#include #include #include @@ -110,14 +109,14 @@ namespace nasal bool from_nasal_helper(naContext c, naRef ref, const bool*); /** - * Convert a Nasal function to a boost::function with the given signature. + * Convert a Nasal function to a std::function with the given signature. * * @tparam Sig Signature of returned function (arguments and return value * are automatically converted using from_nasal/to_nasal) */ template - boost::function - from_nasal_helper(naContext c, naRef ref, const boost::function*) + std::function + from_nasal_helper(naContext c, naRef ref, const std::function*) { if( naIsNil(ref) ) return {}; @@ -131,11 +130,11 @@ namespace nasal } template - boost::function + std::function from_nasal_helper(naContext c, naRef ref, Ret (*const)(Args...)) { return - from_nasal_helper(c, ref, static_cast*>(0)); + from_nasal_helper(c, ref, static_cast*>(0)); } /** diff --git a/simgear/nasal/cppbind/detail/to_nasal_helper.cxx b/simgear/nasal/cppbind/detail/to_nasal_helper.cxx index 26d3363f..a0c76b20 100644 --- a/simgear/nasal/cppbind/detail/to_nasal_helper.cxx +++ b/simgear/nasal/cppbind/detail/to_nasal_helper.cxx @@ -24,8 +24,6 @@ #include #include -#include - namespace nasal { // create single instance of the main loop recipient for Nasal - this will self register at the diff --git a/simgear/nasal/cppbind/detail/to_nasal_helper.hxx b/simgear/nasal/cppbind/detail/to_nasal_helper.hxx index 1098f08e..22d24cf2 100644 --- a/simgear/nasal/cppbind/detail/to_nasal_helper.hxx +++ b/simgear/nasal/cppbind/detail/to_nasal_helper.hxx @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -42,7 +43,7 @@ class SGPath; namespace nasal { - typedef boost::function free_function_t; + typedef std::function free_function_t; /** * Convert std::string to Nasal string diff --git a/simgear/nasal/cppbind/test/cppbind_test.cxx b/simgear/nasal/cppbind/test/cppbind_test.cxx index d488c5a3..1b7e5885 100644 --- a/simgear/nasal/cppbind/test/cppbind_test.cxx +++ b/simgear/nasal/cppbind/test/cppbind_test.cxx @@ -231,25 +231,25 @@ BOOST_AUTO_TEST_CASE( cppbind_misc_testing ) // 'func' is a C++ function registered to Nasal and now converted back to C++ - boost::function f = hash.get("func"); + std::function f = hash.get("func"); BOOST_REQUIRE( f ); BOOST_CHECK_EQUAL(f(3), 3); - boost::function fs = hash.get("func"); + std::function fs = hash.get("func"); BOOST_REQUIRE( fs ); BOOST_CHECK_EQUAL(fs(14), "14"); - typedef boost::function FuncVoidInt; + typedef std::function FuncVoidInt; FuncVoidInt fvi = hash.get("func"); BOOST_REQUIRE( fvi ); fvi(123); - typedef boost::function FuncMultiArg; + typedef std::function FuncMultiArg; FuncMultiArg fma = hash.get("func"); BOOST_REQUIRE( fma ); BOOST_CHECK_EQUAL(fma("test", 3, .5), "test"); - typedef boost::function naRefMemFunc; + typedef std::function naRefMemFunc; naRefMemFunc fmem = hash.get("func"); BOOST_REQUIRE( fmem ); naRef ret = fmem(hash.get_naRef()), @@ -258,7 +258,7 @@ BOOST_AUTO_TEST_CASE( cppbind_misc_testing ) // Check if nasal::Me gets passed as self/me and remaining arguments are // passed on to function - typedef boost::function MeIntFunc; + typedef std::function MeIntFunc; MeIntFunc fmeint = hash.get("func"); BOOST_CHECK_EQUAL(fmeint(Me{}, 5), 5); @@ -331,7 +331,7 @@ BOOST_AUTO_TEST_CASE( cppbind_misc_testing ) BOOST_CHECK( naIsFunc(thisGetter) ); // ...and check if it really gets passed the correct instance - typedef boost::function MemFunc; + typedef std::function MemFunc; MemFunc fGetThis = c.from_nasal(thisGetter); BOOST_REQUIRE( fGetThis ); BOOST_CHECK_EQUAL( fGetThis(Me{derived}), (unsigned long)d.get() ); diff --git a/simgear/nasal/cppbind/test/cppbind_test_ghost.cxx b/simgear/nasal/cppbind/test/cppbind_test_ghost.cxx index 77003e92..cdfcdf12 100644 --- a/simgear/nasal/cppbind/test/cppbind_test_ghost.cxx +++ b/simgear/nasal/cppbind/test/cppbind_test_ghost.cxx @@ -204,7 +204,7 @@ BOOST_AUTO_TEST_CASE( bind_methods ) } }; using TestClassPtr = std::shared_ptr; - auto set_func = boost::function< + auto set_func = std::function< void (TestClass&, int, const std::string&, const std::string&, int) >(&TestClass::set); nasal::Ghost::init("TestClass") diff --git a/simgear/package/Catalog.cxx b/simgear/package/Catalog.cxx index d56975c0..0c1296a8 100644 --- a/simgear/package/Catalog.cxx +++ b/simgear/package/Catalog.cxx @@ -19,8 +19,9 @@ #include #include -#include +#include #include +#include #include #include diff --git a/simgear/package/Catalog.hxx b/simgear/package/Catalog.hxx index 0b885dfc..7c421b88 100644 --- a/simgear/package/Catalog.hxx +++ b/simgear/package/Catalog.hxx @@ -139,7 +139,7 @@ public: */ bool isEnabled() const; - typedef boost::function Callback; + typedef std::function Callback; void addStatusCallback(const Callback& cb); diff --git a/simgear/package/Install.cxx b/simgear/package/Install.cxx index 091af47a..f784b305 100644 --- a/simgear/package/Install.cxx +++ b/simgear/package/Install.cxx @@ -18,8 +18,9 @@ #include #include -#include #include +#include +#include #include #include diff --git a/simgear/package/Install.hxx b/simgear/package/Install.hxx index 1a4124b4..086c5284 100644 --- a/simgear/package/Install.hxx +++ b/simgear/package/Install.hxx @@ -52,9 +52,8 @@ class Install : public SGReferenced public: virtual ~Install(); - typedef boost::function Callback; - typedef boost::function - ProgressCallback; + typedef std::function Callback; + typedef std::function ProgressCallback; /** * create from a directory on disk, or fail. diff --git a/simgear/package/Package.cxx b/simgear/package/Package.cxx index 8bc8e60a..c9acdb6f 100644 --- a/simgear/package/Package.cxx +++ b/simgear/package/Package.cxx @@ -19,6 +19,7 @@ #include +#include #include #include diff --git a/simgear/package/Package.hxx b/simgear/package/Package.hxx index 03e44717..b274d408 100644 --- a/simgear/package/Package.hxx +++ b/simgear/package/Package.hxx @@ -51,7 +51,7 @@ typedef std::vector PackageList; { public: - typedef boost::function InstallCallback; + typedef std::function InstallCallback; /** * get or create an install for the package diff --git a/simgear/package/Root.cxx b/simgear/package/Root.cxx index 07ac6ff2..e0fedfcf 100755 --- a/simgear/package/Root.cxx +++ b/simgear/package/Root.cxx @@ -19,9 +19,11 @@ #include +#include +#include #include -#include #include +#include #include #include diff --git a/simgear/props/PropertyBasedMgr.hxx b/simgear/props/PropertyBasedMgr.hxx index 1d40326a..f7cb6615 100644 --- a/simgear/props/PropertyBasedMgr.hxx +++ b/simgear/props/PropertyBasedMgr.hxx @@ -23,7 +23,6 @@ #include "PropertyBasedElement.hxx" #include -#include #include namespace simgear @@ -62,7 +61,7 @@ public: virtual const SGPropertyNode* getPropertyRoot() const; protected: - typedef boost::function + typedef std::function ElementFactory; /** Branch in the property tree for this property managed subsystem */ diff --git a/simgear/structure/function_list.hxx b/simgear/structure/function_list.hxx index da9933d6..ce37e4b0 100644 --- a/simgear/structure/function_list.hxx +++ b/simgear/structure/function_list.hxx @@ -19,7 +19,7 @@ #ifndef SG_FUNCTION_LIST_HXX_ #define SG_FUNCTION_LIST_HXX_ -#include +#include #include namespace simgear @@ -27,14 +27,14 @@ namespace simgear template class function_list; /** - * Handle a list of callbacks like a single boost::function. + * Handle a list of callbacks like a single std::function. * * @tparam Ret Return type of the callbacks * @tparam Args Parameter types of the callbacks */ template class function_list: - public std::vector> + public std::vector> { public: Ret operator()(Args ... args) const @@ -53,10 +53,10 @@ namespace simgear /** * Handle a list of callbacks with the same signature as the given - * boost::function type. + * std::function type. */ template - class function_list>: + class function_list>: public function_list { diff --git a/simgear/structure/function_list_test.cxx b/simgear/structure/function_list_test.cxx index 58202c9c..38a0dcf6 100644 --- a/simgear/structure/function_list_test.cxx +++ b/simgear/structure/function_list_test.cxx @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE( create_and_call ) BOOST_REQUIRE_EQUAL(func_called, 2); BOOST_REQUIRE_EQUAL(func2_called, 1); - function_list > func_list2; + function_list > func_list2; func_list2.push_back(&func); func_list2.push_back(&func2); func_list2.push_back(&func2); @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE( create_and_call ) BOOST_REQUIRE_EQUAL(func2_called, 3); // two parameters - function_list > func_list3; + function_list > func_list3; func_list3.push_back(&func_add); func_list3.push_back(&func2_add);