next Function

private function next(this)

Arguments

Type IntentOptional AttributesName
class(iterator), intent(inout) :: this

Return Value class(container), allocatable

The next item held in the iterator, if present. Otherwise an unallocated container.

Description

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.


Source Code

  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