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