开发者

Alternatives to Boost::Function and Boost::Bind

Does anyone know of any libraries that can be used in place of Boost::Function and Boost::Bind? We are trying to remove our dependency on Boost since it's a pretty large library. We're looking for s开发者_运维知识库omething more focused.

I found this: http://www.codeproject.com/KB/cpp/fastdelegate2.aspx

I've never used it though and it looks like it was last updated in 2007. Has anyone used it?

We use callbacks are fair amount throughout our code and boost::function and boost::bind allow us to do so. But we've run into problems turning RTTI and exceptions off using Boost. So any replacements would need to be usable with RTTI and exceptions turned off.

Thanks!


The implementation that you pointed to is built upon undefined behavior according to the standards. Disabling exceptions should be no problem with Boost.Function, as long as you define your own throw_exception function. And I'm sure disabling RTTI won't be a problem either, since Boost.Function goes through great trouble to avoid virtual functions at all (its all explained in its rationale). There are problems with disabling exceptions and RTTI for some Boost libraries, but Function and Bind are not the case, I have been using them in Android NDK with disabled exceptions and RTTI for a long while.

As for alternatives, you could always use the now standard C++11 ones (based on Boost) which are already available in several compilers; or you could always roll your own. There is also an alternative implementation of Boost.Function by Domagoj Saric, but I cannot seem to find pointers to it right now.

Check out Boost bcp tool, to extract only the files related to Function and Bind, and roll on your own version of them. You shouldn't need to change anything for them to work.


I've had good results using the sigslot library. This is an extremely lightweight library, it consists of just a single header file. It plays nice with STL and has optional multithreading support for Windows threads and pthreads.


There is a bcp tool which allows you to copy the part of boost library that you need.

There is no need to find alternatives for boost. This is a great library. If any library exists there it is the best in the world. Probably there are some exceptions like boost.test, but in generally it's true. Particularly it's true for boost.function and for boost.bind.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜