|
Boost : |
From: Steven Watanabe (steven_at_[hidden])
Date: 2007-03-28 11:58:09
AMDG
Michael Fawcett <michael.fawcett <at> gmail.com> writes:
> <snip>
>
> > No more switch statement smell.
>
> I agree on the smell...Thankfully it's very contained when using the
> compile-time version. It seems like with a run-time component that
> was interoperable with the compile-time one, you could have zero
> run-time overhead during computations as well as get rid of all switch
> statements at the boundaries (reading/writing from database or GUI).
> Something like:
>
> quantity<SI::length> on_dialog_ok()
> {
> quantity<abstract> dist;
> dist.set_unit(combo.selected_item().data());
> dist.set_value(entry.value().as_double());
> return quantity<SI::length>(dist);
> }
>
Here is how I would do it:
quantity<SI::length> on_dialog_ok()
{
double conversion = combo.selected_item().data();
double value = entry.value().as_double();
return quantity<SI::length>::from_value(conversion * value);
}
Absolutely minimum overhead.
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk