Feedback for generics prototype

Nice to see it working!

If more test cases are needed, they can be picked from the std::ranges algorithms library. The insertion_sort in Fortran stdlib is also an easy target (and already written as a fypp template). To verify it was sorted correctly, you need a generic is_sorted:

template is_sorted_tmpl(t,lt)
requires comparable(t,lt)
contains
logical function is_sorted(array)
   type(t), intent(in) :: array(:)
   is_sorted = .true.
   do i = 1, size(array)-1
      if (lt(array(i+1),array(i)) then
         is_sorted = .false.
         return
      end if
   end do
end function
end template
1 Like