开发者

Help me understand why find returns something different than end() on std::set when set is empty

why is the if-case true?!

 typedef std::set< boost::shared_ptr<CCall>, HasFirstQueuedLongerTime> queued_container;
    queued_container::iterator itTemp = queued.find(spCall);
    queued_container::iterator itTempEnd = queued.end();
    if(itTemp != itTempEnd ) //<-- is true

queued is an empty std::set and spCall is a shared pointer to an object. Since queuedis empty the find function should return the iterator equal to queued.end()...

Im compiling and debugging on vs2005. I can see that itTemp and itTempEnd points to same address.

Thankful for all answers!

More code info, the following is declared before if-statement:

queued_container queuedCalls;
const boost::shared_ptr<CCall> &spCall; //spCall is valid according to debug info.


struct HasFirstQueuedLongerTime : std::binary_function < boost::shared_ptr<CCall>, boost::shared_ptr<CCall>, bool> {
        bool operator() (const boost::shared_ptr<CCall>& lhs, const boost::shared_ptr<CCall>& rhs) const
        {
            return lhs->CreatedTime() < rhs->CreatedTime(); //returns true if lhs queued longer time than rhs
      开发者_StackOverflow社区  }
    };

My real executable code:

queued_container::iterator itTemp = queued.find(spCall);
queued_container::iterator itTempEnd = queued.end();

if(itTemp != itTempEnd )
    AS_ERROR(1, "XXX", "ERROR: Already added to queue container.");
queued.insert(spCall);
CCallQueue::insert(spCall);

Ps. Sorry for many edits..


Problem solved!

itTemp != itTempEnd

was never true! The function below AS_ERROR was a "#define-function" with multiple statements. So the first statement was never executed but the second was.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜