Examine the following code:
This works:
T *p = (std::find( this->first(), this->last(), *pPos ));
if( p != last() )
{
this->push_back(data);
T *right = (this->last() - 1);
T *left = (this->last() - 2);
while( *pPos != data )
std::iter_swap( left--, right-- );
return const_cast<T*>(pPos);
}
This does not:
boost::scoped_ptr<T> p(std::find( this->first(), this->last(), *pPos ));
if( p.get() != last() )
{
this->push_back(data);
T *right = (this->last() - 1);
T *left = (this->last() - 2);
while( *pPos != data )
std::iter_swap( left--, right-- );
return const_cast<T*>(pPos);
}
The second version gives a runtime error of
Expression: _BLOCK_TYPE_IS_VALID_(pHead->nBlockUse)
meaning that my scoped_ptr went out of scope either too soon or is doing some funky things that invalidate it.
What am I doing wrong with the scoped_ptr?
Addendum:
I can't delete any of the pointers. Is this normal? Even if I delete right/left, I get the same error even though they aren't being referenced anymore at the return.