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) 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#ifndef BOOST_UNITS_DETAIL_ONE_HPP
12#define BOOST_UNITS_DETAIL_ONE_HPP
13
14#include <boost/units/operators.hpp>
15
16namespace boost {
17
18namespace units {
19
20struct one { BOOST_CONSTEXPR one() {} };
21
22// workaround for pathscale.
23inline BOOST_CONSTEXPR one make_one() {
24 return(one());
25}
26
27template<class T>
28struct multiply_typeof_helper<one, T>
29{
30 typedef T type;
31};
32
33template<class T>
34struct multiply_typeof_helper<T, one>
35{
36 typedef T type;
37};
38
39template<>
40struct multiply_typeof_helper<one, one>
41{
42 typedef one type;
43};
44
45template<class T>
46inline BOOST_CONSTEXPR T operator*(const one&, const T& t)
47{
48 return(t);
49}
50
51template<class T>
52inline BOOST_CONSTEXPR T operator*(const T& t, const one&)
53{
54 return(t);
55}
56
57inline BOOST_CONSTEXPR one operator*(const one&, const one&)
58{
59 return(one());
60}
61
62template<class T>
63struct divide_typeof_helper<T, one>
64{
65 typedef T type;
66};
67
68template<class T>
69struct divide_typeof_helper<one, T>
70{
71 typedef T type;
72};
73
74template<>
75struct divide_typeof_helper<one, one>
76{
77 typedef one type;
78};
79
80template<class T>
81inline BOOST_CONSTEXPR T operator/(const T& t, const one&)
82{
83 return(t);
84}
85
86template<class T>
87inline BOOST_CONSTEXPR T operator/(const one&, const T& t)
88{
89 return(1/t);
90}
91
92inline BOOST_CONSTEXPR one operator/(const one&, const one&)
93{
94 return(one());
95}
96
97template<class T>
98inline BOOST_CONSTEXPR bool operator>(const boost::units::one&, const T& t) {
99 return(1 > t);
100}
101
102template<class T>
103BOOST_CONSTEXPR T one_to_double(const T& t) { return t; }
104
105inline BOOST_CONSTEXPR double one_to_double(const one&) { return 1.0; }
106
107template<class T>
108struct one_to_double_type { typedef T type; };
109
110template<>
111struct one_to_double_type<one> { typedef double type; };
112
113} // namespace units
114
115} // namespace boost
116
117#endif
118

source code of boost/libs/units/include/boost/units/detail/one.hpp