non_base_dimension.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /**
  11. \file
  12. \brief non_base_dimension.cpp
  13. \details
  14. Another example of user-defined units with conversions.
  15. Output:
  16. @verbatim
  17. //[non_base_dimension_output
  18. //]
  19. @endverbatim
  20. **/
  21. #include <iostream>
  22. #include <boost/units/io.hpp>
  23. #include <boost/units/conversion.hpp>
  24. #include <boost/units/unit.hpp>
  25. #include <boost/units/quantity.hpp>
  26. #include <boost/units/physical_dimensions.hpp>
  27. #include <boost/units/base_unit.hpp>
  28. #include <boost/units/make_system.hpp>
  29. namespace boost {
  30. namespace units {
  31. //[non_base_dimension_snippet_1
  32. struct imperial_gallon_tag :
  33. base_unit<imperial_gallon_tag, volume_dimension, 1> { };
  34. typedef make_system<imperial_gallon_tag>::type imperial;
  35. typedef unit<volume_dimension,imperial> imperial_gallon;
  36. struct us_gallon_tag : base_unit<us_gallon_tag, volume_dimension, 2> { };
  37. typedef make_system<us_gallon_tag>::type us;
  38. typedef unit<volume_dimension,us> us_gallon;
  39. //]
  40. } // namespace units
  41. } // namespace boost
  42. BOOST_UNITS_DEFINE_CONVERSION_FACTOR(boost::units::imperial_gallon_tag,
  43. boost::units::us_gallon_tag,
  44. double, 1.2009499255);
  45. using namespace boost::units;
  46. int main(void)
  47. {
  48. quantity<imperial_gallon> ig1(1.0*imperial_gallon());
  49. quantity<us_gallon> ug1(1.0*us_gallon());
  50. quantity<imperial_gallon> ig2(ug1);
  51. quantity<us_gallon> ug2(ig1);
  52. return 0;
  53. }