Hi! I am dog.in.yellow(dog.in.yellow@163.com)
There are two problems when I use binded functor.
1. I bind a std::string param,but it has lost when called.
2. Called a binded functor out of the scoap of an user-defined object will cause a memory error.
struct TestFunctor
{
int operator()(string str)
{
cout << str << endl;
return 0;
}
};
Functor<int,NullType> BindCmd1()
{
TestFunctor f;
Functor<int,LOKI_TYPELIST_1(string) > cmd1( f );
Functor<int,NullType> bcmd1 = BindFirst( cmd1, "another bind cmd1" );
return bcmd1;
}
int _tmain(int argc, _TCHAR* argv[])
{
TestFunctor f;
Functor<int,LOKI_TYPELIST_1(string) > cmd1( f );
//problem one:when bcmd1() called,the str is empty.
//But there's no problem in v0.1.5
Functor<int,NullType> bcmd1 = BindFirst( cmd1, "bind cmd1" );
bcmd1();
/*problem two:called the functor out of the scoap of params will cause a memory error. It's the same in v0.1.5. And I modified the BoundTypeStorage in class BinderFirst to avoid it.
the original definition:
typedef typename Private::BinderFirstBoundTypeStorage<
typename Private::BinderFirstTraits<OriginalFunctor>
::OriginalParm1>
::RefOrValue
BoundTypeStorage;
my definition:
typedef typename Private::BinderFirstTraits<OriginalFunctor>
::OriginalParm1
BoundTypeStorage;
*/
Functor<int,NullType> bcmd1_1 = BindCmd1();
bcmd1_1();
}
test case