Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.

Ticket #10267: units.cpp

File units.cpp, 1.2 KB (added by rleigh, 10 years ago)

Units in C++ using Boost.Units

Line 
1#include <iostream>
2
3#include <boost/units/unit.hpp>
4#include <boost/units/quantity.hpp>
5#include <boost/units/systems/si.hpp>
6#include <boost/units/systems/si/prefixes.hpp>
7#include <boost/units/io.hpp>
8#include <boost/units/base_units/metric/angstrom.hpp>
9
10using namespace boost::units;
11using namespace boost::units::si;
12
13typedef quantity<si::length, double> length_type;
14
15typedef make_scaled_unit <si::length,scale<10,static_rational<-3> > >::type millimeter;
16typedef make_scaled_unit <si::length,scale<10,static_rational<-6> > >::type micrometer;
17typedef make_scaled_unit <si::length,scale<10,static_rational<-9> > >::type nanometer;
18
19namespace boost { namespace units
20{
21  typedef metric::angstrom_base_unit::unit_type angstrom_unit;
22  BOOST_UNITS_STATIC_CONSTANT(angstrom, angstrom_unit);
23  }
24}
25
26int
27main (void)
28{
29  length_type x1(24.25 * micro * meter);
30  //  length_type x2(2.0 * mm);
31  quantity<micrometer> x2(24.25 * micro * meter);
32  quantity<nanometer> x3(2.425 * angstrom);
33  length_type x4(x2);
34
35  std::cout << "Length x1 = " << x1 << std::endl;
36  std::cout << "Length x2 = " << x2 << std::endl;
37  std::cout << "Length x3 = " << x3 << std::endl;
38  std::cout << "Length x4 = " << x4 << std::endl;
39
40}

1.3.13-PRO © 2008-2011 Agilo Software all rights reserved (this page was served in: 0.71369 sec.)

We're Hiring!