distance_type vs. size_type for iterator

C

cablepuff

Alright, I am sort of confused on c++ iterators having both
distance_type and size_type.

On sgi and Microsoft compiler it uses distance_type for input
iterator. For mingw and cygwin it uses size_type , is it just standard
issues or is it platform dependent.
 
V

Victor Bazarov

Alright, I am sort of confused on c++ iterators having both
distance_type and size_type.

On sgi and Microsoft compiler it uses distance_type for input
iterator. For mingw and cygwin it uses size_type , is it just standard
issues or is it platform dependent.

The Standard does not require that type 'size_type' is defined for
an iterator (through its traits), it requires 'difference_type',
however (along with 'value_type' and 'iterator_category').

Mingw or cygwin never appeared to me to be especially standard
compliant, they seem to usually contain the compiler or the
library that is simply too old. Just an impression I get.

V
 
J

James Kanze

The Standard does not require that type 'size_type' is defined for
an iterator (through its traits), it requires 'difference_type',
however (along with 'value_type' and 'iterator_category').

Mingw or cygwin never appeared to me to be especially standard
compliant, they seem to usually contain the compiler or the
library that is simply too old. Just an impression I get.

V
 
J

James Kanze

The Standard does not require that type 'size_type' is defined for
an iterator (through its traits), it requires 'difference_type',
however (along with 'value_type' and 'iterator_category').
Mingw or cygwin never appeared to me to be especially standard
compliant, they seem to usually contain the compiler or the
library that is simply too old. Just an impression I get.

I don't know. Before I'd comment, I'd want to know what he
means by "uses size_type for input iterator". The version of
CygWin I have installed here (which isn't the very latest---I
don't use it often enough to bother keeping it up to date) have
g++ 3.3.3, and in std::iterator, it defines difference_type, and
not size_type. The class std::input_iterator_tag doesn't define
any types (which is normal), and there's no other "input
iterator" class that I can think of to which he might be
referring.

And of course, difference_type doesn't have any real meaning for
input and output iterators. You can't obtain a difference at
all for output iterators, and the only way to obtain one for an
input iterator is by incrementing a copy, after which, the
original iterator isn't usable, or doesn't point to where it
originally did.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top