Replace boost::function by std::function

This commit is contained in:
gallaert 2020-04-21 15:38:45 +01:00 committed by James Turner
parent 2ff6a4966a
commit 567293c14d
28 changed files with 96 additions and 99 deletions

View File

@ -26,9 +26,9 @@
#include <osg/ref_ptr>
#include <osgText/Font>
#include <boost/function.hpp>
#include <functional>
#include <map>
#include <memory>
#include <vector>
namespace simgear
@ -83,10 +83,10 @@ namespace canvas
typedef osg::ref_ptr<osgText::Font> FontPtr;
typedef std::vector<PlacementPtr> Placements;
typedef boost::function<Placements( SGPropertyNode*,
typedef std::function<Placements( SGPropertyNode*,
CanvasPtr )> PlacementFactory;
typedef boost::function<void(const EventPtr&)> EventListener;
typedef std::function<void(const EventPtr&)> EventListener;
} // namespace canvas
} // namespace simgear

View File

@ -29,8 +29,6 @@
#include <osg/BoundingBox>
#include <osg/MatrixTransform>
#include <boost/function.hpp>
namespace osg
{
class Drawable;
@ -61,9 +59,9 @@ namespace canvas
OSGUserData(ElementPtr element);
};
typedef boost::function<bool(Element&, const SGPropertyNode*)>
typedef std::function<bool(Element&, const SGPropertyNode*)>
StyleSetterFunc;
typedef boost::function<void(Element&, const SGPropertyNode*)>
typedef std::function<void(Element&, const SGPropertyNode*)>
StyleSetterFuncUnchecked;
struct StyleSetter:
public SGReferenced
@ -318,7 +316,7 @@ namespace canvas
StyleSetter
addStyle( const std::string& name,
const std::string& type,
const boost::function<void (Derived&, T2)>& setter,
const std::function<void (Derived&, T2)>& 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<void (Derived&, T)>& setter,
const std::function<void (Derived&, T)>& setter,
bool inheritable = true )
{
return addStyle<T, T>(name, type, setter, inheritable);
@ -380,7 +378,7 @@ namespace canvas
(
name,
type,
boost::function<void (Derived&, T)>(setter),
std::function<void (Derived&, T)>(setter),
inheritable
);
}
@ -401,7 +399,7 @@ namespace canvas
(
name,
type,
boost::function<void (Derived&, T2)>(setter),
std::function<void (Derived&, T2)>(setter),
inheritable
);
}
@ -420,7 +418,7 @@ namespace canvas
(
name,
type,
boost::function<void (Derived&, const std::string&)>(setter),
std::function<void (Derived&, const std::string&)>(setter),
inheritable
);
}
@ -483,7 +481,7 @@ namespace canvas
StyleSetter
addStyle( const std::string& name,
const std::string& type,
const boost::function<void (Other&, T2)>& setter,
const std::function<void (Other&, T2)>& setter,
OtherRef Derived::*instance_ref,
bool inheritable = true )
{
@ -513,7 +511,7 @@ namespace canvas
(
name,
type,
boost::function<void (Other&, const std::string&)>(setter),
std::function<void (Other&, const std::string&)>(setter),
instance_ref,
inheritable
);
@ -521,7 +519,7 @@ namespace canvas
template<typename T, class Derived, class Other, class OtherRef>
static
boost::function<void (Derived&, T)>
std::function<void (Derived&, T)>
bindOther( void (Other::*setter)(T), OtherRef Derived::*instance_ref )
{
return std::bind(setter,
@ -531,8 +529,8 @@ namespace canvas
template<typename T, class Derived, class Other, class OtherRef>
static
boost::function<void (Derived&, T)>
bindOther( const boost::function<void (Other&, T)>& setter,
std::function<void (Derived&, T)>
bindOther( const std::function<void (Other&, T)>& 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<void (Derived&, T2)>& setter )
const std::function<void (Derived&, T2)>& setter )
{
return std::bind(setter,
// We will only call setters with Derived instances, so we can safely

View File

@ -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 );
}

View File

@ -40,8 +40,8 @@ namespace canvas
{
public:
typedef boost::function<void (nasal::Me, const SGRecti&)> SetGeometryFunc;
typedef boost::function<int (nasal::Me, int)> HeightForWidthFunc;
typedef std::function<void (nasal::Me, const SGRecti&)> SetGeometryFunc;
typedef std::function<int (nasal::Me, int)> HeightForWidthFunc;
/**
*

View File

@ -18,6 +18,8 @@
#include <simgear_config.h>
#include "HTTPRequest.hxx"
#include <cstring>
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/strutils.hxx>

View File

@ -44,7 +44,7 @@ class Request:
public SGReferenced
{
public:
typedef boost::function<void(Request*)> Callback;
typedef std::function<void(Request*)> Callback;
enum ReadyState
{

View File

@ -1,5 +1,5 @@
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <sstream>

View File

@ -1,3 +1,4 @@
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <map>

View File

@ -21,7 +21,6 @@
#define SG_LISTDIFF_HXX_
#include <vector>
#include <boost/function.hpp>
namespace simgear
{
@ -30,7 +29,7 @@ namespace simgear
struct ListDiff
{
typedef std::vector<T> List;
typedef boost::function<void (T)> Callback;
typedef std::function<void (T)> Callback;
/**
* Perform list diff in-place (modifies both lists) and call cb_add for

View File

@ -33,7 +33,6 @@
#ifndef LRU_CACHE_HXX_
#define LRU_CACHE_HXX_
#include <boost/function.hpp>
#include <map>
#include <list>
#include <utility>

View File

@ -30,7 +30,6 @@
#include <simgear/structure/SGWeakPtr.hxx>
#include <boost/call_traits.hpp>
#include <boost/function.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <map>
@ -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<T>::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<naRef(raw_type&, naContext)>;
using setter_t = boost::function<void( raw_type&, naContext, naRef)>;
using method_t = boost::function<naRef(raw_type&, const CallContext&)>;
using getter_t = std::function<naRef(raw_type&, naContext)>;
using setter_t = std::function<void( raw_type&, naContext, naRef)>;
using method_t = std::function<naRef(raw_type&, const CallContext&)>;
using fallback_getter_t =
boost::function<bool(raw_type&, naContext, const std::string&, naRef&)>;
std::function<bool(raw_type&, naContext, const std::string&, naRef&)>;
using fallback_setter_t =
boost::function<bool(raw_type&, naContext, const std::string&, naRef)>;
std::function<bool(raw_type&, naContext, const std::string&, naRef)>;
template<class Ret, class... Args>
using method_variadic_t = boost::function<Ret (raw_type&, Args...)>;
using method_variadic_t = std::function<Ret (raw_type&, Args...)>;
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,7 +590,7 @@ namespace nasal
* of this ghost, and convert it to the given @a Param type.
*/
template<class Param>
Ghost& _get( const boost::function<bool ( raw_type&,
Ghost& _get( const std::function<bool ( raw_type&,
const std::string&,
Param& )>& getter )
{
@ -623,7 +622,7 @@ namespace nasal
Ghost& _get(bool (raw_type::*getter)(const std::string&, Param&) const)
{
return _get(
boost::function<bool (raw_type&, const std::string&, Param&)>(getter)
std::function<bool (raw_type&, const std::string&, Param&)>(getter)
);
}
@ -666,7 +665,7 @@ namespace nasal
* this ghost, and convert it to the given @a Param type.
*/
template<class Param>
Ghost& _set(const boost::function<bool ( raw_type&,
Ghost& _set(const std::function<bool ( raw_type&,
const std::string&,
Param )>& setter)
{
@ -702,7 +701,7 @@ namespace nasal
Ghost& _set(bool (raw_type::*setter)(const std::string&, Param))
{
return _set(
boost::function<bool (raw_type&, const std::string&, Param)>(setter)
std::function<bool (raw_type&, const std::string&, Param)>(setter)
);
}
@ -768,7 +767,7 @@ namespace nasal
Ghost& method
(
const std::string& name,
const boost::function<Ret (raw_type&, const CallContext&)>& func
const std::function<Ret (raw_type&, const CallContext&)>& func
)
{
return method(name, std::bind(method_invoker<Ret>,
@ -789,7 +788,7 @@ namespace nasal
std::index_sequence<Indices...> )
{
return method<Ret>(name,
typename boost::function<Ret (raw_type&, const CallContext&)>
typename std::function<Ret (raw_type&, const CallContext&)>
(std::bind(func,
std::placeholders::_1,
std::bind(&Ghost::arg_from_nasal<Args>,
@ -1149,7 +1148,7 @@ namespace nasal
static
bool convert_param_invoker
(
const boost::function<bool ( raw_type&,
const std::function<bool ( raw_type&,
const std::string&,
Param& )>& func,
raw_type& obj,
@ -1174,7 +1173,7 @@ namespace nasal
std::enable_if_t<!std::is_void<Ret>::value, naRef>
method_invoker
(
const boost::function<Ret (raw_type&, const CallContext&)>& func,
const std::function<Ret (raw_type&, const CallContext&)>& func,
raw_type& obj,
const CallContext& ctx
)
@ -1190,7 +1189,7 @@ namespace nasal
std::enable_if_t<std::is_void<Ret>::value, naRef>
method_invoker
(
const boost::function<Ret (raw_type&, const CallContext&)>& func,
const std::function<Ret (raw_type&, const CallContext&)>& 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());

View File

@ -27,8 +27,6 @@
#include <simgear/emesary/Emesary.hxx>
#include <simgear/emesary/notifications.hxx>
#include <boost/function.hpp>
#include <simgear/debug/logstream.hxx>
#include <simgear/threads/SGThread.hxx>

View File

@ -52,7 +52,7 @@ namespace nasal
return Ret();
Context ctx;
auto func = get_member<boost::function<Ret (Me, Args...)>>(
auto func = get_member<std::function<Ret (Me, Args...)>>(
ctx, _nasal_impl.get_naRef(), name
);
if( func )

View File

@ -32,9 +32,8 @@
#include <simgear/structure/exception.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
#include <boost/function.hpp>
#include <array>
#include <functional>
#include <string>
#include <vector>
@ -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<class Ret, class... Args>
boost::function<Ret (Args...)>
from_nasal_helper(naContext c, naRef ref, const boost::function<Ret (Args...)>*)
std::function<Ret (Args...)>
from_nasal_helper(naContext c, naRef ref, const std::function<Ret (Args...)>*)
{
if( naIsNil(ref) )
return {};
@ -131,11 +130,11 @@ namespace nasal
}
template<class Ret, class... Args>
boost::function<Ret (Args...)>
std::function<Ret (Args...)>
from_nasal_helper(naContext c, naRef ref, Ret (*const)(Args...))
{
return
from_nasal_helper(c, ref, static_cast<boost::function<Ret (Args...)>*>(0));
from_nasal_helper(c, ref, static_cast<std::function<Ret (Args...)>*>(0));
}
/**

View File

@ -24,8 +24,6 @@
#include <simgear/math/SGMath.hxx>
#include <simgear/misc/sg_path.hxx>
#include <boost/function.hpp>
namespace nasal
{
// create single instance of the main loop recipient for Nasal - this will self register at the

View File

@ -31,6 +31,7 @@
#include <boost/call_traits.hpp>
#include <array>
#include <functional>
#include <initializer_list>
#include <map>
#include <string>
@ -42,7 +43,7 @@ class SGPath;
namespace nasal
{
typedef boost::function<naRef (CallContext)> free_function_t;
typedef std::function<naRef (CallContext)> free_function_t;
/**
* Convert std::string to Nasal string

View File

@ -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<int (int)> f = hash.get<int (int)>("func");
std::function<int (int)> f = hash.get<int (int)>("func");
BOOST_REQUIRE( f );
BOOST_CHECK_EQUAL(f(3), 3);
boost::function<std::string (int)> fs = hash.get<std::string (int)>("func");
std::function<std::string (int)> fs = hash.get<std::string (int)>("func");
BOOST_REQUIRE( fs );
BOOST_CHECK_EQUAL(fs(14), "14");
typedef boost::function<void (int)> FuncVoidInt;
typedef std::function<void (int)> FuncVoidInt;
FuncVoidInt fvi = hash.get<FuncVoidInt>("func");
BOOST_REQUIRE( fvi );
fvi(123);
typedef boost::function<std::string (const std::string&, int, float)> FuncMultiArg;
typedef std::function<std::string (const std::string&, int, float)> FuncMultiArg;
FuncMultiArg fma = hash.get<FuncMultiArg>("func");
BOOST_REQUIRE( fma );
BOOST_CHECK_EQUAL(fma("test", 3, .5), "test");
typedef boost::function<naRef (naRef)> naRefMemFunc;
typedef std::function<naRef (naRef)> naRefMemFunc;
naRefMemFunc fmem = hash.get<naRefMemFunc>("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<int (Me, int)> MeIntFunc;
typedef std::function<int (Me, int)> MeIntFunc;
MeIntFunc fmeint = hash.get<MeIntFunc>("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<unsigned long (Me)> MemFunc;
typedef std::function<unsigned long (Me)> MemFunc;
MemFunc fGetThis = c.from_nasal<MemFunc>(thisGetter);
BOOST_REQUIRE( fGetThis );
BOOST_CHECK_EQUAL( fGetThis(Me{derived}), (unsigned long)d.get() );

View File

@ -204,7 +204,7 @@ BOOST_AUTO_TEST_CASE( bind_methods )
}
};
using TestClassPtr = std::shared_ptr<TestClass>;
auto set_func = boost::function<
auto set_func = std::function<
void (TestClass&, int, const std::string&, const std::string&, int)
>(&TestClass::set);
nasal::Ghost<TestClassPtr>::init("TestClass")

View File

@ -19,8 +19,9 @@
#include <simgear/package/Catalog.hxx>
#include <algorithm>
#include <fstream>
#include <cassert>
#include <cstring>
#include <fstream>
#include <simgear/debug/logstream.hxx>
#include <simgear/props/props_io.hxx>

View File

@ -139,7 +139,7 @@ public:
*/
bool isEnabled() const;
typedef boost::function<void(Catalog*)> Callback;
typedef std::function<void(Catalog*)> Callback;
void addStatusCallback(const Callback& cb);

View File

@ -18,8 +18,9 @@
#include <simgear_config.h>
#include <simgear/package/Install.hxx>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <simgear/package/unzip.h>
#include <simgear/package/md5.h>

View File

@ -52,9 +52,8 @@ class Install : public SGReferenced
public:
virtual ~Install();
typedef boost::function<void(Install*)> Callback;
typedef boost::function<void(Install*, unsigned int, unsigned int)>
ProgressCallback;
typedef std::function<void(Install*)> Callback;
typedef std::function<void(Install*, unsigned int, unsigned int)> ProgressCallback;
/**
* create from a directory on disk, or fail.

View File

@ -19,6 +19,7 @@
#include <simgear/package/Package.hxx>
#include <algorithm>
#include <cassert>
#include <simgear/debug/logstream.hxx>

View File

@ -51,7 +51,7 @@ typedef std::vector<PackageRef> PackageList;
{
public:
typedef boost::function<void(Package*, Install*)> InstallCallback;
typedef std::function<void(Package*, Install*)> InstallCallback;
/**
* get or create an install for the package

View File

@ -19,9 +19,11 @@
#include <simgear/package/Root.hxx>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <simgear/debug/logstream.hxx>

View File

@ -23,7 +23,6 @@
#include "PropertyBasedElement.hxx"
#include <simgear/structure/subsystem_mgr.hxx>
#include <boost/function.hpp>
#include <vector>
namespace simgear
@ -62,7 +61,7 @@ public:
virtual const SGPropertyNode* getPropertyRoot() const;
protected:
typedef boost::function<PropertyBasedElementPtr(SGPropertyNode*)>
typedef std::function<PropertyBasedElementPtr(SGPropertyNode*)>
ElementFactory;
/** Branch in the property tree for this property managed subsystem */

View File

@ -19,7 +19,7 @@
#ifndef SG_FUNCTION_LIST_HXX_
#define SG_FUNCTION_LIST_HXX_
#include <boost/function.hpp>
#include <functional>
#include <vector>
namespace simgear
@ -27,14 +27,14 @@ namespace simgear
template<typename Sig> 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 Ret, class... Args>
class function_list<Ret(Args...)>:
public std::vector<boost::function<Ret(Args...)>>
public std::vector<std::function<Ret(Args...)>>
{
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 Ret, class... Args>
class function_list<boost::function<Ret(Args...)>>:
class function_list<std::function<Ret(Args...)>>:
public function_list<Ret(Args...)>
{

View File

@ -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<boost::function<int (int)> > func_list2;
function_list<std::function<int (int)> > 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<boost::function<int (int, int)> > func_list3;
function_list<std::function<int (int, int)> > func_list3;
func_list3.push_back(&func_add);
func_list3.push_back(&func2_add);