[prev in list] [next in list] [prev in thread] [next in thread]
List: boost-users
Subject: [Boost-users] [lambda] Should the code compile?
From: Max <loadcom () sina ! com>
Date: 2008-12-30 12:49:19
Message-ID: 20081230124919.C6B57358C2A () mail175-232 ! sinamail ! sina ! com ! cn
[Download RAW message or body]
[Attachment #2 (text/plain)]
Hello,
For ease of reading, I've reformatted the previously posted message.
I have the following simple code, but doesn't get compiled:
#define DECLARE_PTR_AUTO_DELETOR_CONDITIONAL(CLASS, VAR_PTR, CONDITION)\
boost::scoped_ptr auto__deletor__for__ ## VAR_PTR (\
boost::lambda::ret(boost::lambda::if_then_else(_1,\
VAR_PTR, static_cast(0)))(static_cast(CONDITION)))
struct B
{
B() { std::cout << _T("\nCalling B::B()"); }
~B() { std::cout << _T("\nCalling B::~B()"); }
};
bool processB(B *pb, bool consume)
{
if(consume)
if(pb)
{
std::cout << _T("\nDeleting B by processB()");
delete pb;
}
return consume;
}
void test_selector()
{
bool consumed;
B *pb1 = new B();
consumed = processB(pb1, true); // delete by processB
DECLARE_PTR_AUTO_DELETOR_CONDITIONAL(B, pb1, (! consumed));
B *pb2 = new B();
consumed = processB(pb2, false); // you do the job!
DECLARE_PTR_AUTO_DELETOR_CONDITIONAL(B, pb2, (! consumed));
}
int main()
{
test_selector();
return 0;
}
Thanks for any help.
B/Rgds
Max
-------------------------------------------------------------------
Ð À˿ռ䡪¡ªÓëÅóÓÑ¿ªÐÄ·ÖÏíÍø çÐ Éú»î£¡(http://space.sina.com.cn/ )
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic