Skip to content

Commit e0c8b8f

Browse files
committed
documented move
1 parent a77931c commit e0c8b8f

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

doc/specs/stdlib_string_type.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,3 +1972,58 @@ program demo
19721972
close(io)
19731973
end program demo
19741974
```
1975+
1976+
1977+
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
1978+
### move
1979+
1980+
#### Description
1981+
1982+
Moves the allocation from `from` to `to`, consequently deallocating `from` in this process.
1983+
If `from` is not allocated before execution, `to` gets deallocated by the process.
1984+
An unallocated string is equivalent to an empty string.
1985+
1986+
#### Syntax
1987+
1988+
`call [[stdlib_string_type(module):move(interface)]] (from, to)`
1989+
1990+
#### Status
1991+
1992+
Experimental
1993+
1994+
#### Class
1995+
1996+
Pure Subroutine.
1997+
1998+
#### Argument
1999+
2000+
- `from`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
2001+
This argument is `intent(inout)`.
2002+
- `to`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
2003+
This argument is `intent(out)`.
2004+
2005+
#### Example
2006+
2007+
```fortran
2008+
program demo
2009+
use stdlib_string_type, only : string_type, assignment(=), move
2010+
implicit none
2011+
type(string_type) :: from_string, to_string
2012+
character(len=:), allocatable :: from_char
2013+
2014+
from_string = "move this string"
2015+
from_char = "move this char"
2016+
! from_string <-- "move this string"
2017+
! from_char <-- "move this char"
2018+
! to_string <-- "" (unallocated)
2019+
2020+
call move(from_string, to_string)
2021+
! from_string <-- "" (unallocated)
2022+
! to_string <-- "move this string"
2023+
2024+
call move(from_char, to_string)
2025+
! from_char <-- (unallocated)
2026+
! to_string <-- "move this char"
2027+
2028+
end program demo
2029+
```

0 commit comments

Comments
 (0)