Hello
I have the following simple code, but doesn't get compiled:
#define DECLARE_PTR_AUTO_DELETOR_CONDITIONAL(CLASS, VAR_PTR, CONDITION)\
boost::scoped_ptr<CLASS> auto__deletor__for__ ## VAR_PTR (\
boost::lambda::ret(boost::lambda::if_then_else(_1,\
VAR_PTR, static_cast(0)))(static_cast<bool>(CONDITION)))
struct B
{
B() { std::cout << _T("\nCalling B::B()"); }
~B() { std::cout << _T("\nCalling B::~B()"); }
};
bool processB(B *pb, bool accept)
{
if(accept)
if(pb)
{
std::cout << _T("\nDeleting B by processB()");
delete pb;
}
return accept;
}
void test_selector()
{
bool result;
B *pb1 = new B();
result = processB(pb1, true); // delete by processB
DECLARE_PTR_AUTO_DELETOR_CONDITIONAL(B, pb1, (result == false));
B *pb2 = new B();
result = processB(pb2, false); // you do the job!
DECLARE_PTR_AUTO_DELETOR_CONDITIONAL(B, pb2, (result == false));
}
int main()
{
test_selector();
}
Thanks for any help.
B/Rgds
Max
-------------------------------------------------------------------
新浪空间——与朋友开心分享网络新生活!(http://space.sina.com.cn/ )