在空向量上調用vector.empty
時,我得到一個EX_BAD_ACCESS
。EX_BAD_ACCESS當調用vector.empty()
bool empty = elements.empty();
它在這裏拋出異常;
/**
* Returns a read-only (constant) iterator that points one past
* the last element in the %vector. Iteration is done in
* ordinary element order.
*/
const_iterator
end() const
{ return const_iterator(this->_M_impl._M_finish); } // EXCEPTION
打電話時;
/**
* Returns true if the %vector is empty. (Thus begin() would
* equal end().)
*/
bool
empty() const
{ return begin() == end(); } // EXCEPTION