|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-05-24 10:58:43
"Kobi Cohen-Arazi" <kobi.cohenarazi_at_[hidden]> writes:
> Hi,
>
> I've started reading Abrahams' and Gurtovoy's book, since I'm very
> interested in boost.mpl. Seems like a great book. I have a question
> regarding the 3rd chapter (3.1.4 section).
> Eventually, it says that operator* multiplies the runtime values
> (resulting in 6.0f) and the code uses transform to sum the meta-seq.
>
> template <class T, class D1, class D2>
> quantity<T, typename mpl::transform<D1,D2, plus_f>::type>
> operator*(quantity<T,D1> x, quantity<T,D2> y)
> {
> typedef mpl::transform<D1,D2, plus_f>::type dim;
> return quantity<T,dim>(x.value() * y.value());
> }
>
> 1. Why passing x and y by value? why not const&
a. It adds extra tokens that distract from the point of the example.
b. T is probably float or double, which is usually fine to pass by
value, and thus quantity<T,...> probably has the same size and is
also fine to pass by value
> 2. How did we got 6f ?
It's an erratum:
http://boost-consulting.com/mplbook/errata.html#metafunctions-title
> 3. How and when the mpl::transform is getting into action here? I
> cannot spot it.
It gets into action at compile-time, when the operator is
instantiated. The compiler has to figure out what type the function
returns, and to do so, it instantiates the transform template to
discover what its nested ::type is.
HTH,
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net