1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2008 Steven Watanabe
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)
11 #ifndef BOOST_UNITS_DETAIL_SORT_HPP
12 #define BOOST_UNITS_DETAIL_SORT_HPP
14 #include <boost/mpl/size.hpp>
15 #include <boost/mpl/begin.hpp>
16 #include <boost/mpl/next.hpp>
17 #include <boost/mpl/deref.hpp>
18 #include <boost/mpl/push_front.hpp>
19 #include <boost/mpl/less.hpp>
21 #include <boost/units/dimensionless_type.hpp>
22 #include <boost/units/detail/dimension_list.hpp>
31 struct insertion_sort_insert;
33 template<bool is_greater>
34 struct insertion_sort_comparison_impl;
36 // have to recursively add the element to the next sequence.
38 struct insertion_sort_comparison_impl<true> {
39 template<class Begin, int N, class T>
43 typename insertion_sort_insert<N - 1>::template apply<
51 // prepend the current element
53 struct insertion_sort_comparison_impl<false> {
54 template<class Begin, int N, class T>
56 typedef list<T, Begin> type;
61 struct insertion_sort_insert {
62 template<class Begin, class T>
64 typedef typename insertion_sort_comparison_impl<mpl::less<typename Begin::item, T>::value>::template apply<
73 struct insertion_sort_insert<0> {
74 template<class Begin, class T>
76 typedef list<T, dimensionless_type> type;
81 struct insertion_sort_impl {
84 typedef typename insertion_sort_impl<N - 1>::template apply<typename Begin::next>::type next;
85 typedef typename insertion_sort_insert<(next::size::value)>::template apply<next, typename Begin::item>::type type;
90 struct insertion_sort_impl<0> {
93 typedef dimensionless_type type;
100 typedef typename insertion_sort_impl<T::size::value>::template apply<T>::type type;
103 } // namespace detail