make_system.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_MAKE_SYSTEM_HPP
  11. #define BOOST_UNITS_MAKE_SYSTEM_HPP
  12. /// \file
  13. /// \brief Metafunction returning a homogeneous system that can
  14. /// represent any combination of the base units.
  15. /// \details
  16. /// Metafunction make_system returning a homogeneous system that can
  17. /// represent any combination of the base units. There must
  18. /// be no way to represent any of the base units in terms
  19. /// of the others. make_system<foot_base_unit, meter_base_unit>::type
  20. /// is not allowed, for example.
  21. #include <boost/units/config.hpp>
  22. #include <boost/units/dimensionless_type.hpp>
  23. #include <boost/units/homogeneous_system.hpp>
  24. #include <boost/units/detail/dimension_list.hpp>
  25. #include <boost/units/detail/sort.hpp>
  26. namespace boost {
  27. namespace units {
  28. #ifdef BOOST_UNITS_DOXYGEN
  29. namespace detail {
  30. struct unspecified {};
  31. }
  32. /// Metafunction returning a homogeneous system that can
  33. /// represent any combination of the base units. There must
  34. /// be no way to represent any of the base units in terms
  35. /// of the others. make_system<foot_base_unit, meter_base_unit>::type
  36. /// is not allowed, for example.
  37. template<class BaseUnit0, class BaseUnit1, class BaseUnit2, ..., class BaseUnitN>
  38. struct make_system
  39. {
  40. typedef homogeneous_system<detail::unspecified> type;
  41. };
  42. #else
  43. struct na {};
  44. template<
  45. class U0 = na,
  46. class U1 = na,
  47. class U2 = na,
  48. class U3 = na,
  49. class U4 = na,
  50. class U5 = na,
  51. class U6 = na,
  52. class U7 = na,
  53. class U8 = na,
  54. class U9 = na
  55. >
  56. struct make_system;
  57. template<>
  58. struct make_system<>
  59. {
  60. typedef homogeneous_system<dimensionless_type> type;
  61. };
  62. // Codewarrior 9.2 doesn't like using the defaults. Need
  63. // to specify na explicitly.
  64. template<class T0>
  65. struct make_system<T0, na, na, na, na, na, na, na, na, na>
  66. {
  67. typedef homogeneous_system<list<T0, dimensionless_type> > type;
  68. };
  69. template<class T0, class T1>
  70. struct make_system<T0, T1, na, na, na, na, na, na, na, na>
  71. {
  72. typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, dimensionless_type> > >::type> type;
  73. };
  74. template<class T0, class T1, class T2>
  75. struct make_system<T0, T1, T2, na, na, na, na, na, na, na>
  76. {
  77. typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, dimensionless_type> > > >::type> type;
  78. };
  79. template<class T0, class T1, class T2, class T3>
  80. struct make_system<T0, T1, T2, T3, na, na, na, na, na, na>
  81. {
  82. typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, dimensionless_type> > > > >::type> type;
  83. };
  84. template<class T0, class T1, class T2, class T3, class T4>
  85. struct make_system<T0, T1, T2, T3, T4, na, na, na, na, na>
  86. {
  87. typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, dimensionless_type> > > > > >::type> type;
  88. };
  89. template<class T0, class T1, class T2, class T3, class T4, class T5>
  90. struct make_system<T0, T1, T2, T3, T4, T5, na, na, na, na>
  91. {
  92. typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, list<T5, dimensionless_type> > > > > > >::type> type;
  93. };
  94. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6>
  95. struct make_system<T0, T1, T2, T3, T4, T5, T6, na, na, na>
  96. {
  97. typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, list<T5, list<T6, dimensionless_type> > > > > > > >::type> type;
  98. };
  99. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
  100. struct make_system<T0, T1, T2, T3, T4, T5, T6, T7, na, na>
  101. {
  102. typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, list<T5, list<T6, list<T7, dimensionless_type> > > > > > > > >::type> type;
  103. };
  104. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
  105. struct make_system<T0, T1, T2, T3, T4, T5, T6, T7, T8, na>
  106. {
  107. typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, list<T5, list<T6, list<T7, list<T8, dimensionless_type> > > > > > > > > >::type> type;
  108. };
  109. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9>
  110. struct make_system
  111. {
  112. typedef homogeneous_system<typename detail::insertion_sort<list<T0, list<T1, list<T2, list<T3, list<T4, list<T5, list<T6, list<T7, list<T8, list<T9, dimensionless_type> > > > > > > > > > >::type> type;
  113. };
  114. #endif
  115. } // namespace units
  116. } // namespace boost
  117. #endif