Daniel Krügler wrote:
Jonathan Turkanis wrote:
Daniel Krügler wrote:
2) The function template
template <typename IntType> IntType lcm(IntType n, IntType m);
should be defined as
template <typename IntType> IntType lcm(IntType n, boost::call_traits<IntType>::param_type m);
which makes sense in this case because m is not modified internally (in contrast to n)
I think lcm should be symmetrical.
1) Wow, not so much of details of reasonings, please ;-))
Because the semantics are symmetrical. The above asymmetry wouldn't be acceptable for max or +, would it? How much performance improvement do you expect, and in what cases?
2) OK, the request of symmetry can lead to several conclusions:
If we argue that the interface should not reflect the implementation, the most reasonable signature would be something like
template <typename IntType> IntType lcm(const IntTyp& n, const IntTyp& m);
(We cannot use the optimal version
template <typename IntType> IntType lcm(boost::call_traits<IntType>::param_type n, boost::call_traits<IntType>::param_type m);
because that would prevent argument deduction)
Otherway around we could argue, that we want to use advantages of a special copy-optimization technique. This is an implementation-driven interface, but there are cases, where proposers (I am not one) have argued that the advantages outweight its disadvantages.
Okay, what are you arguing, then?
If I try to compare these to approaches not too strongly subjectively (its impossible, I know, but I'll try ;-))), than I would say, that an implementation-driven interface should be only used where necessary, but not otherwise. This lead to my proposal to use call-by-value only for the first, not for the second argument of lcm.
I don't understand, **why** you think, that the interface must/should be symmetric:
1) Thinking not implementation-driven, than
template <typename IntType> IntType lcm(const IntTyp& n, const IntTyp& m);
would be right thing for general IntTypes (see std::max/min interface). I would agree to that proposal
Are you saying this is always better than pass by value, or just sometimes?
2) Thinking implementation-driven, than
template <typename IntType> IntType lcm(IntType n, boost::call_traits<IntType>::param_type m);
must be acceptable and **even more reasonable** than the currently existing
template <typename IntType> IntType lcm(IntType n, boost::call_traits<IntType>::param_type m);
interface.
They look the same to me.
Greetings,
Daniel
Jonathan