Index of the next unfilled positional, advancing used.
A subroutine rather than a function because it advances the counter,
and a pure function may not have an intent(inout) argument.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| integer(kind=default_int), | intent(inout) | :: | used |
Positionals consumed so far; incremented when one is taken. |
||
| integer(kind=default_int), | intent(out) | :: | idx |
Index of the positional taken, or 0 when they are all filled. |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | i | ||||
| integer(kind=default_int), | private | :: | seen |
pure subroutine next_positional(this, used, idx) !! Index of the next unfilled positional, advancing `used`. !! !! A subroutine rather than a function because it advances the counter, !! and a pure function may not have an `intent(inout)` argument. class(cli_t), intent(in) :: this integer(default_int), intent(inout) :: used !! Positionals consumed so far; incremented when one is taken. integer(default_int), intent(out) :: idx !! Index of the positional taken, or 0 when they are all filled. integer(default_int) :: i, seen idx = 0_default_int seen = 0_default_int do i = 1_default_int, this%count if (this%entries(i)%kind /= KIND_POSITIONAL) cycle seen = seen + 1_default_int if (seen > used) then used = seen idx = i return end if end do end subroutine next_positional