dimension_list.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_DIMENSION_LIST_HPP
  11. #define BOOST_UNITS_DIMENSION_LIST_HPP
  12. #include <boost/mpl/next.hpp>
  13. #include <boost/mpl/deref.hpp>
  14. #include <boost/mpl/push_front_fwd.hpp>
  15. #include <boost/mpl/pop_front_fwd.hpp>
  16. #include <boost/mpl/size_fwd.hpp>
  17. #include <boost/mpl/begin_end_fwd.hpp>
  18. #include <boost/mpl/front_fwd.hpp>
  19. #include <boost/units/config.hpp>
  20. namespace boost {
  21. namespace units {
  22. struct dimensionless_type;
  23. namespace detail {
  24. struct dimension_list_tag { };
  25. } // namespace detail
  26. template<class Item, class Next>
  27. struct list
  28. {
  29. typedef detail::dimension_list_tag tag;
  30. typedef list type;
  31. typedef Item item;
  32. typedef Next next;
  33. typedef typename mpl::next<typename Next::size>::type size;
  34. };
  35. } // namespace units
  36. namespace mpl {
  37. // INTERNAL ONLY
  38. template<>
  39. struct size_impl<units::detail::dimension_list_tag>
  40. {
  41. template<class L> struct apply : public L::size { };
  42. };
  43. // INTERNAL ONLY
  44. template<>
  45. struct begin_impl<units::detail::dimension_list_tag>
  46. {
  47. template<class L>
  48. struct apply
  49. {
  50. typedef L type;
  51. };
  52. };
  53. // INTERNAL ONLY
  54. template<>
  55. struct end_impl<units::detail::dimension_list_tag>
  56. {
  57. template<class L>
  58. struct apply
  59. {
  60. typedef units::dimensionless_type type;
  61. };
  62. };
  63. // INTERNAL ONLY
  64. template<>
  65. struct push_front_impl<units::detail::dimension_list_tag>
  66. {
  67. template<class L, class T>
  68. struct apply
  69. {
  70. typedef units::list<T, L> type;
  71. };
  72. };
  73. // INTERNAL ONLY
  74. template<>
  75. struct pop_front_impl<units::detail::dimension_list_tag>
  76. {
  77. template<class L>
  78. struct apply
  79. {
  80. typedef typename L::next type;
  81. };
  82. };
  83. // INTERNAL ONLY
  84. template<>
  85. struct front_impl<units::detail::dimension_list_tag>
  86. {
  87. template<class L>
  88. struct apply
  89. {
  90. typedef typename L::item type;
  91. };
  92. };
  93. // INTERNAL ONLY
  94. template<class Item, class Next>
  95. struct deref<units::list<Item, Next> >
  96. {
  97. typedef Item type;
  98. };
  99. } // namespace mpl
  100. } // namespace boost
  101. #if BOOST_UNITS_HAS_BOOST_TYPEOF
  102. #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
  103. BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::list, 2)
  104. #endif
  105. #include <boost/units/dimensionless_type.hpp>
  106. #endif // BOOST_UNITS_DIMENSION_LIST_HPP