Boost logo

Boost :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2006-03-09 08:36:11


I was playing around with Dave's and Aleksey's dimensional analysis example, and
I decided that I couldn't leave well enough alone. To that end, I decided to
reimplement it so that combining units could be written using infix operator
notation. Anyway, the attached file implements it so the following works (on
EDG).

#include "dim.hpp"

#include <iostream>

int main(void) {
    using namespace dim;
    using dim::time; // annoying names from C headers!

    DIM( length / time ) velocity;
    DIM( velocity / time ) acceleration;
    DIM( mass * acceleration ) force;

    quantity<float, DIM(mass)> m = 5.0f;
    quantity<float, DIM(acceleration)> a = 9.8f;

    quantity<float, DIM(force)> f = m * a;

    std::cout << "force = " << f.value() << '\n';
    return 0;
}

I find the syntax like

    DIM( mass * length / (time * time) ) force;

mildly amusing, so I thought I'd share.

Regards,
Paul Mensonides




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk