473,382 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

STL map question

Hello all,

First of all I am aware of the fact that my question is STL related.
However the comp.std.c++ group is moderated and I have no idea how long
it will take to be answered there. So, please, hold your fire.

And now the question:

Is there any special reason (performance, etc.) for using "(*i).second"
instead of "i->second"?

The example follows:

typedef std::map<...> table;

extern table t;
table::iterator i;
for (i=t.begin(); i!=t.end(); i++)
{
param = (*i).second;
...
}

Thanks.

Jul 23 '05 #1
13 1268
"brian" <br***********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
First of all I am aware of the fact that my question is STL related.
However the comp.std.c++ group is moderated and I have no idea how long
it will take to be answered there. So, please, hold your fire. All C++ questions are welcome here, no fire to be expected.
Is there any special reason (performance, etc.) for using "(*i).second"
instead of "i->second"?

No, most certainly not.
6-7 years ago, some were saying that (*i). may be more portable
that i-> , because of the inconsistency of some library
implementations - but this is history.
I see no rationale today for preferring (*i). over i->
hth-Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Jul 23 '05 #2
brian wrote:
Hello all,

First of all I am aware of the fact that my question is STL related.
However the comp.std.c++ group is moderated and I have no idea how
long it will take to be answered there. So, please, hold your fire.

And now the question:

Is there any special reason (performance, etc.) for using
"(*i).second" instead of "i->second"?
No, just personal preference.

The example follows:

typedef std::map<...> table;

extern table t;
table::iterator i;
for (i=t.begin(); i!=t.end(); i++)


But there is a performance hit here using post increment. Use ++i instead
whenever possible.

Jeff Flinn
Jul 23 '05 #3
On Fri, 18 Feb 2005 13:18:24 +0100, Ivan Vecerina
<NO**********************************@vecerina.com > wrote:
"brian" <br***********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
First of all I am aware of the fact that my question is STL related.
However the comp.std.c++ group is moderated and I have no idea how long
it will take to be answered there. So, please, hold your fire.

All C++ questions are welcome here, no fire to be expected.
Is there any special reason (performance, etc.) for using "(*i).second"
instead of "i->second"?

No, most certainly not.
6-7 years ago, some were saying that (*i). may be more portable
that i-> , because of the inconsistency of some library
implementations - but this is history.
I see no rationale today for preferring (*i). over i->


Ah, thanks, I too remembered hearing about it but not why, I've used the
-> form in all of my C++ code for many years with no problems.

Chris C
Jul 23 '05 #4
But there is a performance hit here using post increment. Use ++i instead
whenever possible.


I use pre increment when I want to make clear that post increment is not
what I need. And I don't think that the compiler will make any
diffderence in Release mode if I don't use the result.

Ingo
Jul 23 '05 #5
>> Is there any special reason (performance, etc.) for using
"(*i).second"
instead of "i->second"?

No, most certainly not.
6-7 years ago, some were saying that (*i). may be more portable
that i-> , because of the inconsistency of some library
implementations - but this is history.
I see no rationale today for preferring (*i). over i->

Thank you.

Jul 23 '05 #6
>> Is there any special reason (performance, etc.) for using
"(*i).second" instead of "i->second"? No, just personal preference.

Thank you.
The example follows:

typedef std::map<...> table;

extern table t;
table::iterator i;
for (i=t.begin(); i!=t.end(); i++)


But there is a performance hit here using post increment. Use ++i

instead whenever possible. Isn't this a history?

Jeff Flinn


Jul 23 '05 #7
"brian" <br***********@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
for (i=t.begin(); i!=t.end(); i++)


But there is a performance hit here using post increment. Use ++i

instead
whenever possible.

Isn't this a history?


No, this remains an issue by design: the post-increment operator
has to create and return a new instance of the iterator.
It is typically implemented in terms of the pre-increment:
{ MyIteratorType result(*this); ++this; return result; }

For some types of iterators, the cost of creating this new
instance (result) can be canceled after inlining, but this
is often not the case.
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form

Jul 23 '05 #8
"Ivan Vecerina" <NO**********************************@vecerina.com > wrote in
message news:cv**********@news.hispeed.ch...
{ MyIteratorType result(*this); ++this; return result; }

Of course this was actually: ++(*this)

Jul 23 '05 #9
Well, and what about basic types like "int"?

int i;

Is there any difference (performance) between:

i++;

and

++i;

Thanks.

Jul 23 '05 #10
brian wrote:
Well, and what about basic types like "int"?

int i;

Is there any difference (performance) between:

i++;

and

++i;


Most compilers will optimize the temporary away for simple built-in types.
But why not be explicit in your coding? If you're not using the previous
value, don't refer to it in the first place.

Jeff Flinn
Jul 23 '05 #11
> Most compilers will optimize the temporary away for simple built-in
types.
But why not be explicit in your coding? If you're not using the previous value, don't refer to it in the first place.


So, in other words it is still preferred using ++i instead of i++.
Example:
for (int i=0; i<10; ++i)
{
}
Correct?

Jul 23 '05 #12
brian wrote:
Most compilers will optimize the temporary away for simple built-in
types. But why not be explicit in your coding? If you're not using
the previous value, don't refer to it in the first place.


So, in other words it is still preferred using ++i instead of i++.
Example:
for (int i=0; i<10; ++i)
{
}
Correct?


Correct.

Jeff Flinn
Jul 23 '05 #13
>>> Most compilers will optimize the temporary away for simple built-in
types. But why not be explicit in your coding? If you're not using
the previous value, don't refer to it in the first place.

So, in other words it is still preferred using ++i instead of i++.
Example:
for (int i=0; i<10; ++i)
{
}
Correct?


Correct.

Thank you very much.

Jul 23 '05 #14

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

Similar topics

1
by: Mohammed Mazid | last post by:
Can anyone please help me on how to move to the next and previous question? Here is a snippet of my code: Private Sub cmdNext_Click() End Sub Private Sub cmdPrevious_Click() showrecord
3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
3
by: Zhang Weiwu | last post by:
Hello! I wrote this: ..required-question p:after { content: "*"; } Corresponding HTML: <div class="required-question"><p>Question Text</p><input /></div> <div...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.