This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: vector<T>::iterator


Thomas Kunert <kunert@physik.tu-dresden.de> writes:

| Gabriel Dos Reis wrote:
| 
| >From my point of view, the problem is in the compiler not in the
| > library.  The above example is not the kind of argument that will
| > change my take on this.  We have better gains by improving the
| > compiler,
| 
| Sure. But complaining about the compiler does not help, at
| least in the short term.

On the contrary it does.  It was after complaining that we got ADDRESSOF.
Of course, there are many ways to complain.
The compiler needs to handle pattern usage of the language correctly.  
std::vector<T>::iterator is just an examplar.  We gain much more benefit
by improving the compiler in that area than giving away type safety.

| > Once you start removing that simple structure, you would also have to
| > remove object functions and any other bonus for the same reason.
| > That is a wrong-headed road.
| 
| That conclusion seems wrong. Why would you have to remove
| function objects?

Because they are structs containing as small data as std::vector<T>::iterator

| They are useful because they allow simpler code.

std::vector<T>::iterator is useful because it brings more annotation,
better type safety.

| Iterator classes do not alleviate anything but originate from
| the idea that the compiler must control and limit the programmer.

No.  Iterator are abstractions and we use classes to annotate the data
we intend to use as such.  That annotation helps distinguishin between
data and catching errors very early in the process.  Those annotation
are compile-time notions and should be removed by the compiler once it
does its checking job. 

| And that is a very bad notion.

No, it is a useful notion.  Only a compiler that systematically put
off optimization when it sees a type that can turn it into a bad
notion.  But the notion itself is good.

| Just trust the programmer. In most cases he is right.

Yes, and a T* is not a std::vector<T>::iterator.  For the compiler to
trust the programmer, the programmer needs to help, and type
annotation is the primary mean.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]