-
Notifications
You must be signed in to change notification settings - Fork 183
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
[Proposal] add swap
subroutines: swap the values of two variables of the same type ?
#462
Comments
swap
subroutines: swap
subroutines: swap the values of two variables of the same type
swap
subroutines: swap the values of two variables of the same typeswap
subroutines: swap the values of two variables of the same type ?
|
Hello @aman-godara , for |
a = string_type( "... a very long string ..." ) c = a ! This will create a deep copy (since the underlying `raw` variable is `allocatable` and NOT `pointer`) of `a` and assign it to `c`)
a = b
b = c Using move_alloc( a, c ) ! happens in O(1) time since no new copy has been created
move_alloc( b, a )
move_alloc( c, b ) So |
Thank you for your reply. I just tested it and found that type :: string_type
! Use the sequence statement below as a hack to prevent extending this type.
! It is not used for storage association.
sequence
private
character(len=:), allocatable :: raw !! Component 'raw' is a PRIVATE component of 'string_type'
end type string_type And type(string_type) :: a, b !! They are not allocatable.
a = string_type( "... a very long string ..." )
b = string_type( "... another long string ..." )
call move_alloc( b, a ) !! Error: `move_alloc` requires its arguments to be `allocatable`. I also found that |
you cannot access In my comment above, by move_alloc( a, c ) I meant call a subroutine which does equivalent of |
Thank you very much!😘 Understood! |
Completed in #869. Now closed. |
Description
Does
stdlib
need simpleswap
routines as follows? (Wait for #449 )The use of
swap
already instdlib
:The text was updated successfully, but these errors were encountered: