We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
move
1 parent 8476d65 commit 4aa4f75Copy full SHA for 4aa4f75
src/stdlib_string_type.fypp
@@ -17,6 +17,7 @@ module stdlib_string_type
17
& to_title_ => to_title, to_sentence_ => to_sentence, reverse_ => reverse
18
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
19
use stdlib_optval, only: optval
20
+ use iso_c_binding, only: c_loc,c_associated
21
implicit none
22
private
23
@@ -679,10 +680,12 @@ contains
679
680
!> Moves the allocated character scalar from 'from' to 'to'
681
!> No output
682
elemental subroutine move_string_string(from, to)
- type(string_type), intent(inout) :: from
683
- type(string_type), intent(inout) :: to
684
- character(:), allocatable :: tmp
+ type(string_type), intent(inout), target :: from
+ type(string_type), intent(inout), target :: to
685
+ character(:), allocatable :: tmp
686
687
+ if (c_associated(c_loc(from),c_loc(to))) return
688
+
689
call move_alloc(from%raw, tmp)
690
call move_alloc(tmp, to%raw)
691
0 commit comments