ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
Re: [boost] Postfix Increment Operator
by Brad King other posts by this author
Jun 11 2002 3:14PM messages near this date
Re: [boost] Postfix Increment Operator | [boost] Postfix Increment Operator
>  When testing this and the prev. version with gcc, I get a 2:3
>  perfomance difference in favour of the traditional solution.
>  
>  Gcc 3.1 -O3
>  ./postincr
>  Number1: 6650000
>  Number2: 9900000

Compilers are good at optimizing integer operations, so I'm not surprised.  
There may be an improvement, however, when copy construction is more
expensive than an integer assignment.

There are other advantages than just performance, though.  Doug Gregor
pointed out to me that if this occurs:

  const number operator++(int) {
    number temp(*this);
    ++(*this);
    return temp; // exception thrown on second copy construction
  }

The original value will not be "unincremented", so only the basic
exception guarantee is satisfied.  However, with this implementation:

  const number operator++(int) {
    return number(*this, postfix_increment());
  }

the original value is not incremented until after the construction
finishes.  With the return value optimization present, this satisfies the
strong exception guarantee.

-Brad

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Powell, Gary
=?iso-8859-1?Q?Terje_Sletteb=F8?=
Daniel Frey
Daniel Frey
David Abrahams
Richard Peters
David Abrahams
Lars Gullik =?iso-8859-1?q?Bj=F8nnes?=
Brad King
Brad King

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved