1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
3 //
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2007-2008 Steven Watanabe
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 /**
12 \file
13 
14 \brief non_base_dimension.cpp
15 
16 \details
17 Another example of user-defined units with conversions.
18 
19 Output:
20 @verbatim
21 
22 //[non_base_dimension_output
23 //]
24 
25 @endverbatim
26 **/
27 
28 #include <iostream>
29 
30 #include <boost/units/io.hpp>
31 #include <boost/units/conversion.hpp>
32 #include <boost/units/unit.hpp>
33 #include <boost/units/quantity.hpp>
34 #include <boost/units/physical_dimensions.hpp>
35 #include <boost/units/base_unit.hpp>
36 #include <boost/units/make_system.hpp>
37 
38 namespace boost {
39 
40 namespace units {
41 
42 //[non_base_dimension_snippet_1
43 
44 struct imperial_gallon_tag :
45     base_unit<imperial_gallon_tag, volume_dimension, 1> { };
46 
47 typedef make_system<imperial_gallon_tag>::type imperial;
48 
49 typedef unit<volume_dimension,imperial> imperial_gallon;
50 
51 struct us_gallon_tag : base_unit<us_gallon_tag, volume_dimension, 2> { };
52 
53 typedef make_system<us_gallon_tag>::type us;
54 
55 typedef unit<volume_dimension,us> us_gallon;
56 
57 //]
58 
59 } // namespace units
60 
61 } // namespace boost
62 
63 BOOST_UNITS_DEFINE_CONVERSION_FACTOR(boost::units::imperial_gallon_tag,
64                                      boost::units::us_gallon_tag,
65                                      double, 1.2009499255);
66 
67 using namespace boost::units;
68 
main(void)69 int main(void)
70 {
71     quantity<imperial_gallon>   ig1(1.0*imperial_gallon());
72     quantity<us_gallon>         ug1(1.0*us_gallon());
73 
74     quantity<imperial_gallon>   ig2(ug1);
75     quantity<us_gallon>         ug2(ig1);
76 
77     return 0;
78 }
79