File indexing completed on 2025-01-18 09:53:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_UNITS_DETAIL_SORT_HPP
0012 #define BOOST_UNITS_DETAIL_SORT_HPP
0013
0014 #include <boost/mpl/size.hpp>
0015 #include <boost/mpl/begin.hpp>
0016 #include <boost/mpl/next.hpp>
0017 #include <boost/mpl/deref.hpp>
0018 #include <boost/mpl/push_front.hpp>
0019 #include <boost/mpl/less.hpp>
0020
0021 #include <boost/units/dimensionless_type.hpp>
0022 #include <boost/units/detail/dimension_list.hpp>
0023
0024 namespace boost {
0025
0026 namespace units {
0027
0028 namespace detail {
0029
0030 template<int N>
0031 struct insertion_sort_insert;
0032
0033 template<bool is_greater>
0034 struct insertion_sort_comparison_impl;
0035
0036
0037 template<>
0038 struct insertion_sort_comparison_impl<true> {
0039 template<class Begin, int N, class T>
0040 struct apply {
0041 typedef list<
0042 typename Begin::item,
0043 typename insertion_sort_insert<N - 1>::template apply<
0044 typename Begin::next,
0045 T
0046 >::type
0047 > type;
0048 };
0049 };
0050
0051
0052 template<>
0053 struct insertion_sort_comparison_impl<false> {
0054 template<class Begin, int N, class T>
0055 struct apply {
0056 typedef list<T, Begin> type;
0057 };
0058 };
0059
0060 template<int N>
0061 struct insertion_sort_insert {
0062 template<class Begin, class T>
0063 struct apply {
0064 typedef typename insertion_sort_comparison_impl<mpl::less<typename Begin::item, T>::value>::template apply<
0065 Begin,
0066 N,
0067 T
0068 >::type type;
0069 };
0070 };
0071
0072 template<>
0073 struct insertion_sort_insert<0> {
0074 template<class Begin, class T>
0075 struct apply {
0076 typedef list<T, dimensionless_type> type;
0077 };
0078 };
0079
0080 template<int N>
0081 struct insertion_sort_impl {
0082 template<class Begin>
0083 struct apply {
0084 typedef typename insertion_sort_impl<N - 1>::template apply<typename Begin::next>::type next;
0085 typedef typename insertion_sort_insert<(next::size::value)>::template apply<next, typename Begin::item>::type type;
0086 };
0087 };
0088
0089 template<>
0090 struct insertion_sort_impl<0> {
0091 template<class Begin>
0092 struct apply {
0093 typedef dimensionless_type type;
0094 };
0095 };
0096
0097 template<class T>
0098 struct insertion_sort
0099 {
0100 typedef typename insertion_sort_impl<T::size::value>::template apply<T>::type type;
0101 };
0102
0103 }
0104
0105 }
0106
0107 }
0108
0109 #endif