No, I want the object to be reference counted - and am aware that internally bind has to make copies. However, I expected at least one, perhaps two or three copies to be made. 10 copies made for a single call to bind seems really expensive. I'm asking more about whether the optimizer is able to optimize out several of these copies, or if it's overhead that one has to accept if one wants to use bind and/or function?
I haven't tested it yet, but I imagine a call to bind with more arguments will involve a lot more copying, as bind looks something like this for argument lists internally:
template< class A1 , class A2 , class A3 , class A4 > class list4: private storage4< A1 , A2 , A3 , A4 >
template< class A1 , class A2 , class A3 , class A4 > struct storage4 : public storage3< A1 , A2 , A3 >
template< class A1 , class A2 , class A3 > struct storage3 : public storage2< A1 , A2 >
template< class A1 , class A2 > struct storage2 : public storage1< A1 >
template< class A1 > struct storage1
Argument A1 is copied for each constructor in the list as it's passed down the inheritance hierarchy.
Are there plans to implement bind using variadic templates? Not sure if that would reduce the number of copies?