796 {
797 static constexpr auto lt = nt::comparators::lessThan<T...>();
798 static constexpr auto eq = nt::comparators::equal<T...>();
799 auto ret = create_empty_vector<VEC_T, FUNC_T>();
800
801
802
803 if (vec.empty()) {
804 return ret;
805 }
806 auto min_element = vec[0];
807 auto max_element = vec[0];
808
809 for (const auto& e : vec) {
810 if (lt(e, min_element)) {
811 min_element = e;
812 }
813
814 if (lt(max_element, e)) {
815 max_element = e;
816 }
817 }
818
819 if (eq(min_element, max_element)) {
820 ret.push_back(
821 fun_c(vec)
822 );
823 return ret;
824 }
825
826 std::vector<VEC_T> buff{};
827 buff.reserve(vec.size());
828
829
830
831 auto process = [&]() {
832 buff.clear();
833 VEC_T next_min_element{};
834 next_min_element = max_element;
835
836 for (const auto& e : vec) {
837 if (eq(min_element, e)) {
838 buff.push_back(e);
839 } else if (lt(min_element, e) && lt(e, next_min_element)) {
840 next_min_element = e;
841 }
842
843 }
844
845 min_element = next_min_element;
846
847
848 ret.push_back(fun_c(buff));
849 };
850
851 while (lt(min_element, max_element)) {
852 process();
853
854 }
855
856 process();
857
858
859 return ret;
860 }