[std-interval] C++ interval std

Guillaume Melquiond guillaume.melquiond at ens-lyon.fr
Wed Apr 5 14:55:35 PDT 2006


Le mercredi 05 avril 2006 à 04:52 -0600, Alan Eliasen a écrit :
> 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).
> 
>    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.  The passed-in
> objects should not be modified in the interim.  So pass-by-value
> *always* has completely unnecessary overhead.  There is absolutely no
> reason to copy and subsequently destroy the objects being passed in.
> Passing by constant reference will *always* be faster in this respect,
> as the copy constructors and destructors will never be called.

Please note that our proposed interval type is meant to be a POD (plain
old data) type and as such has no copy constructor nor destructor. As a
consequence, on some architectures and with non-broken compilers, they
will behave no differently than if the function arguments were simply
integers; except that the register will probably be bigger, or two
registers will be used. When this happens, passing by value will be
faster than passing by const-reference. Indeed there is no architecture
such that foo(int) is slower than bar(int const &).

Best regards,

Guillaume



More information about the Std-interval mailing list