no. of arguments in boost::bind

南楼画角 提交于 2019-12-10 14:14:20

问题


How many maximum arguments can we pass to boost::bind()


回答1:


by default it's 9.

http://www.boost.org/doc/libs/1_45_0/libs/bind/bind.html#NumberOfArguments




回答2:


Even if you can't switch to C++11, you should consider switching from boost::function to the TR1 functions, which was a preview for C++11

Basically, what started out as boost::function became part of the C++ standard library, which nowadays is defined with variadic templates. In a nutshell this means that there is no hard limit anymore (but you might need to define additional placeholder variables if you need something beyond _19 )

To switch from boost::function to std::tr1 do the following

find all occurences of #include <boost/function> and #include <boost/bind> and replace them by:

 #include <tr1/functional>
 using std::tr1::function;
 using std::tr1::bind;
 using std::tr1::placeholders::_1;
 using std::tr1::placeholders::_2;
...

This should work as a drop-in replacement. If you happen to switch to C++11 later, just throw out the "tr1" part.



来源:https://stackoverflow.com/questions/4955841/no-of-arguments-in-boostbind

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!