While debugging something, I saw the STL vector::empty() implementation:
bool empty() const
{return (size() == 0); }
I believe, whenever we are probing the emptiness of vector it is always recommended to use empty over size(). But seeing that implementation, I am wondering, what is the benefit of doing so? Instead, there is a function call overhead in calling empty as it internally calls size()==0.
I thought empty() may be helpful in case of list as size() doesn't guarantees the constant time in list. To verify my assumption, I checked the list implementation and surprisingly, found the same implementation in list as well,
return (size() == 0);
I am bit confused now. If empty internally uses size() then why should we prefer empty over size() ?