#include #include #include using std::tuple; using std::integral_constant; using std::is_same; template struct to_int_types{ typedef tuple< integral_constant... > type; }; template struct Less { template struct Apply { static bool const value = X::value < Pivot::value; }; }; template struct GE { template struct Apply { static bool const value = X::value >= Pivot::value; }; }; template struct Tuple_PushFront {}; template struct Tuple_PushFront> { typedef tuple type; }; template struct Tuple_PushFront> { typedef tuple type; }; template struct Filter; template struct Filter< Pred, tuple<> > { typedef tuple<> type; }; template struct Filter< Pred, tuple > { typedef typename Tuple_PushFront< Head, Pred::template Apply::value, typename Filter>::type >::type type; }; template struct ConcatenateTuple {}; template struct ConcatenateTuple { typedef Tuple0 type; }; template struct ConcatenateTuple { template struct ConcatenateImpl {}; template struct ConcatenateImpl< tuple > { template struct Apply; template struct Apply< tuple > { typedef tuple type; }; }; typedef typename ConcatenateImpl::template Apply::type type; }; template struct ConcatenateTuple { typedef typename ConcatenateTuple< FirstTuple, typename ConcatenateTuple::type >::type type; }; template struct QuickSort {}; template <> struct QuickSort< tuple< > > { typedef tuple< > type; }; template struct QuickSort< tuple > { typedef tuple type; }; template struct QuickSort< tuple > { typedef typename Filter< Less, tuple >::type LeftElems; typedef typename Filter< GE , tuple >::type RightElems; typedef typename ConcatenateTuple< typename QuickSort::type, tuple, typename QuickSort::type >::type type; }; void StaticTest() { typedef to_int_types<1, 2, 3>::type lst_1_3; typedef to_int_types<3, 2, 1>::type lst_3_1; typedef to_int_types<3, 7, 1, 6, 5, 22, 5>::type lst; typedef integral_constant::type i1; typedef integral_constant::type i2; typedef integral_constant::type i3; static_assert(Less::Apply::value == true, ""); static_assert(Less::Apply::value == false, ""); static_assert(Less::Apply::value == false, ""); static_assert(GE::Apply::value == true, ""); static_assert(GE::Apply::value == true, ""); static_assert(GE::Apply::value == false, ""); static_assert(is_same>::type, tuple>::value, ""); static_assert(is_same>::type, tuple>::value, ""); static_assert(is_same>::type, tuple>::value, ""); static_assert(is_same, lst_1_3>::type, tuple>::value, ""); static_assert(is_same::type, lst_1_3>::value, ""); static_assert(is_same::type, lst_1_3>::value, ""); static_assert(is_same >::type, tuple<>>::value, ""); static_assert(is_same>::type, tuple>::value, ""); }