diff options
author | Anas Nashif <anas.nashif@intel.com> | 2012-10-30 12:57:26 -0700 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2012-10-30 12:57:26 -0700 |
commit | 1a78a62555be32868418fe52f8e330c9d0f95d5a (patch) | |
tree | d3765a80e7d3b9640ec2e930743630cd6b9fce2b /boost/units/detail/sort.hpp | |
download | boost-1a78a62555be32868418fe52f8e330c9d0f95d5a.tar.gz boost-1a78a62555be32868418fe52f8e330c9d0f95d5a.tar.bz2 boost-1a78a62555be32868418fe52f8e330c9d0f95d5a.zip |
Imported Upstream version 1.49.0upstream/1.49.0
Diffstat (limited to 'boost/units/detail/sort.hpp')
-rw-r--r-- | boost/units/detail/sort.hpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/boost/units/detail/sort.hpp b/boost/units/detail/sort.hpp new file mode 100644 index 0000000000..389adfe6ec --- /dev/null +++ b/boost/units/detail/sort.hpp @@ -0,0 +1,109 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_UNITS_DETAIL_SORT_HPP +#define BOOST_UNITS_DETAIL_SORT_HPP + +#include <boost/mpl/size.hpp> +#include <boost/mpl/begin.hpp> +#include <boost/mpl/next.hpp> +#include <boost/mpl/deref.hpp> +#include <boost/mpl/push_front.hpp> +#include <boost/mpl/less.hpp> + +#include <boost/units/dimensionless_type.hpp> +#include <boost/units/detail/dimension_list.hpp> + +namespace boost { + +namespace units { + +namespace detail { + +template<int N> +struct insertion_sort_insert; + +template<bool is_greater> +struct insertion_sort_comparison_impl; + +// have to recursively add the element to the next sequence. +template<> +struct insertion_sort_comparison_impl<true> { + template<class Begin, int N, class T> + struct apply { + typedef list< + typename Begin::item, + typename insertion_sort_insert<N - 1>::template apply< + typename Begin::next, + T + >::type + > type; + }; +}; + +// prepend the current element +template<> +struct insertion_sort_comparison_impl<false> { + template<class Begin, int N, class T> + struct apply { + typedef list<T, Begin> type; + }; +}; + +template<int N> +struct insertion_sort_insert { + template<class Begin, class T> + struct apply { + typedef typename insertion_sort_comparison_impl<mpl::less<typename Begin::item, T>::value>::template apply< + Begin, + N, + T + >::type type; + }; +}; + +template<> +struct insertion_sort_insert<0> { + template<class Begin, class T> + struct apply { + typedef list<T, dimensionless_type> type; + }; +}; + +template<int N> +struct insertion_sort_impl { + template<class Begin> + struct apply { + typedef typename insertion_sort_impl<N - 1>::template apply<typename Begin::next>::type next; + typedef typename insertion_sort_insert<(next::size::value)>::template apply<next, typename Begin::item>::type type; + }; +}; + +template<> +struct insertion_sort_impl<0> { + template<class Begin> + struct apply { + typedef dimensionless_type type; + }; +}; + +template<class T> +struct insertion_sort +{ + typedef typename insertion_sort_impl<T::size::value>::template apply<T>::type type; +}; + +} // namespace detail + +} // namespace units + +} // namespace boost + +#endif |