one.hpp 2.1 KB

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