|
Boost : |
From: Michael Fawcett (michael.fawcett_at_[hidden])
Date: 2007-02-13 12:05:08
On 2/13/07, Noah Roberts <roberts.noah_at_[hidden]> wrote:
> Janek Kozicki wrote:
> > Matthias Schabel said: (by the date of Tue, 13 Feb 2007 00:20:09 -0700)
> >
> >> quantity<SI::length> getInput(const unit_enum& input_unit,double val)
> >> {
> >> typedef quantity<SI::length> return_type;
> >>
> >> switch (input_unit)
> >> {
> >> case FEET : return return_type(val*imperial::feet);
> >> case LEAGUES : return return_type(val*nautical::leagues);
> >> case METERS :
> >> default : return return_type(val*SI::meters);
> >> };
> >> }
> >
> > I like this approach.
> >
>
> I wouldn't recommend it. It doesn't scale too well.
I too like the approach. I'm curious how it doesn't scale well. With
the existence of some runtime support (for which I agree with others,
should not be in this iteration of the library) and the programmer's
acceptance that it would incur overhead, how would you implement that
function? Wouldn't you still need the switch?
// Note the change to abstract::length
quantity<abstract::length> getInput(const unit_enum& input_unit,double val)
{
typedef quantity<abstract::length> return_type;
switch (input_unit)
{
case FEET : return return_type(val*imperial::feet);
case LEAGUES : return return_type(val*nautical::leagues);
case METERS :
default : return return_type(val*SI::meters);
};
}
I think everyone is trying really hard to see your point of view,
Noah. All of the questions are to gain understanding, not personal
attacks, so please don't take them that way.
--Michael Fawcett
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk