Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struct type arguments for generic quicksort #2964

Merged
merged 4 commits into from
Dec 12, 2023

Conversation

ansharlubis
Copy link
Contributor

Building on #2956 and referring back to #2266, I added another template instantiation where the argument is a struct type:

    subroutine test_template()
        ...
        instantiate qsort_t(my_type, lt_my_type), only: qsort_my_type => qs
        call quicksort{my_type, lt_my_type}(xm, 1, 10)
        ...
    end subroutine

Where my_type is

module template_sort_02_type
    implicit none
    public :: my_type, my_type_lt

    type my_type
        real :: d
    end type

contains

    pure elemental function lt_my_type(lhs, rhs) result(res)
        type(my_type), intent(in) :: lhs, rhs
        logical :: res
        res = lhs%d <= rhs%d
    end function

end module

@ansharlubis ansharlubis added the generics Fortran 202Y Generics label Dec 12, 2023
@ansharlubis ansharlubis marked this pull request as ready for review December 12, 2023 00:28
@ansharlubis ansharlubis mentioned this pull request Dec 12, 2023
37 tasks
Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful, good stuff!

@certik certik merged commit c63c8af into lfortran:main Dec 12, 2023
20 checks passed
@ansharlubis ansharlubis deleted the issue-2266-sort-struct branch December 12, 2023 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generics Fortran 202Y Generics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants