Boost logo

Boost Users :

Subject: [Boost-users] [lambda] Should the code compile?
From: Max (loadcom_at_[hidden])
Date: 2008-12-30 07:49:19


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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net