From: Ulrich Eckhardt on 8 Dec 2009 08:53 Andrew wrote: > Subject says it all really. A common baseclass and virtual functions require a certain overhead which is paid for just dereferencing or stepping an iterator. That overhead is unacceptable to the STL philosophy, which had efficiency as a major goal. > I realise that in the upcoming standard the use of auto to declare the > iterator will make it slightly easier. That doesn't change anything, it just saves you some typing. The STL or its descendants in the C++ standard library will remain compile-time polymorphic only. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Pedro Lamarão on 8 Dec 2009 08:53 On 7 dez, 17:52, Andrew <marlow.and...(a)googlemail.com> wrote: > Subject says it all really. I have been in Javaland for a while where > you do have this capability. I am aware of Meyers Effective STL item 2 > ("beware of the illusion of container-independent code") but I don't > think item 2 applies when all you want to do is iterate over a > container. This is the simple case that people want to do most of the > time (IMHO). Of course if you want to do something else like reverse > iterate etc then with C++ you can. But it does seem mysterious to me > why it is more awkward to do a generic iteration for the most common > case. Do you mean you want to use one name for the type of "iterator variable" and use that name with all container types? Like this? -- x -- std::vector<int> v; std::list<double> l; std::set<char> s; general_iterator* i = v.begin(); // etc. i = l.begin(); // etc. i = s.begin(); // etc. -- x -- In C++ an array is a very primitive type whose "iterator" cannot be an instance of general_iterator. Therefore, this scheme would never be truly uniform -- as the current scheme actually is. As you pointed out, the notational inconvenience will go away with the new "auto" syntax. This is just no the C++ way of things. It may sound silly but goes all the way down to compiler optimizers. -- P. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: CornedBee on 8 Dec 2009 08:53 On Dec 7, 8:52 pm, Andrew <marlow.and...(a)googlemail.com> wrote: > Subject says it all really. I have been in Javaland for a while where > you do have this capability. The runtime polymorphism of Java is often not available in C++ in favor of static polymorphism using generic programming. for_each can iterate over any container. Sebastian -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Kirill_Lykov on 8 Dec 2009 08:52 STL - is a template library. Template is an implementation of static polymorphism. It makes it possible to use containers in common way in different algorithms and so on but in another way than using dynamics polymorphism. I believe you should read more about difference in these two kinds of polymorphism. In Java there is no static polymorphism at all(generics is just a syntactical sugar) that's why dynamic polymorphism is used. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Kenneth 'Bessarion' Boyd on 8 Dec 2009 08:51 On Dec 7, 1:52 pm, Andrew <marlow.and...(a)googlemail.com> wrote: > Subject says it all really. I have been in Javaland for a while where > you do have this capability. Well, C++ does have generic iteration, it just uses the tools available (template functions and #include <algorithm>) to generically iterate with any iterator (as defined by the standards), even raw pointers. Raw pointers are bad news for generically iterating by deriving from the One True Abstract Base Class Iterator of the One True Abstract Base Class. * In C++, iterators are generalizations of raw C-style pointers. So generic iteration has to generically iterate raw C-style pointers. * raw C-style pointers can't inherit from anything, by definition. In particular, they can't inherit from the One True Abstract Base Class Iterator. As Java does not have raw pointers by design, it has more flexibility in how to provide generic iteration. Someone who actually knows the history could review what other options were rejected for C++. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Next
|
Last
Pages: 1 2 Prev: C++ library that offers tensors? Next: Dependent function templates and overloaded functions |