dimensionless_unit.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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) 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. #ifndef BOOST_UNITS_DETAIL_DIMENSIONLESS_UNIT_HPP
  11. #define BOOST_UNITS_DETAIL_DIMENSIONLESS_UNIT_HPP
  12. #include <boost/mpl/bool.hpp>
  13. #include <boost/units/units_fwd.hpp>
  14. namespace boost {
  15. namespace units {
  16. template<class T>
  17. struct heterogeneous_system;
  18. template<class T>
  19. struct homogeneous_system;
  20. template<class T1, class T2, class Scale>
  21. struct heterogeneous_system_impl;
  22. typedef boost::units::heterogeneous_system<
  23. boost::units::heterogeneous_system_impl<
  24. boost::units::dimensionless_type,
  25. boost::units::dimensionless_type,
  26. boost::units::dimensionless_type
  27. >
  28. > heterogeneous_dimensionless_system;
  29. namespace detail {
  30. template<class System>
  31. struct void_if_dimensionless {
  32. typedef int type;
  33. };
  34. template<class T>
  35. struct void_if_dimensionless<boost::units::homogeneous_system<T> > {
  36. typedef void type;
  37. };
  38. template<>
  39. struct void_if_dimensionless<heterogeneous_dimensionless_system> {
  40. typedef void type;
  41. };
  42. template<class System, class Test = void>
  43. struct void_if_heterogeneous {
  44. typedef void type;
  45. };
  46. template<class System>
  47. struct void_if_heterogeneous<System, typename void_if_dimensionless<System>::type> {
  48. typedef int type;
  49. };
  50. template<class System, class Enable=void>
  51. struct is_dimensionless_system : mpl::false_ {};
  52. template<class System>
  53. struct is_dimensionless_system<System, typename void_if_dimensionless<System>::type> : mpl::true_ {};
  54. #define BOOST_UNITS_DIMENSIONLESS_UNIT(T)\
  55. boost::units::unit<\
  56. boost::units::dimensionless_type,\
  57. T,\
  58. typename ::boost::units::detail::void_if_dimensionless<T>::type\
  59. >
  60. #define BOOST_UNITS_HETEROGENEOUS_DIMENSIONLESS_UNIT(T)\
  61. boost::units::unit<\
  62. boost::units::dimensionless_type,\
  63. T,\
  64. typename ::boost::units::detail::void_if_heterogeneous<T>::type\
  65. >
  66. }
  67. }
  68. }
  69. #endif