473,508 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Const iterators

Hi,

someone told me that STL const_iterators are faster than non-const
iterators. Is this really true? And if so, why?

I though that const_iterators should be used when possible in
order to avoid side effects (no accidental writes). But I never heard
of a speed-up.

Regards,
Chris
Aug 12 '06 #1
2 1411
Christian Chrismann wrote:
Hi,

someone told me that STL const_iterators are faster than non-const
iterators. Is this really true? And if so, why?

I though that const_iterators should be used when possible in
order to avoid side effects (no accidental writes). But I never heard
of a speed-up.

Regards,
Chris
for a good answer:

http://www.gotw.ca/gotw/081.htm

very nice writing :)

Pierre
Aug 12 '06 #2
Christian Chrismann wrote:
Hi,

someone told me that STL const_iterators are faster than non-const
iterators. Is this really true? And if so, why?

I though that const_iterators should be used when possible in
order to avoid side effects (no accidental writes). But I never heard
of a speed-up.

Regards,
Chris
I forgot ... the short answer is "no, it is not quicker to run", the
long answer is in the article.

Pierre
Aug 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5047
by: Bolin | last post by:
Hi all, A question about smart pointers of constant objects. The problem is to convert from Ptr<T> to Ptr<const T>. I have look up and seen some answers to this question, but I guess I am too...
26
1514
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class...
4
1793
by: NKOBAYE027 | last post by:
Hi Everyone: Short description first MathematicalSet is to be a class template that's supposed to behave as the name suggests. It has functions that define union, contains, is_contained_in,...
5
11431
by: James Gregory | last post by:
#include <cstdlib> #include <cctype> #include <string> template <class Input_Iter> inline int IterToInt(Input_Iter& iter, const Input_Iter& lineEnd) { char tempArray = {0}; for (int i = 0;...
3
2460
by: Old Wolf | last post by:
Hi all. G++ fails to compile the following: #include <string> int main() { std::string foo("abc=123"); std::string::const_iterator delimiter = std::find(foo.begin(), foo.end(), '=');
1
1111
by: vsgdp | last post by:
Hi, Is the reason for supplying both const and non-const iterators so that you can still traverse a const container for reading. The compiler knows to call the const version if the object is...
2
1998
by: Lorenzo Castelli | last post by:
This is an old problem of mine. Basically I have an abstract base class which represents a generic iterator over a collection of elements, and various derived classes that implement the...
4
2701
by: kotau | last post by:
Hi, I'm having trouble with something that would appear to have a simple solution. Here's a version of the code I'm working with: const Item* p 0; name::const_iterator i;
9
1840
by: miaohua1982 | last post by:
the program is as follows: #include <vector> using namespace std; class A{}; int main() { A* const &p = NULL; vector<A*B(3,NULL); //there is a compile error B.push_back(NULL);
0
1916
by: wellingj | last post by:
A little back ground on what I'm trying to do: I'm making a generic weighted graph class (vertexes and edges althought I don't call them that) to implement some pathfinding algorithms like A* and D*....
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.