|
Boost Users : |
Subject: Re: [Boost-users] [math][tools][units] generic libraries not genericenough
From: Michael Fawcett (michael.fawcett_at_[hidden])
Date: 2011-08-26 14:26:30
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 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