|
Boost : |
From: John Maddock (John_Maddock_at_[hidden])
Date: 2000-07-20 06:49:53
Dave,
Thanks again,
>This is better, but you still need a period or semicolon after "array
itself", rather than a comma.
Just noticed something else in your 1st table:
"Defines a type that represents a reference to type T. Use for methods that
would normally return a T&."
Should say "functions", not "methods".
<
Yep.
>I'm trying to get you to clarify your language.
I know, I'm just not succeeding :-)
>Does the example have
>anything to do with std::pair? If so, what? If not, please strike the
>reference.
OK, no it's just a trivial example, based on Howard's original test model,
I'll make it clear that it is just a trivial example.
>Is a pointer a compound type or a fundamental type? This should cover
>pointers, shouldn't it?
No a pointer is a compound type, as are references, arrays cv-qualified
types etc.
>Sorry, I still don't like it. They don't implement the proposal. They
>provide a (tedious) workaround for the same problems that the proposed
>language change would solve.
OK, how about "call_traits<T>::value_type and call_traits<T>::param_type
both provide the same effect as that proposal, without the need for a
language change (in other words it's a workaround)."
>I thought of two things:
>1. The optimization I propose is not strictly equivalent: someone might
take
>the address of the parameter
>2. another optimization in the same category. Can we do this with call
>traits?
>
>// use this implementation by default
>template <class X>
>const X& max(const X& x, const X& y) { return y < x ? x : y; }
>// but this one for fundamental types
>template <class X>
>X max(X x, X y) { return y < x ? x : y; }
You;re right about (1): lets forget it.
With respect to (2), I don't think that you will gain anything with the
"optimised" version, implementation would have to be something like:
template <class X>
inline typename call_traits<X>::param_type do_max(typename
call_traits<X>::param_type i, typename call_traits<X>::param_type j)
{ return i > j ? i : j; }
template <class X>
inline typename call_traits<X>::param_type max(const X& i, const X& j)
{ return do_max(i, j); }
Unless you can show that there is some situation where this makes a
difference, then it's not worthwhile, the typical situation where
call_traits does make an optimisation, occurs when the function is not
inline, and contains a loop which uses the call_traits optimised value.
Primarily I think this is an alias issue, by passing by value where
appropriate, the function isn't passed an alias which may or may not mess
up compiler optimisations. In the case of min and max I don't think that
there are any alias issues?
>You need an example right here. Say, "T is of type <...>, but X is of type
><...>" (or something). Show a potential problem being caused.
>
>> By using call_traits the degradation from array to pointer is
>> explicit, and the type of the paramter is the same as it's declared
type.
>
>Put another example here, which shows the problem being addressed.
>
Yep.
- John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk