Boost logo

Boost Users :

Subject: [Boost-users] [lambda] Should the code compile?
From: Max (loadcom_at_[hidden])
Date: 2008-12-30 00:10:50


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<CLASS*>(boost::lambda::if_then_else(_1,\
        VAR_PTR, static_cast<CLASS*>(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/ )


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