Boost logo

Boost Users :

Subject: Re: [Boost-users] [math][tools][units] generic libraries not genericenough
From: Michael Powell (mwpowellnm_at_[hidden])
Date: 2011-08-26 14:36:49


Okay that helps, yes. However, I thought this was necessarily the whole
point motivating b::u, or any units library for that matter. However, when I
stop to consider the whole point of b::u compile-time-type-safety, doesn't
it stand to reason that some units can't necessarily find a root? Like I
wouldn't want to root a m^3, this doesn't make sense to do so; even if I
could, what would the unit outcome be? Although I expect I should be able to
root a m^2. These are simple examples of course.

On Fri, Aug 26, 2011 at 12:26 PM, Michael Fawcett <michael.fawcett_at_[hidden]
> wrote:

> On Fri, Aug 26, 2011 at 2:14 PM, Michael Powell <mwpowellnm_at_[hidden]>
> wrote:
> > Okay, I'm not positive I fully understood the first question in the whole
> > series of emails, only so far as to respond with our experience with
> > boost::units so far. Now, I'm really very extremely positive I don't know
> > the tangent we're on. Perhaps someone with more history and experience
> with
> > boost::units could give us a run-down what the premise behind b::u is,
> maybe
> > a short primer, examples, what have you, just besides the user docs.
> which
> > are fine, don't get me wrong, but might help to explain some
> misconceptions
> > about what b::u is all about. Because I for one thought I knew, or at
> least
> > still have a grasp of an idea, but wouldn't hurt for the newcomers.
> > Thanks...
>
> [Please don't top post]
>
> The basic gist of the discussion is that many generic libraries don't
> fully support Boost.Units because they don't support mixed type
> arithmetic correctly (or aren't generic enough, however people want to
> say it). Consider a very simple example of a hypothetical math
> library function "add" that purports to handle user defined types
> (some sort of BigInt is a popular example):
>
> template <typename N>
> N add(N lhs, N rhs)
> {
> return lhs + rhs;
> }
>
> Functions like this often break with Boost.Units because the result
> type might not necessarily be the same as the argument types (N in
> this case). Not only that, it doesn't allow adding two distinct types
> together.
>
> To define the function such that it would work with BigInt and
> Boost.Units, it would have to be something like:
>
> template <typename LHS, typename RHS>
> BOOST_TYPEOF_TPL(LHS() + RHS())
> add(LHS lhs, RHS rhs)
> {
> return lhs + rhs;
> }
>
> Hopefully that helps answer your question,
>
> --Michael Fawcett
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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