Boost logo

Boost :

From: Janek Kozicki (janek_listy_at_[hidden])
Date: 2006-06-13 18:10:50


David A. Greene said: (by the date of Fri, 09 Jun 2006 21:23:21 -0400)

> Janek Kozicki wrote:
> > Andy Little said: (by the date of Fri, 9 Jun 2006 16:11:14 +0100)
> >
> >
> >>FWIW this syntax is trival in PQS:
> >>
> >> typedef pqs::length::m length;
> >> typedef pqs::time::s time;
> >> typedef pqs::velocity::m_div_s velocity;
> >>
> >> length meter(){return length(1);}
> >> time second(){return time(1);}
> >> velocity x = 10 * meter() / second();
> >>
> >> IOW If you prefer to work this way you can.
> >
> >
> > It's a very interesting idea!
>
> Yes, definitely. I like this solution very much.

Adding those definitions to the headers should make things even simpler
and more user friendly!

With above definitions, and with macro that I have described in another
post (titled "Re: [boost] [review] pqs - defining own units" )

#define BOOST_UNITS_DIVIDED(numerator,denominator,new_type) \
        typedef /*typename */ pqs::meta::binary_operation< \
                 numerator, \
                 pqs::meta::divides, \
                 denominator \
>::type new_type \

I can use this macro, but define a friendlier name:

   BOOST_UNITS_DIVIDED(pqs::force::N,pqs::length::m,spring_stiffness);

And now I can write a valid C++ code that really looks good!

   // in my euqations I use 'kn' to represent spring stiffness
   spring_stiffness kn = 12 * newton() / metr();

The only drawback would be compile time, and nothing more, I really
think that it's worth that.

Given that, maybe there is no need at all to define velocity.hpp,
pressure.hpp and all the others with dimensions combined? When the user
plans to work with velocity he will just write:

   // requires only this macro
   BOOST_UNITS_DIVIDED(pqs::length::m,pqs::time::s,velocity);

instead of this:

   // requires file velocity.hpp with dozens of definitions inside
   typedef pqs::velocity::m_div_s velocity;

And now it's the user who makes a choice whether to use name "velocity"
or name "m_div_s" or name "m_per_s". And all arguments 'div' versus
'per' become obsolete :)

PS: sorry about scattering this single topic into to posts on the mailing list :/

-- 
Janek Kozicki                                                         |

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk