
AMDG On 12/03/2012 06:07 AM, "Claas H. Köhler" wrote:
Consider e.g. a simple template of the form
template<class IT> struct Range { IT first, last;
Range(void)= default;
size_t size(void) const {return last - first;} };
I do not know of any iterator for which Range<II> r; std::size_t size = r.size(); is legal.
The behaviour of size() is currently undefined for default constructed Range objects, which is a major disadvantage in my opinion, since any reproducible default value will result in the expected behaviour of size zero for a default constructed Range object. This is what all other iterator implementations guarantee, too, if I am not mistaken (Please correct me if I am wrong here).
Most iterators do not make this guarantee: std::vector/list/string/deque/map/set<T>::iterator - default constructed iterators may be singular. value initialization may not make any difference. T* - default constructed iterator is uninitialized std::istream_iterator - okay, end std::istreambuf_iterator - okay, end In Christ, Steven Watanabe