.. Algorithms/Transformation Algorithms//sort |95 sort ==== Synopsis -------- .. parsed-literal:: template< typename Seq , typename Pred = less<_1,_2> , typename In = |unspecified| > struct sort { typedef |unspecified| type; }; Description ----------- Returns a new sequence of all elements in the range |begin/end| sorted according to the ordering relation ``Pred``. |transformation algorithm disclaimer| Header ------ .. parsed-literal:: #include Model of -------- |Reversible Algorithm| Parameters ---------- +-------------------+-----------------------------------+-------------------------------+ | Parameter | Requirement | Description | +===================+===================================+===============================+ | ``Seq`` | |Forward Sequence| | An original sequence. | +-------------------+-----------------------------------+-------------------------------+ | ``Pred`` | Binary |Lambda Expression| | An ordering relation. | +-------------------+-----------------------------------+-------------------------------+ | ``In`` | |Inserter| | An inserter. | +-------------------+-----------------------------------+-------------------------------+ Expression semantics -------------------- |Semantics disclaimer...| |Reversible Algorithm|. For any |Forward Sequence| ``s``, a binary |Lambda Expression| ``pred``, and an |Inserter| ``in``: .. parsed-literal:: typedef sort::type r; :Return type: A type. :Semantics: If ``size::value <= 1``, equivalent to .. parsed-literal:: typedef copy::type r; otherwise equivalent to .. parsed-literal:: typedef back_inserter< vector<> > aux_in; typedef lambda::type p; typedef begin::type pivot; typedef partition< iterator_range< next::type, end::type > , apply_wrap2::type> , aux_in , aux_in >::type partitioned; typedef sort::type part1; typedef sort::type part2; typedef copy< joint_view< joint_view::type > > , part2 > , in >::type r; Complexity ---------- Average *O(n log(n))* where *n* == ``size::value``, quadratic at worst. Example ------- .. parsed-literal:: typedef vector_c numbers; typedef vector_c expected; typedef sort::type result; BOOST_MPL_ASSERT(( equal< result, expected, equal_to<_,_> > )); See also -------- |Transformation Algorithms|, |Reversible Algorithm|, |partition|