# Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-04-12 14:13:42

I've been thinking about assuming an approach like this for algebraic
concepts. Typically algebraic concepts depend on more than just the
numeric element type, they also depend on the operations. One way to go
with the algebraic concepts is to require all of the operations to be
supplied as separate functors that get passed around. However, this is
unweildy. Another way to go is to use type wrappers similar to those
described here to artificially encode more information in the numeric
element types.

On Thu, 12 Apr 2001, Dejan Jelovic wrote:

djelov> On September 23, 1999, NASA lost the Mars Climate Orbiter just as it was
djelov> starting to circle the planet. The cause was a failure to convert
djelov> navigational data from the English units used by one group of technicians to
djelov> the metric units used by another.
djelov>
djelov> In order to avoid problems like this in my programs, I've developed a
djelov> template class called arithmetic_type_wrapper. It provides a thin wrapper
djelov> around primitive types like int and double but lets you define different
djelov> types to represent different things.
djelov>
djelov> For example, say you have to do some calculation in meters and feet and want
djelov> to represent different units with different types. The code for something
djelov> like that would be:
djelov>
djelov>
djelov> class meters_tag;
djelov> typedef arithmetic_type_wrapper<double, meters_tag> meters;
djelov>
djelov> class feet_tag;
djelov> typedef arithmetic_type_wrapper<double, feet_tag> feet;
djelov>
djelov>
djelov> meters m = meters (10) + meters (20); //ok
djelov>
djelov> feet f = feet (5) + feet (10); // ok
djelov>
djelov> meters (10) + feet (20); // oops, compile-time error
djelov>
djelov>
djelov> Is there any interest in adding this to Boost?
djelov>
djelov> Dejan
djelov> www.jelovic.com
djelov>
djelov> P.S. I usually demonstrate this with apples and oranges, but then noone
djelov> takes me seriously :).
djelov>
djelov>
djelov>
djelov> To unsubscribe, send email to: <mailto:boost-unsubscribe_at_[hidden]>
djelov>
djelov>
djelov> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
djelov>
djelov>
djelov>

----------------------------------------------------------------------
Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
Ph.D. Candidate email: jsiek_at_[hidden]
Univ. of Notre Dame work phone: (219) 631-3906
----------------------------------------------------------------------