Chris@16
|
1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
|
Chris@16
|
2 // unit/quantity manipulation and conversion
|
Chris@16
|
3 //
|
Chris@16
|
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
|
Chris@16
|
5 // Copyright (C) 2008 Steven Watanabe
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
8 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
9 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_UNITS_DETAIL_ONE_HPP
|
Chris@16
|
12 #define BOOST_UNITS_DETAIL_ONE_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/units/operators.hpp>
|
Chris@16
|
15
|
Chris@16
|
16 namespace boost {
|
Chris@16
|
17
|
Chris@16
|
18 namespace units {
|
Chris@16
|
19
|
Chris@16
|
20 struct one { one() {} };
|
Chris@16
|
21
|
Chris@16
|
22 // workaround for pathscale.
|
Chris@16
|
23 inline one make_one() {
|
Chris@16
|
24 one result;
|
Chris@16
|
25 return(result);
|
Chris@16
|
26 }
|
Chris@16
|
27
|
Chris@16
|
28 template<class T>
|
Chris@16
|
29 struct multiply_typeof_helper<one, T>
|
Chris@16
|
30 {
|
Chris@16
|
31 typedef T type;
|
Chris@16
|
32 };
|
Chris@16
|
33
|
Chris@16
|
34 template<class T>
|
Chris@16
|
35 struct multiply_typeof_helper<T, one>
|
Chris@16
|
36 {
|
Chris@16
|
37 typedef T type;
|
Chris@16
|
38 };
|
Chris@16
|
39
|
Chris@16
|
40 template<>
|
Chris@16
|
41 struct multiply_typeof_helper<one, one>
|
Chris@16
|
42 {
|
Chris@16
|
43 typedef one type;
|
Chris@16
|
44 };
|
Chris@16
|
45
|
Chris@16
|
46 template<class T>
|
Chris@16
|
47 inline T operator*(const one&, const T& t)
|
Chris@16
|
48 {
|
Chris@16
|
49 return(t);
|
Chris@16
|
50 }
|
Chris@16
|
51
|
Chris@16
|
52 template<class T>
|
Chris@16
|
53 inline T operator*(const T& t, const one&)
|
Chris@16
|
54 {
|
Chris@16
|
55 return(t);
|
Chris@16
|
56 }
|
Chris@16
|
57
|
Chris@16
|
58 inline one operator*(const one&, const one&)
|
Chris@16
|
59 {
|
Chris@16
|
60 one result;
|
Chris@16
|
61 return(result);
|
Chris@16
|
62 }
|
Chris@16
|
63
|
Chris@16
|
64 template<class T>
|
Chris@16
|
65 struct divide_typeof_helper<T, one>
|
Chris@16
|
66 {
|
Chris@16
|
67 typedef T type;
|
Chris@16
|
68 };
|
Chris@16
|
69
|
Chris@16
|
70 template<class T>
|
Chris@16
|
71 struct divide_typeof_helper<one, T>
|
Chris@16
|
72 {
|
Chris@16
|
73 typedef T type;
|
Chris@16
|
74 };
|
Chris@16
|
75
|
Chris@16
|
76 template<>
|
Chris@16
|
77 struct divide_typeof_helper<one, one>
|
Chris@16
|
78 {
|
Chris@16
|
79 typedef one type;
|
Chris@16
|
80 };
|
Chris@16
|
81
|
Chris@16
|
82 template<class T>
|
Chris@16
|
83 inline T operator/(const T& t, const one&)
|
Chris@16
|
84 {
|
Chris@16
|
85 return(t);
|
Chris@16
|
86 }
|
Chris@16
|
87
|
Chris@16
|
88 template<class T>
|
Chris@16
|
89 inline T operator/(const one&, const T& t)
|
Chris@16
|
90 {
|
Chris@16
|
91 return(1/t);
|
Chris@16
|
92 }
|
Chris@16
|
93
|
Chris@16
|
94 inline one operator/(const one&, const one&)
|
Chris@16
|
95 {
|
Chris@16
|
96 one result;
|
Chris@16
|
97 return(result);
|
Chris@16
|
98 }
|
Chris@16
|
99
|
Chris@16
|
100 template<class T>
|
Chris@16
|
101 inline bool operator>(const boost::units::one&, const T& t) {
|
Chris@16
|
102 return(1 > t);
|
Chris@16
|
103 }
|
Chris@16
|
104
|
Chris@16
|
105 template<class T>
|
Chris@16
|
106 T one_to_double(const T& t) { return t; }
|
Chris@16
|
107
|
Chris@16
|
108 inline double one_to_double(const one&) { return 1.0; }
|
Chris@16
|
109
|
Chris@16
|
110 template<class T>
|
Chris@16
|
111 struct one_to_double_type { typedef T type; };
|
Chris@16
|
112
|
Chris@16
|
113 template<>
|
Chris@16
|
114 struct one_to_double_type<one> { typedef double type; };
|
Chris@16
|
115
|
Chris@16
|
116 } // namespace units
|
Chris@16
|
117
|
Chris@16
|
118 } // namespace boost
|
Chris@16
|
119
|
Chris@16
|
120 #endif
|