Skip to content

[Proposal] add swap subroutines: swap the values of two variables of the same type ? #462

Closed
@zoziha

Description

@zoziha

Description

Does stdlib need simple swap routines as follows? (Wait for #449 )

interface swap
    ...
end interface swap

!! Swap the values of two variables of the same type.
!! `type & kind` description: logical, integer, real, complex, character, string_type
pure elemental subroutine swap_${t1[0]}$${k1}$(a, b)
	${t1}$, intent(inout) :: a, b
	${t1}$ :: c
	c = a
	a = b
	b = c
end subroutine swap_${t1[0]}$${k1}$

call [[stdlib_math(module):swap(interface)]](a, b)

The use of swap already in stdlib:

  1. Initial implementation of COO / CSR sparse format #189 (comment)
  2. https://github.com/fortran-lang/stdlib/blob/888b5d343e5579a392273755b66394404fd361f9/src/stdlib_sorting_sort.fypp#L216~L219

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideaProposition of an idea and opening an issue to discuss ittopic: utilitiescontainers, strings, files, OS/environment integration, unit testing, assertions, logging, ...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions