Hmm, odd, I could of sworn that it wasn't required... now where did I read that...
Found it:
Note that the & isn't really necessary unless you happen to be using Microsoft Visual C++ version 6.
It is refering to function pointers, that is actually in the boost documentation:
http://www.boost.org/doc/html/function/ ... #id2688524
So it might only be with boost...
EDIT: In another program I have that uses boost::function, this is what the compiled code turns into when calling the function:
00401124 mov edi,dword ptr [callbackEvent]
00401127 test edi,edi
00401129 jne $L82157 (40113Dh)
0040112B lea eax,[ebp-34h]
0040112E push eax
0040112F call boost::bad_function_call::bad_function_call (401000h)
00401134 mov byte ptr [ebp-4],1
00401138 call boost::throw_exception<boost::bad_function_call> (403320h)
$L82157:
0040113D mov esi,dword ptr [ebp+0Ch]
00401140 push 0Dh
00401142 push esi
00401143 call dword ptr [ebp+10h]
, in which most of it is just if it fails, no function assigned to it. So assuming that the function has something in it, this is its code path:
00401124 mov edi,dword ptr [tes]
00401127 test edi,edi
00401129 jne $L82157 (40113Dh)
0040113D mov esi,dword ptr [ebp+0Ch]
00401140 push 0Dh
00401142 push esi
00401143 call dword ptr [ebp+10h]
Going to test the fast delegate thing when I get a chance, then post up its generated assembly. Let's see how it compares. Don't forget that the fastdelegate function is years old, boost:function gets an update every revision (few times a year), so it would make sense it would be as perfect as can be, especially since it is already accepted into std (to be released upon next C++ version, 2007 is expected
).
EDIT2: Gull bloody frick I can't get this fast delegate to compile. Trying to convert what I showed above from using boost to fastdelegate Quick help you who use it?
Using boost I was doing:
template<class cla>
void saveMethodPointer(boost::function<void(cla*,int)> tes, cla *instancedClassPointer){
methodPtr = boost::bind(tes, instancedClassPointer, _1);
}
I can't seem to figure out a way to get this to compile with fastdelegate, this is where I am at now:
template<class cla>
void saveMethodPointer(fastdelegate::FastDelegate2<cla*,int> tes, cla *instancedClassPointer){
methodPtr = fastdelegate::MakeDelegate(instancedClassPointer, tes);
}
Also tried:
template<class cla>
void saveMethodPointer(fastdelegate::FastDelegate2<cla*,int> tes, cla *instancedClassPointer){
methodPtr.bind(instancedClassPointer, tes);
}
Nothing will compile like this using fastdelegate, and I have a good couple dozen things written using this way.
0040F3A0 mov ecx,dword ptr [methodPtr]
0040F3A3 push 10h
0040F3A5 call dword ptr [ebp-8]
EDIT3: Okay, not using a passing thing like above, actually putting a makedelegate thing inside a source file that calls that function (ew) and it works, here is the same code at the same location:
0040F3B0 mov ecx,dword ptr [tes]
0040F3B3 push 10h
0040F3B5 lea edx,[callbackEvent]
0040F3B8 push edx
0040F3B9 call dword ptr [ebp-8]
And here is the boost one again:
00401124 mov edi,dword ptr [tes]
00401127 test edi,edi
00401129 jne $L82157 (40113Dh)
0040113D mov esi,dword ptr [ebp+0Ch]
00401140 push 0Dh
00401142 push esi
00401143 call dword ptr [ebp+10h]
The boost one has a check to make sure it is valid, other then that they are... identical. I have a place where functors are used, going to test it there...
EDIT4: Okay, here is the assembly using a functor and boost::function:
0040F477 mov eax,offset boost::detail::function::functor_manager<callBackFunctor,std::allocator<void> >::manage (403820h)
0040F47C test eax,eax
0040F47E mov dword ptr [ebp-4],0
0040F485 jne main+99h (40F499h)
0040F487 lea ecx,[ebp-50h]
0040F48A push ecx
0040F48B call boost::bad_function_call::bad_function_call (401000h)
0040F490 mov byte ptr [ebp-4],1
0040F494 jmp boost::throw_exception<boost::bad_function_call> (403350h)
0040F499 push 11h
0040F49B push esi
0040F49C call boost::detail::function::void_function_obj_invoker1<callBackFunctor,void,int>::invoke (4037F0h)
Again, a ton of failure condition code, the actual code is quite small, but since it is a functor it has another jump to do before the function is called, that call leads to another section of code that apparently inlined my entire functor into, the code that isn't my functor is two assembly lines total.
Now, as for using fastdelegate, still trying to get it to compile it, getting rather irritating.
boost::function<void(int)> m_ActionCallback = theFunctor;
is basically what I'm doing with the boost code (although it is a member variable and theFunctor is a function variable passed in).
FastDelegate1<int> m_ActionCallback = theFunctor;
This just does not want to compile, and I can't figure out a way. I've tried the makedelegate, bind, all sorts of things...