From: Steven W. <ste...@us...> - 2007-04-30 23:19:26
|
Update of /cvsroot/boost-sandbox/boost-sandbox/boost/units/experimental In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv31739/boost-sandbox/boost/units/experimental Modified Files: linear_algebra.hpp Log Message: Use bubble sort instead of mpl::sort Index: linear_algebra.hpp =================================================================== RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/units/experimental/linear_algebra.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- linear_algebra.hpp 29 Apr 2007 01:58:24 -0000 1.3 +++ linear_algebra.hpp 30 Apr 2007 23:19:19 -0000 1.4 @@ -446,14 +446,83 @@ }; }; +template<bool second_is_less> +struct bubble_sort_conditional_swap; + +template<> +struct bubble_sort_conditional_swap<true> { + template<class T0, class T1> + struct apply { + typedef T1 first; + typedef T0 second; + }; +}; + +template<> +struct bubble_sort_conditional_swap<false> { + template<class T0, class T1> + struct apply { + typedef T0 first; + typedef T1 second; + }; +}; + +template<int N> +struct bubble_sort_pass_impl { + template<class Begin, class Current> + struct apply { + typedef typename mpl::deref<Begin>::type val; + typedef typename bubble_sort_conditional_swap<mpl::less<val, Current>::value>::template apply<Current, val> pair; + typedef typename bubble_sort_pass_impl<N-1>::template apply<typename mpl::next<Begin>::type, typename pair::second> next; + typedef typename mpl::push_front<typename next::type, typename pair::first>::type type; + enum { value = next::value || mpl::less<val, Current>::value }; + }; +}; + +template<> +struct bubble_sort_pass_impl<0> { + template<class Begin, class Current> + struct apply { + typedef typename mpl::push_front<mpl::list0<>, Current>::type type; + enum { value = false }; + }; +}; + +template<bool> +struct bubble_sort_impl; + +template<> +struct bubble_sort_impl<true> { + template<class T> + struct apply { + typedef typename mpl::begin<T>::type begin; + typedef typename bubble_sort_pass_impl<mpl::size<T>::value - 1>::template apply< + typename mpl::next<begin>::type, + typename mpl::deref<begin>::type + > single_pass; + typedef typename bubble_sort_impl<(single_pass::value)>::template apply<typename single_pass::type>::type type; + }; +}; + +template<> +struct bubble_sort_impl<false> { + template<class T> + struct apply { + typedef T type; + }; +}; + +template<class T> +struct bubble_sort { + typedef typename bubble_sort_impl<((mpl::size<T>::value) > 1)>::template apply<T>::type type; +}; + template<class T> struct find_base_dimensions { - typedef typename mpl::sort< + typedef typename bubble_sort< typename find_base_dimensions_impl< mpl::size<T>::value - >::template apply<typename mpl::begin<T>::type>::type, - mpl::greater<>, - mpl::front_inserter<mpl::list0<> > + >::template apply<typename mpl::begin<T>::type>::type >::type type; }; |