This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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]

C++ -- a valid idea?


Dear GCC people,

I'm a very happy user of g++ and gcc! I like this compiler very much.

Now, the other day I thought of something which is (to my point of view) a 
problem in C++. Many people are used to the post increment operator which, 
as you certainly know needs to create a copy of this before to computer 
the increment and returns the result being that copy (which in many cases 
ends up being yet another copy).

Code which use an int will go very fast:

   for(int i = 0; i < max; i++) ...

If you transform the variable i with an iterator from the standard 
library:

   for(interator it = v.begin(); it < max; it++) ...

The it++ expression is in many cases slow.

A solution to this problem (it seems to me) is to determine that the 
result of the expression it++ isn't used (void) and thus, ++it could be 
called instead. Since both functions could do something quite different, 
you can't change them on the user without him saying whether it is okay or 
not. Thus a new attribute would tell the compiler that it is fine and the 
change can occur as the compiler sees fit.

   class iterator {
      ...
      operator ++ () __atribute__ ((share_pre_and_post_increment));
      operator ++ (int) __atribute__ ((share_pre_and_post_increment));
      ...
   };

Note that since this change would be taken in consideration only in 
declarations, recompiling all of your code would (possibly) make it faster 
at once without much work.

Thank you for reading this email in its entirety! 8-)

Best regards,

-- 

Alexis Wilke
Director
Made to Order Software, Corporation
Made to Order Software, Limited

e-mail:		alexis@m2osw.com
cell-text:	alexis.cell@m2osw.com (please, only small messages)

Web Page:	http://www.m2osw.com
Company e-mail:	contact@m2osw.com
Phone 1:	+(1) 916 220 6482
Phone 2:	+(1) 916 988 1450

Address 1:	9275 Blue Oak Drive
		Orangevale, California 95662
		United States of America

Address 2:	2nd Floor, Hammersmith Broadway
		Hammersmith
		London W6 7BB
		United Kingdom


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