5

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

Shweta
  • 5,198
  • 11
  • 44
  • 58

2 Answers2

12

by default it's 9.

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

KitsuneYMG
  • 12,753
  • 4
  • 37
  • 58
  • 2
    And if you are calling functions with more than 9 arguments then you need to rethink your design! – GrahamS Feb 10 '11 at 11:00
  • @GrahamS I think boost.lambda bind takes up to 9 as well. Boost.Spirit.Phoenix, the library I use for functional programming, has default 10 w/a macro to define the upper limit. – KitsuneYMG Feb 10 '11 at 11:06
  • I wrote an IOC system that required templates per argument used to construct objects. I think it ended up going as high as 12. Was probably too many – CashCow Feb 10 '11 at 11:50
  • 1
    @GrahamS : sometimes you just have to consume headers from some commecrial external libraries where discussing the design with the vendor isn't an option. – Ichthyo Jul 03 '13 at 21:30
3

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.

Ichthyo
  • 8,038
  • 2
  • 26
  • 32