Menu

version 0.0.1

This is a first alpha release. Very unfinished. No documentation. See tests/ to view use patterns. Basically it goes something like so:

#include <unitlib/unit.hpp>
#include <unitlib/unit_quantity.hpp>
#include <unitlib/basic_quantity.hpp>
#include <unitlib/dimensions.hpp>
#include <unitlib/metafunc/is_quantity_operand.hpp>
#include <iostream>

int main()
{
using namespace unitlib;
using dimensions::length;
std::cout << metafunc::is_quantity_operand<basic_quantity<length> >::type::value << std::endl;
std::cout << metafunc::is_quantity_operand<int>type::value << std::endl;

unit<length> centimeters(.01); // conversion for meters
unit<length> meters(1);
unit_quantity<length> a_meter = 100 * centimeters;
basic_quantity<length> t1 = a_meter; // t1.base_value() == 1

unit_quanity<length> t2 = 10 * meters;

a_meter = (a_meter * t2) / a_meter + a_meter;

// a_meter.value() == 1100
// a_meter.basic_value() == 11
}

The intended use is that basic_quantity is the type used by equations and functions doing calculations so as little unit conversion is done at runtime. To facilitate writing equations in units given by domain documentation you can do something like so:

basic_quantity<length> f(basic_quantity<length> in)
{
static basic_quantity<length> const standard_len = 50 * some_unit;
return in + standard_length;
} // so of course the unit conversion for standard_length is only done once per lifetime of the program.

Posted by Noah Roberts 2007-01-25

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.