[std-interval] C++ interval std

Gabriel Dos Reis gdr at integrable-solutions.net
Thu Apr 6 00:26:51 PDT 2006


Alan Eliasen <eliasen at mindspring.com> writes:

| Steve Clamage wrote:
| 
| 
| >> Bill Clarke wrote:
| >>
| >>> This experiment is extremely platform specific, as you probably are
| >>> aware.  Most platforms in use today other than x86 will be the other way
| >>> around (add-by-value will be faster than add-by-const-ref).
| 
| Alan Eliasen wrote:
| >>    How can that assertion possibly be made?  As you know, if a parameter
| >> is passed by value, then the copy constructor is automatically called
| >> for each object (e.g. twice for an add operator) on function entry, and
| >> then the destructor is called (twice) on function exit.
| > 
| 
| Steve Clamage wrote:
| > A simple object like complex or interval should have no user-defined
| > copy constructor or destructor. That is, the default copy constructor
| > generated by the compiler does the right thing and does not need to be
| > user-defined. The destructor has nothing to do, and so should not be
| > user-defined. In that case, pass-by-value can be optimized into register
| > passing with no additional copying.
| 
|    You still agree, though, that even if the implementation doesn't do
| memory allocation in the constructor, the compiler will still generate a
| copy constructor and a destructor, (perhaps pretty simple and efficient)
| and these will get normally get called in a pass-by-value.  Again, a
| very smart compiler can optimize these away if it realizes that the copy
| is unnecessary, but by simply specifying call-by-constant-reference, we
| don't have to hope that the compiler is very smart.  We simply eliminate
| even the possibility of calling the copy constructor and destructor.

Steve and Lawrence have been working on C++ and C++ compilers, long
long before I even knew the language existed -- let alone, started
working on C++ libraries and compilers.  Their inputs in that area
should not be taken lightly.
I know of no existing production C++ compilers that run trivial
destructors, or that do not implement trivial copy-constructor
appropriately (given ABI requirements) at usual optimization level.
If you find one, I would encourage you to report it to your vendor.
TC++PL3 has guidance, I believe, on exactly this point.  

You're right that we don't have to hope the compiler is very smart:
The compilers are already doing it; so that is a non-issue.

When you make your proposal to the committee, do expect that 
making pass-by-const-ref where it should have been pass-by-value (as
suggested by Lawrence and Steve) be a contentious point to resolve.

-- Gaby


More information about the Std-interval mailing list