diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index a9960120..1fd6f927 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -53,6 +53,22 @@ SOFTWARE. #include #endif +namespace etl +{ + // Declare prototypes of the ETL's sort functions + template + void shell_sort(TIterator first, TIterator last); + + template + void shell_sort(TIterator first, TIterator last, TCompare compare); + + template + void insertion_sort(TIterator first, TIterator last); + + template + void insertion_sort(TIterator first, TIterator last, TCompare compare); +} + //***************************************************************************** // Algorithms defined by the ETL //***************************************************************************** @@ -2084,6 +2100,96 @@ namespace etl return std::none_of(begin, end, predicate); } #endif + +#if defined(ETL_NO_STL) + //*************************************************************************** + /// Sorts the elements. + /// Uses user defined comparison. + ///\ingroup algorithm + //*************************************************************************** + template + void sort(TIterator first, TIterator last, TCompare compare) + { + etl::shell_sort(first, last, compare); + } + + //*************************************************************************** + /// Sorts the elements. + ///\ingroup algorithm + //*************************************************************************** + template + void sort(TIterator first, TIterator last) + { + etl::shell_sort(first, last, etl::less::value_type>()); + } + + //*************************************************************************** + /// Sorts the elements. + /// Stable. + /// Uses user defined comparison. + ///\ingroup algorithm + //*************************************************************************** + template + void stable_sort(TIterator first, TIterator last, TCompare compare) + { + etl::insertion_sort(first, last, compare); + } + + //*************************************************************************** + /// Sorts the elements. + /// Stable. + ///\ingroup algorithm + //*************************************************************************** + template + void stable_sort(TIterator first, TIterator last) + { + etl::insertion_sort(first, last, etl::less::value_type>()); + } +#else + //*************************************************************************** + /// Sorts the elements. + /// Uses user defined comparison. + ///\ingroup algorithm + //*************************************************************************** + template + void sort(TIterator first, TIterator last, TCompare compare) + { + std::sort(first, last, compare); + } + + //*************************************************************************** + /// Sorts the elements. + ///\ingroup algorithm + //*************************************************************************** + template + void sort(TIterator first, TIterator last) + { + std::sort(first, last); + } + + //*************************************************************************** + /// Sorts the elements. + /// Stable. + /// Uses user defined comparison. + ///\ingroup algorithm + //*************************************************************************** + template + void stable_sort(TIterator first, TIterator last, TCompare compare) + { + std::stable_sort(first, last, compare); + } + + //*************************************************************************** + /// Sorts the elements. + /// Stable. + ///\ingroup algorithm + //*************************************************************************** + template + void stable_sort(TIterator first, TIterator last) + { + std::stable_sort(first, last); + } +#endif } //***************************************************************************** @@ -2681,50 +2787,6 @@ namespace etl etl::insertion_sort(first, last, etl::less::value_type>()); } - //*************************************************************************** - /// Sorts the elements. - /// Uses user defined comparison. - ///\ingroup algorithm - //*************************************************************************** - template - void sort(TIterator first, TIterator last, TCompare compare) - { - etl::shell_sort(first, last, compare); - } - - //*************************************************************************** - /// Sorts the elements. - ///\ingroup algorithm - //*************************************************************************** - template - void sort(TIterator first, TIterator last) - { - etl::shell_sort(first, last, etl::less::value_type>()); - } - - //*************************************************************************** - /// Sorts the elements. - /// Stable. - /// Uses user defined comparison. - ///\ingroup algorithm - //*************************************************************************** - template - void stable_sort(TIterator first, TIterator last, TCompare compare) - { - etl::insertion_sort(first, last, compare); - } - - //*************************************************************************** - /// Sorts the elements. - /// Stable. - ///\ingroup algorithm - //*************************************************************************** - template - void stable_sort(TIterator first, TIterator last) - { - etl::insertion_sort(first, last, etl::less::value_type>()); - } - //*************************************************************************** /// Returns the maximum value. //***************************************************************************