[std-interval] passing by value vs reference

Sylvain Pion Sylvain.Pion at sophia.inria.fr
Wed Apr 5 12:32:52 PDT 2006


[ Let me create separate threads of discussion on each point. ]


Summary of the arguments on this issue:

1- pass by value can be faster or slower than pass by reference
    depending on the processor/ABI.
2- pass by value can be faster due to removal of aliasing issues.
3- pass by value is safer in general as a programming idiom
    (an example is operator*= which may need tweaking to protect
     itself multipliying by *this)
4- pass by reference is consistent with std::complex
5- having it specified is useful when taking addresses of functions.


Possible solutions, assuming we want a uniform treatment for all
functions on intervals:

1- enforce pass-by-value
2- enforce pass-by-ref
3- leave freedom for the implementation to choose
4- leave freedom for the implementation and have it provide
    a standard specified way to obtain this information.


Now, I assume that users want the best performance on all
compilers/processors, so I don't like 1 nor 2.
I also do not see a large need for manipulating function
pointers for the intervals, I never needed that personnaly
at least (speak up if you think it is an important use case).
If there is indeed no large need for these, and given that it
is always possible (though painful) to write function wrappers
to get function pointers, then I would prefer 3 to 4.  I think
the complexity of implementing 4 is not worth it.  Moreover,
specifying 4- can be proposed later as an addition (e.g. in
the more general context of the whole standard library).


So, as for the proper text in the proposal, let me propose:
- to have the text of the function prototypes use pass-by-value,
   as it fulfills the "advocate safer programming style" argument
   of Lawrence, and it is also shorter.
- a note at the beginning mentionning that the implementation
   is free to use pass-by-reference.


Does this seem reasonnable ?

-- 
Sylvain


More information about the Std-interval mailing list