blob: 4476a34e184a0c2c3f97c1d4d1ec6a36a4c1b6cd [file] [log] [blame]
Brian Silvermana8ce4c32018-08-04 23:57:09 -07001// 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
17Another example of user-defined units with conversions.
18
19Output:
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
38namespace boost {
39
40namespace units {
41
42//[non_base_dimension_snippet_1
43
44struct imperial_gallon_tag :
45 base_unit<imperial_gallon_tag, volume_dimension, 1> { };
46
47typedef make_system<imperial_gallon_tag>::type imperial;
48
49typedef unit<volume_dimension,imperial> imperial_gallon;
50
51struct us_gallon_tag : base_unit<us_gallon_tag, volume_dimension, 2> { };
52
53typedef make_system<us_gallon_tag>::type us;
54
55typedef unit<volume_dimension,us> us_gallon;
56
57//]
58
59} // namespace units
60
61} // namespace boost
62
63BOOST_UNITS_DEFINE_CONVERSION_FACTOR(boost::units::imperial_gallon_tag,
64 boost::units::us_gallon_tag,
65 double, 1.2009499255);
66
67using namespace boost::units;
68
69int 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}