Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(iterator), | intent(inout) | :: | this |
The next item held in the iterator, if present. Otherwise an unallocated container.
Returns the next item stored in the iterator. If there are no more items present then an empty container is returned. If there are no contents stored in this iterator then it returns an unallocated container.
function next(this)
!* Author: Chris MacMackin
! Date: March 2016
!
! Returns the next item stored in the iterator. If there are no
! more items present then an empty [[container]] is returned. If
! there are no contents stored in this iterator then it returns
! an unallocated [[container]].
!
class(iterator), intent(inout) :: this
class(container), allocatable :: next
!! The next item held in the iterator, if present. Otherwise
!! an unallocated container.
if (.not. this%filled) return
if (this%location > size(this%contents)) then
allocate(next, mold=this%contents(1))
return
end if
allocate(next,source=this%contents(this%location))
this%location = this%location + 1
end function next